mirror of
https://github.com/docker/metadata-action.git
synced 2026-03-04 15:58:19 +00:00
replace actions/github/lib/context deep imports with public typing
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import {beforeEach, describe, expect, test, it, vi} from 'vitest';
|
import {beforeEach, describe, expect, test, it, vi} from 'vitest';
|
||||||
import {Context} from '@actions/github/lib/context.js';
|
|
||||||
import {Git} from '@docker/actions-toolkit/lib/git.js';
|
import {Git} from '@docker/actions-toolkit/lib/git.js';
|
||||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit.js';
|
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit.js';
|
||||||
|
|
||||||
@@ -98,11 +97,11 @@ describe('getContext', () => {
|
|||||||
expect(ctx.commitDate).toEqual(new Date('2024-11-13T13:42:28.000Z'));
|
expect(ctx.commitDate).toEqual(new Date('2024-11-13T13:42:28.000Z'));
|
||||||
});
|
});
|
||||||
it('git', async () => {
|
it('git', async () => {
|
||||||
vi.spyOn(Git, 'context').mockImplementation((): Promise<Context> => {
|
vi.spyOn(Git, 'context').mockImplementation((): Promise<context.Context> => {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
ref: 'refs/heads/git-test',
|
ref: 'refs/heads/git-test',
|
||||||
sha: 'git-test-sha'
|
sha: 'git-test-sha'
|
||||||
} as Context);
|
} as context.Context);
|
||||||
});
|
});
|
||||||
vi.spyOn(Git, 'commitDate').mockImplementation(async (): Promise<Date> => {
|
vi.spyOn(Git, 'commitDate').mockImplementation(async (): Promise<Date> => {
|
||||||
return new Date('2023-01-01T13:42:28.000Z');
|
return new Date('2023-01-01T13:42:28.000Z');
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ import * as fs from 'fs';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as dotenv from 'dotenv';
|
import * as dotenv from 'dotenv';
|
||||||
|
|
||||||
import {Context} from '@actions/github/lib/context.js';
|
|
||||||
import {GitHub} from '@docker/actions-toolkit/lib/github.js';
|
import {GitHub} from '@docker/actions-toolkit/lib/github.js';
|
||||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit.js';
|
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit.js';
|
||||||
import {GitHubRepo} from '@docker/actions-toolkit/lib/types/github.js';
|
import {GitHubRepo} from '@docker/actions-toolkit/lib/types/github.js';
|
||||||
|
|
||||||
import {ContextSource, getContext, getInputs, Inputs} from '../src/context.js';
|
import {ContextSource, getContext, getInputs, Inputs} from '../src/context.js';
|
||||||
|
import type {Context as MetadataContext} from '../src/context.js';
|
||||||
import {Meta, Version} from '../src/meta.js';
|
import {Meta, Version} from '../src/meta.js';
|
||||||
|
|
||||||
import repoFixture from './fixtures/repo.json' with {type: 'json'};
|
import repoFixture from './fixtures/repo.json' with {type: 'json'};
|
||||||
@@ -38,16 +38,28 @@ beforeEach(() => {
|
|||||||
delete process.env[key];
|
delete process.env[key];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
vi.spyOn(GitHub, 'context', 'get').mockImplementation((): MetadataContext => {
|
||||||
vi.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => {
|
const repository = process.env.GITHUB_REPOSITORY || 'docker/repo';
|
||||||
//@ts-expect-error partial info
|
const [owner, repo] = repository.includes('/') ? repository.split('/', 2) : ['docker', 'repo'];
|
||||||
|
const eventPath = process.env.GITHUB_EVENT_PATH;
|
||||||
|
const payload = eventPath && fs.existsSync(eventPath) ? JSON.parse(fs.readFileSync(eventPath, 'utf8')) : {};
|
||||||
return {
|
return {
|
||||||
...new Context(),
|
payload,
|
||||||
repo: {
|
eventName: process.env.GITHUB_EVENT_NAME || '',
|
||||||
owner: 'docker',
|
sha: process.env.GITHUB_SHA || '',
|
||||||
repo: 'repo'
|
ref: process.env.GITHUB_REF || '',
|
||||||
}
|
workflow: process.env.GITHUB_WORKFLOW || '',
|
||||||
};
|
action: process.env.GITHUB_ACTION || '',
|
||||||
|
actor: process.env.GITHUB_ACTOR || '',
|
||||||
|
job: process.env.GITHUB_JOB || '',
|
||||||
|
runAttempt: +(process.env.GITHUB_RUN_ATTEMPT || 1),
|
||||||
|
runNumber: +(process.env.GITHUB_RUN_NUMBER || 0),
|
||||||
|
runId: +(process.env.GITHUB_RUN_ID || 0),
|
||||||
|
apiUrl: process.env.GITHUB_API_URL || 'https://api.github.com',
|
||||||
|
serverUrl: process.env.GITHUB_SERVER_URL || 'https://github.com',
|
||||||
|
graphqlUrl: process.env.GITHUB_GRAPHQL_URL || 'https://api.github.com/graphql',
|
||||||
|
repo: {owner, repo}
|
||||||
|
} as MetadataContext;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
import {Context as GithubContext} from '@actions/github/lib/context.js';
|
|
||||||
import {Util} from '@docker/actions-toolkit/lib/util.js';
|
import {Util} from '@docker/actions-toolkit/lib/util.js';
|
||||||
import {Git} from '@docker/actions-toolkit/lib/git.js';
|
import {Git} from '@docker/actions-toolkit/lib/git.js';
|
||||||
import {GitHub} from '@docker/actions-toolkit/lib/github.js';
|
import {GitHub} from '@docker/actions-toolkit/lib/github.js';
|
||||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit.js';
|
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit.js';
|
||||||
|
|
||||||
|
type GithubContext = typeof GitHub.context;
|
||||||
|
|
||||||
export interface Context extends GithubContext {
|
export interface Context extends GithubContext {
|
||||||
commitDate: Date;
|
commitDate: Date;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user