Compare commits

...

11 Commits

Author SHA1 Message Date
CrazyMax
c255c9c200
chore: update generated content
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-03-04 11:00:17 +01:00
CrazyMax
e8d0bd119c
test: stabilize github mock setup since ESM
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-03-04 10:52:39 +01:00
CrazyMax
302938f99d
github class moved since actions-toolkit v0.77.0
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-03-04 10:52:39 +01:00
dependabot[bot]
5a81aee75f
chore(deps): Bump @docker/actions-toolkit from 0.68.0 to 0.77.0
Bumps [@docker/actions-toolkit](https://github.com/docker/actions-toolkit) from 0.68.0 to 0.77.0.
- [Release notes](https://github.com/docker/actions-toolkit/releases)
- [Commits](https://github.com/docker/actions-toolkit/compare/v0.68.0...v0.77.0)

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>

---
updated-dependencies:
- dependency-name: "@docker/actions-toolkit"
  dependency-version: 0.77.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-04 10:52:38 +01:00
CrazyMax
c769610e5c
Merge pull request #603 from docker/dependabot/npm_and_yarn/semver-7.7.4
Some checks failed
ci / tag-schedule () (push) Has been cancelled
ci / tag-schedule (cron-{{date 'YYYYMMDD'}}) (push) Has been cancelled
ci / tag-schedule (schedule) (push) Has been cancelled
ci / tag-schedule ({{date 'YYYYMMDD-HHmmss'}}) (push) Has been cancelled
ci / tag-match (\d.\d, 0) (push) Has been cancelled
ci / tag-match (\d.\d.\d, 0) (push) Has been cancelled
ci / tag-match (v(.*), 1) (push) Has been cancelled
ci / tag-semver (auto) (push) Has been cancelled
ci / tag-semver (false) (push) Has been cancelled
ci / tag-semver (true) (push) Has been cancelled
ci / flavor (push) Has been cancelled
ci / images (push) Has been cancelled
ci / custom-labels-annotations (push) Has been cancelled
ci / global-exps (push) Has been cancelled
ci / json (push) Has been cancelled
ci / docker-push (push) Has been cancelled
ci / bake (push) Has been cancelled
ci / sep-tags ( ) (push) Has been cancelled
ci / sep-tags (,) (push) Has been cancelled
ci / output-env (push) Has been cancelled
ci / no-output-env (push) Has been cancelled
ci / bake-annotations (push) Has been cancelled
ci / no-images (push) Has been cancelled
ci / bake-path-context (push) Has been cancelled
ci / sha-short () (push) Has been cancelled
ci / sha-short (16) (push) Has been cancelled
ci / dump (push) Has been cancelled
test / test (push) Has been cancelled
validate / prepare (push) Has been cancelled
validate / validate (push) Has been cancelled
chore(deps): Bump semver from 7.7.3 to 7.7.4
2026-03-04 10:52:19 +01:00
github-actions[bot]
f0f930b111 chore: update generated content 2026-03-04 09:19:30 +00:00
dependabot[bot]
f4771c2b1f
chore(deps): Bump semver from 7.7.3 to 7.7.4
Bumps [semver](https://github.com/npm/node-semver) from 7.7.3 to 7.7.4.
- [Release notes](https://github.com/npm/node-semver/releases)
- [Changelog](https://github.com/npm/node-semver/blob/main/CHANGELOG.md)
- [Commits](https://github.com/npm/node-semver/compare/v7.7.3...v7.7.4)

---
updated-dependencies:
- dependency-name: semver
  dependency-version: 7.7.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-04 09:18:03 +00:00
CrazyMax
538feedf47
Merge pull request #597 from docker/dependabot/npm_and_yarn/actions/github-9.0.0
chore(deps): Bump @actions/github from 6.0.1 to 9.0.0
2026-03-04 10:07:45 +01:00
CrazyMax
2c6e6d9d3b
chore: update generated content
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-03-03 16:00:55 +01:00
CrazyMax
8fd476a5a7
replace actions/github/lib/context deep imports with public typing
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-03-03 15:59:05 +01:00
dependabot[bot]
a33d385eb1
chore(deps): Bump @actions/github from 6.0.1 to 9.0.0
Bumps [@actions/github](https://github.com/actions/toolkit/tree/HEAD/packages/github) from 6.0.1 to 9.0.0.
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/github/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/github)

---
updated-dependencies:
- dependency-name: "@actions/github"
  dependency-version: 9.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-03 13:57:21 +00:00
9 changed files with 766 additions and 1202 deletions

View File

@ -1,5 +1,4 @@
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 {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'));
});
it('git', async () => {
vi.spyOn(Git, 'context').mockImplementation((): Promise<Context> => {
vi.spyOn(Git, 'context').mockImplementation((): Promise<context.Context> => {
return Promise.resolve({
ref: 'refs/heads/git-test',
sha: 'git-test-sha'
} as Context);
} as context.Context);
});
vi.spyOn(Git, 'commitDate').mockImplementation(async (): Promise<Date> => {
return new Date('2023-01-01T13:42:28.000Z');

View File

@ -3,12 +3,12 @@ import * as fs from 'fs';
import * as path from 'path';
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/github.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/github.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 repoFixture from './fixtures/repo.json' with {type: 'json'};
@ -38,16 +38,28 @@ beforeEach(() => {
delete process.env[key];
}
});
vi.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => {
//@ts-expect-error partial info
vi.spyOn(GitHub, 'context', 'get').mockImplementation((): MetadataContext => {
const repository = process.env.GITHUB_REPOSITORY || 'docker/repo';
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 {
...new Context(),
repo: {
owner: 'docker',
repo: 'repo'
}
};
payload,
eventName: process.env.GITHUB_EVENT_NAME || '',
sha: process.env.GITHUB_SHA || '',
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;
});
});

View File

@ -1,32 +1,11 @@
import fs from 'node:fs';
import {createRequire} from 'node:module';
import os from 'node:os';
import path from 'node:path';
import {vi} from 'vitest';
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-metadata-action-'));
process.env = Object.assign({}, process.env, {
TEMP: tmpDir,
GITHUB_REPOSITORY: 'docker/metadata-action',
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'),
RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache')
});
const require = createRequire(import.meta.url);
type RequireCacheEntry = NonNullable<(typeof require.cache)[string]>;
const githubMock = {
context: {
repo: {
owner: 'docker',
repo: 'actions-toolkit'
},
ref: 'refs/heads/dev',
sha: '5f3331d7f7044c18ca9f12c77d961c4d7cf3276a',
runId: 2188748038,
runNumber: 15,
payload: {
const githubPayload = {
after: '860c1904a1ce19322e91ac35af1ab07466440c37',
base_ref: null,
before: '5f3331d7f7044c18ca9f12c77d961c4d7cf3276a',
@ -43,11 +22,11 @@ const githubMock = {
username: 'crazy-max'
},
distinct: true,
id: '860c1904a1ce19322e91ac35af1ab07466440c37',
id: '5f3331d7f7044c18ca9f12c77d961c4d7cf3276a',
message: 'hello dev',
timestamp: '2022-04-19T11:27:24+02:00',
timestamp: '2024-11-13T13:42:28Z',
tree_id: 'd2c60af597e863787d2d27f569e30495b0b92820',
url: 'https://github.com/docker/test-docker-action/commit/860c1904a1ce19322e91ac35af1ab07466440c37'
url: 'https://github.com/docker/test-docker-action/commit/5f3331d7f7044c18ca9f12c77d961c4d7cf3276a'
}
],
compare: 'https://github.com/docker/test-docker-action/compare/5f3331d7f704...860c1904a1ce',
@ -66,11 +45,11 @@ const githubMock = {
username: 'crazy-max'
},
distinct: true,
id: '860c1904a1ce19322e91ac35af1ab07466440c37',
id: '5f3331d7f7044c18ca9f12c77d961c4d7cf3276a',
message: 'hello dev',
timestamp: '2022-04-19T11:27:24+02:00',
timestamp: '2024-11-13T13:42:28Z',
tree_id: 'd2c60af597e863787d2d27f569e30495b0b92820',
url: 'https://github.com/docker/test-docker-action/commit/860c1904a1ce19322e91ac35af1ab07466440c37'
url: 'https://github.com/docker/test-docker-action/commit/5f3331d7f7044c18ca9f12c77d961c4d7cf3276a'
},
organization: {
avatar_url: 'https://avatars.githubusercontent.com/u/5429470?v=4',
@ -220,12 +199,26 @@ const githubMock = {
type: 'User',
url: 'https://api.github.com/users/crazy-max'
}
}
},
getOctokit: () => ({
rest: {
repos: {
getCommit: async () => ({
};
const githubEventPath = path.join(tmpDir, 'github-event.json');
fs.writeFileSync(githubEventPath, JSON.stringify(githubPayload));
process.env = Object.assign({}, process.env, {
TEMP: tmpDir,
GITHUB_REPOSITORY: 'docker/metadata-action',
GITHUB_REF: 'refs/heads/dev',
GITHUB_RUN_ID: '2188748038',
GITHUB_RUN_ATTEMPT: '1',
GITHUB_RUN_NUMBER: '15',
GITHUB_SHA: '5f3331d7f7044c18ca9f12c77d961c4d7cf3276a',
GITHUB_EVENT_PATH: githubEventPath,
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'),
RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache')
});
const getCommitMock = vi.hoisted(() =>
vi.fn(async () => ({
data: {
commit: {
committer: {
@ -233,27 +226,27 @@ const githubMock = {
}
}
}
})
}))
);
const getOctokitMock = vi.hoisted(() =>
vi.fn(() => ({
rest: {
repos: {
getCommit: getCommitMock
}
}
})
}))
);
vi.mock('@actions/github', async importOriginal => {
const actual = await importOriginal<typeof import('@actions/github')>();
return {
...actual,
context: {
...actual.context,
payload: githubPayload
},
getOctokit: getOctokitMock
};
vi.mock('@actions/github', () => githubMock);
for (const mod of ['@actions/github', '@docker/actions-toolkit/node_modules/@actions/github']) {
try {
const resolved = require.resolve(mod);
vi.doMock(resolved, () => githubMock);
require.cache[resolved] = {
id: resolved,
filename: resolved,
loaded: true,
exports: githubMock,
children: [],
paths: []
} as RequireCacheEntry;
} catch {
// Ignore unresolved optional paths; vi.mock handles module-level mocking.
}
}
});

141
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -25,14 +25,14 @@
"packageManager": "yarn@4.9.2",
"dependencies": {
"@actions/core": "^3.0.0",
"@actions/github": "^6.0.1",
"@docker/actions-toolkit": "^0.68.0",
"@actions/github": "^9.0.0",
"@docker/actions-toolkit": "^0.77.0",
"@renovate/pep440": "^1.0.0",
"csv-parse": "^6.1.0",
"handlebars": "^4.7.8",
"moment": "^2.30.1",
"moment-timezone": "^0.6.0",
"semver": "^7.7.3"
"semver": "^7.7.4"
},
"devDependencies": {
"@eslint/js": "^9.39.3",

View File

@ -1,11 +1,12 @@
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 {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/github.js';
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit.js';
type GithubContext = typeof GitHub.context;
export interface Context extends GithubContext {
commitDate: Date;
}

View File

@ -6,7 +6,7 @@ import * as pep440 from '@renovate/pep440';
import * as semver from 'semver';
import * as core from '@actions/core';
import {Context as ToolkitContext} from '@docker/actions-toolkit/lib/context.js';
import {GitHubRepo} from '@docker/actions-toolkit/lib/types/github.js';
import {GitHubRepo} from '@docker/actions-toolkit/lib/types/github/github.js';
import {Inputs, Context} from './context.js';
import * as icl from './image.js';

1304
yarn.lock

File diff suppressed because it is too large Load Diff