mirror of
https://github.com/docker/metadata-action.git
synced 2026-03-25 17:38:18 +00:00
Compare commits
25 Commits
e7819bbe91
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8fcbb5b808 | ||
|
|
b13d25e5fc | ||
|
|
f58488e265 | ||
|
|
414af88e96 | ||
|
|
2c2d4fb584 | ||
|
|
85e876bd3a | ||
|
|
e2d26b25bd | ||
|
|
a26abf68b2 | ||
|
|
030e881283 | ||
|
|
4b529ac4e5 | ||
|
|
b0082b33bc | ||
|
|
7b19fec715 | ||
|
|
281c9b0599 | ||
|
|
5f43b3b4f4 | ||
|
|
9d53276575 | ||
|
|
eaa3d3973e | ||
|
|
6b695f7a8a | ||
|
|
a1afadcb28 | ||
|
|
c769610e5c | ||
|
|
f0f930b111 | ||
|
|
f4771c2b1f | ||
|
|
538feedf47 | ||
|
|
2c6e6d9d3b | ||
|
|
8fd476a5a7 | ||
|
|
a33d385eb1 |
44
.github/workflows/ci.yml
vendored
44
.github/workflows/ci.yml
vendored
@@ -46,7 +46,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver: docker
|
driver: docker
|
||||||
@@ -83,7 +83,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver: docker
|
driver: docker
|
||||||
@@ -119,7 +119,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver: docker
|
driver: docker
|
||||||
@@ -153,7 +153,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver: docker
|
driver: docker
|
||||||
@@ -184,7 +184,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver: docker
|
driver: docker
|
||||||
@@ -207,7 +207,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver: docker
|
driver: docker
|
||||||
@@ -228,7 +228,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver: docker
|
driver: docker
|
||||||
@@ -258,7 +258,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver: docker
|
driver: docker
|
||||||
@@ -288,7 +288,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver: docker
|
driver: docker
|
||||||
@@ -323,7 +323,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver-opts: network=host
|
driver-opts: network=host
|
||||||
@@ -345,7 +345,7 @@ jobs:
|
|||||||
type=sha
|
type=sha
|
||||||
-
|
-
|
||||||
name: Build and push to local registry
|
name: Build and push to local registry
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v7
|
||||||
with:
|
with:
|
||||||
context: ./test
|
context: ./test
|
||||||
file: ./test/Dockerfile
|
file: ./test/Dockerfile
|
||||||
@@ -371,7 +371,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
-
|
-
|
||||||
@@ -393,7 +393,7 @@ jobs:
|
|||||||
type=sha
|
type=sha
|
||||||
-
|
-
|
||||||
name: Build
|
name: Build
|
||||||
uses: docker/bake-action@v6
|
uses: docker/bake-action@v7
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
./test/docker-bake.hcl
|
./test/docker-bake.hcl
|
||||||
@@ -416,7 +416,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver: docker
|
driver: docker
|
||||||
@@ -444,7 +444,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver: docker
|
driver: docker
|
||||||
@@ -462,7 +462,7 @@ jobs:
|
|||||||
maintainer=Foo
|
maintainer=Foo
|
||||||
-
|
-
|
||||||
name: Build
|
name: Build
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v7
|
||||||
with:
|
with:
|
||||||
context: ./test
|
context: ./test
|
||||||
file: ./test/output.Dockerfile
|
file: ./test/output.Dockerfile
|
||||||
@@ -507,7 +507,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
-
|
-
|
||||||
@@ -531,7 +531,7 @@ jobs:
|
|||||||
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
|
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
|
||||||
-
|
-
|
||||||
name: Build
|
name: Build
|
||||||
uses: docker/bake-action@v6
|
uses: docker/bake-action@v7
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
./test/docker-bake.hcl
|
./test/docker-bake.hcl
|
||||||
@@ -548,7 +548,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver: docker
|
driver: docker
|
||||||
@@ -574,7 +574,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
-
|
-
|
||||||
@@ -583,7 +583,7 @@ jobs:
|
|||||||
uses: ./
|
uses: ./
|
||||||
-
|
-
|
||||||
name: Build
|
name: Build
|
||||||
uses: docker/bake-action@v6
|
uses: docker/bake-action@v7
|
||||||
with:
|
with:
|
||||||
source: .
|
source: .
|
||||||
files: |
|
files: |
|
||||||
@@ -607,7 +607,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
version: ${{ env.BUILDX_VERSION }}
|
version: ${{ env.BUILDX_VERSION }}
|
||||||
driver: docker
|
driver: docker
|
||||||
|
|||||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -20,7 +20,7 @@ jobs:
|
|||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: Test
|
name: Test
|
||||||
uses: docker/bake-action@v6
|
uses: docker/bake-action@v7
|
||||||
with:
|
with:
|
||||||
source: .
|
source: .
|
||||||
targets: test
|
targets: test
|
||||||
|
|||||||
4
.github/workflows/update-dist.yml
vendored
4
.github/workflows/update-dist.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
|||||||
-
|
-
|
||||||
name: GitHub auth token from GitHub App
|
name: GitHub auth token from GitHub App
|
||||||
id: docker-read-app
|
id: docker-read-app
|
||||||
uses: actions/create-github-app-token@v2
|
uses: actions/create-github-app-token@v3
|
||||||
with:
|
with:
|
||||||
app-id: ${{ secrets.GHACTIONS_REPO_WRITE_APP_ID }}
|
app-id: ${{ secrets.GHACTIONS_REPO_WRITE_APP_ID }}
|
||||||
private-key: ${{ secrets.GHACTIONS_REPO_WRITE_APP_PRIVATE_KEY }}
|
private-key: ${{ secrets.GHACTIONS_REPO_WRITE_APP_PRIVATE_KEY }}
|
||||||
@@ -28,7 +28,7 @@ jobs:
|
|||||||
token: ${{ steps.docker-read-app.outputs.token || github.token }}
|
token: ${{ steps.docker-read-app.outputs.token || github.token }}
|
||||||
-
|
-
|
||||||
name: Build
|
name: Build
|
||||||
uses: docker/bake-action@v6
|
uses: docker/bake-action@v7
|
||||||
with:
|
with:
|
||||||
source: .
|
source: .
|
||||||
targets: build
|
targets: build
|
||||||
|
|||||||
10
.github/workflows/validate.yml
vendored
10
.github/workflows/validate.yml
vendored
@@ -15,15 +15,15 @@ jobs:
|
|||||||
prepare:
|
prepare:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
targets: ${{ steps.generate.outputs.targets }}
|
matrix: ${{ steps.generate.outputs.matrix }}
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
-
|
-
|
||||||
name: List targets
|
name: Generate matrix
|
||||||
id: generate
|
id: generate
|
||||||
uses: docker/bake-action/subaction/list-targets@v6
|
uses: docker/bake-action/subaction/matrix@v7
|
||||||
with:
|
with:
|
||||||
target: validate
|
target: validate
|
||||||
|
|
||||||
@@ -34,10 +34,10 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
target: ${{ fromJson(needs.prepare.outputs.targets) }}
|
include: ${{ fromJson(needs.prepare.outputs.matrix) }}
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Validate
|
name: Validate
|
||||||
uses: docker/bake-action@v6
|
uses: docker/bake-action@v7
|
||||||
with:
|
with:
|
||||||
targets: ${{ matrix.target }}
|
targets: ${{ matrix.target }}
|
||||||
|
|||||||
@@ -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';
|
||||||
|
|
||||||
@@ -80,6 +79,67 @@ describe('getInputs', () => {
|
|||||||
tags: [],
|
tags: [],
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
3,
|
||||||
|
new Map<string, string>([
|
||||||
|
['labels', 'mylabel=foo#bar\n#comment\nanother=bar'],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
context: context.ContextSource.workflow,
|
||||||
|
bakeTarget: 'docker-metadata-action',
|
||||||
|
flavor: [],
|
||||||
|
githubToken: '',
|
||||||
|
images: [],
|
||||||
|
labels: ['mylabel=foo#bar', 'another=bar'],
|
||||||
|
annotations: [],
|
||||||
|
sepLabels: '\n',
|
||||||
|
sepTags: '\n',
|
||||||
|
sepAnnotations: '\n',
|
||||||
|
tags: [],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
4,
|
||||||
|
new Map<string, string>([
|
||||||
|
['annotations', 'org.opencontainers.image.url=https://example.com/path#readme\n#comment\norg.opencontainers.image.source=https://github.com/docker/metadata-action'],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
context: context.ContextSource.workflow,
|
||||||
|
bakeTarget: 'docker-metadata-action',
|
||||||
|
flavor: [],
|
||||||
|
githubToken: '',
|
||||||
|
images: [],
|
||||||
|
labels: [],
|
||||||
|
annotations: [
|
||||||
|
'org.opencontainers.image.url=https://example.com/path#readme',
|
||||||
|
'org.opencontainers.image.source=https://github.com/docker/metadata-action'
|
||||||
|
],
|
||||||
|
sepLabels: '\n',
|
||||||
|
sepTags: '\n',
|
||||||
|
sepAnnotations: '\n',
|
||||||
|
tags: [],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
5,
|
||||||
|
new Map<string, string>([
|
||||||
|
['tags', 'type=raw,value=foo#bar\n#comment'],
|
||||||
|
['flavor', 'prefix=v#1\n#comment'],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
context: context.ContextSource.workflow,
|
||||||
|
bakeTarget: 'docker-metadata-action',
|
||||||
|
flavor: ['prefix=v#1'],
|
||||||
|
githubToken: '',
|
||||||
|
images: [],
|
||||||
|
labels: [],
|
||||||
|
annotations: [],
|
||||||
|
sepLabels: '\n',
|
||||||
|
sepTags: '\n',
|
||||||
|
sepAnnotations: '\n',
|
||||||
|
tags: ['type=raw,value=foo#bar'],
|
||||||
|
}
|
||||||
|
],
|
||||||
];
|
];
|
||||||
test.each(cases)('[%d] given %o as inputs, returns %o', async (num: number, inputs: Map<string, string>, expected: context.Inputs) => {
|
test.each(cases)('[%d] given %o as inputs, returns %o', async (num: number, inputs: Map<string, string>, expected: context.Inputs) => {
|
||||||
inputs.forEach((value: string, name: string) => {
|
inputs.forEach((value: string, name: string) => {
|
||||||
@@ -98,11 +158,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/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/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,32 +1,11 @@
|
|||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import {createRequire} from 'node:module';
|
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import {vi} from 'vitest';
|
import {vi} from 'vitest';
|
||||||
|
|
||||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-metadata-action-'));
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-metadata-action-'));
|
||||||
|
|
||||||
process.env = Object.assign({}, process.env, {
|
const githubPayload = {
|
||||||
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: {
|
|
||||||
after: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
after: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
||||||
base_ref: null,
|
base_ref: null,
|
||||||
before: '5f3331d7f7044c18ca9f12c77d961c4d7cf3276a',
|
before: '5f3331d7f7044c18ca9f12c77d961c4d7cf3276a',
|
||||||
@@ -43,11 +22,11 @@ const githubMock = {
|
|||||||
username: 'crazy-max'
|
username: 'crazy-max'
|
||||||
},
|
},
|
||||||
distinct: true,
|
distinct: true,
|
||||||
id: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
id: '5f3331d7f7044c18ca9f12c77d961c4d7cf3276a',
|
||||||
message: 'hello dev',
|
message: 'hello dev',
|
||||||
timestamp: '2022-04-19T11:27:24+02:00',
|
timestamp: '2024-11-13T13:42:28Z',
|
||||||
tree_id: 'd2c60af597e863787d2d27f569e30495b0b92820',
|
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',
|
compare: 'https://github.com/docker/test-docker-action/compare/5f3331d7f704...860c1904a1ce',
|
||||||
@@ -66,11 +45,11 @@ const githubMock = {
|
|||||||
username: 'crazy-max'
|
username: 'crazy-max'
|
||||||
},
|
},
|
||||||
distinct: true,
|
distinct: true,
|
||||||
id: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
id: '5f3331d7f7044c18ca9f12c77d961c4d7cf3276a',
|
||||||
message: 'hello dev',
|
message: 'hello dev',
|
||||||
timestamp: '2022-04-19T11:27:24+02:00',
|
timestamp: '2024-11-13T13:42:28Z',
|
||||||
tree_id: 'd2c60af597e863787d2d27f569e30495b0b92820',
|
tree_id: 'd2c60af597e863787d2d27f569e30495b0b92820',
|
||||||
url: 'https://github.com/docker/test-docker-action/commit/860c1904a1ce19322e91ac35af1ab07466440c37'
|
url: 'https://github.com/docker/test-docker-action/commit/5f3331d7f7044c18ca9f12c77d961c4d7cf3276a'
|
||||||
},
|
},
|
||||||
organization: {
|
organization: {
|
||||||
avatar_url: 'https://avatars.githubusercontent.com/u/5429470?v=4',
|
avatar_url: 'https://avatars.githubusercontent.com/u/5429470?v=4',
|
||||||
@@ -220,12 +199,26 @@ const githubMock = {
|
|||||||
type: 'User',
|
type: 'User',
|
||||||
url: 'https://api.github.com/users/crazy-max'
|
url: 'https://api.github.com/users/crazy-max'
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
},
|
|
||||||
getOctokit: () => ({
|
const githubEventPath = path.join(tmpDir, 'github-event.json');
|
||||||
rest: {
|
fs.writeFileSync(githubEventPath, JSON.stringify(githubPayload));
|
||||||
repos: {
|
|
||||||
getCommit: async () => ({
|
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: {
|
data: {
|
||||||
commit: {
|
commit: {
|
||||||
committer: {
|
committer: {
|
||||||
@@ -233,27 +226,27 @@ const githubMock = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}))
|
||||||
}
|
);
|
||||||
}
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
vi.mock('@actions/github', () => githubMock);
|
const getOctokitMock = vi.hoisted(() =>
|
||||||
|
vi.fn(() => ({
|
||||||
for (const mod of ['@actions/github', '@docker/actions-toolkit/node_modules/@actions/github']) {
|
rest: {
|
||||||
try {
|
repos: {
|
||||||
const resolved = require.resolve(mod);
|
getCommit: getCommitMock
|
||||||
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.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
vi.mock('@actions/github', async importOriginal => {
|
||||||
|
const actual = await importOriginal<typeof import('@actions/github')>();
|
||||||
|
return {
|
||||||
|
...actual,
|
||||||
|
context: {
|
||||||
|
...actual.context,
|
||||||
|
payload: githubPayload
|
||||||
|
},
|
||||||
|
getOctokit: getOctokitMock
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|||||||
@@ -66,5 +66,5 @@ outputs:
|
|||||||
description: 'Bake definition file with tags and labels'
|
description: 'Bake definition file with tags and labels'
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node20'
|
using: 'node24'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
ARG NODE_VERSION=20
|
ARG NODE_VERSION=24
|
||||||
|
|
||||||
FROM node:${NODE_VERSION}-alpine AS base
|
FROM node:${NODE_VERSION}-alpine AS base
|
||||||
RUN apk add --no-cache cpio findutils git rsync
|
RUN apk add --no-cache cpio findutils git rsync
|
||||||
|
|||||||
141
dist/index.js
generated
vendored
141
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@@ -25,18 +25,18 @@
|
|||||||
"packageManager": "yarn@4.9.2",
|
"packageManager": "yarn@4.9.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^3.0.0",
|
"@actions/core": "^3.0.0",
|
||||||
"@actions/github": "^6.0.1",
|
"@actions/github": "^9.0.0",
|
||||||
"@docker/actions-toolkit": "^0.68.0",
|
"@docker/actions-toolkit": "^0.79.0",
|
||||||
"@renovate/pep440": "^1.0.0",
|
"@renovate/pep440": "^1.0.0",
|
||||||
"csv-parse": "^6.1.0",
|
"csv-parse": "^6.1.0",
|
||||||
"handlebars": "^4.7.8",
|
"handlebars": "^4.7.8",
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.30.1",
|
||||||
"moment-timezone": "^0.6.0",
|
"moment-timezone": "^0.6.0",
|
||||||
"semver": "^7.7.3"
|
"semver": "^7.7.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.39.3",
|
"@eslint/js": "^9.39.3",
|
||||||
"@types/node": "^20.19.35",
|
"@types/node": "^24.11.0",
|
||||||
"@types/semver": "^7.7.1",
|
"@types/semver": "^7.7.1",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
||||||
"@typescript-eslint/parser": "^8.56.1",
|
"@typescript-eslint/parser": "^8.56.1",
|
||||||
|
|||||||
@@ -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/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;
|
||||||
}
|
}
|
||||||
@@ -27,11 +28,11 @@ export interface Inputs {
|
|||||||
export function getInputs(): Inputs {
|
export function getInputs(): Inputs {
|
||||||
return {
|
return {
|
||||||
context: (core.getInput('context') || ContextSource.workflow) as ContextSource,
|
context: (core.getInput('context') || ContextSource.workflow) as ContextSource,
|
||||||
images: Util.getInputList('images', {ignoreComma: true, comment: '#'}),
|
images: Util.getInputList('images', {ignoreComma: true, comment: '#', commentNoInfix: true}),
|
||||||
tags: Util.getInputList('tags', {ignoreComma: true, comment: '#'}),
|
tags: Util.getInputList('tags', {ignoreComma: true, comment: '#', commentNoInfix: true}),
|
||||||
flavor: Util.getInputList('flavor', {ignoreComma: true, comment: '#'}),
|
flavor: Util.getInputList('flavor', {ignoreComma: true, comment: '#', commentNoInfix: true}),
|
||||||
labels: Util.getInputList('labels', {ignoreComma: true, comment: '#'}),
|
labels: Util.getInputList('labels', {ignoreComma: true, comment: '#', commentNoInfix: true}),
|
||||||
annotations: Util.getInputList('annotations', {ignoreComma: true, comment: '#'}),
|
annotations: Util.getInputList('annotations', {ignoreComma: true, comment: '#', commentNoInfix: true}),
|
||||||
sepTags: core.getInput('sep-tags', {trimWhitespace: false}) || `\n`,
|
sepTags: core.getInput('sep-tags', {trimWhitespace: false}) || `\n`,
|
||||||
sepLabels: core.getInput('sep-labels', {trimWhitespace: false}) || `\n`,
|
sepLabels: core.getInput('sep-labels', {trimWhitespace: false}) || `\n`,
|
||||||
sepAnnotations: core.getInput('sep-annotations', {trimWhitespace: false}) || `\n`,
|
sepAnnotations: core.getInput('sep-annotations', {trimWhitespace: false}) || `\n`,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import * as pep440 from '@renovate/pep440';
|
|||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import {Context as ToolkitContext} from '@docker/actions-toolkit/lib/context.js';
|
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 {Inputs, Context} from './context.js';
|
||||||
import * as icl from './image.js';
|
import * as icl from './image.js';
|
||||||
|
|||||||
Reference in New Issue
Block a user