Compare commits
146 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
96383f4557 | ||
|
f138b9677b | ||
|
9cf7015b15 | ||
|
5a8a5ff8df | ||
|
2279d9af58 | ||
|
c659933213 | ||
|
48d23ccc05 | ||
|
b83ffb48d6 | ||
|
3207f2405f | ||
|
63f4a263e5 | ||
|
547dcd6d67 | ||
|
450eef4207 | ||
|
903f5af663 | ||
|
3634bd57d7 | ||
|
d3faf0d1af | ||
|
ff376f4737 | ||
|
79f06a31c0 | ||
|
6f69513dab | ||
|
b67fef219a | ||
|
51990f24d1 | ||
|
4af6ba2231 | ||
|
59de4866c5 | ||
|
0f8c876baf | ||
|
389ff6bdd5 | ||
|
2bcfca25d5 | ||
|
05b244eb76 | ||
|
35e9aff4f5 | ||
|
1586898b63 | ||
|
7a273586e1 | ||
|
ef25336f42 | ||
|
0ab15faee8 | ||
|
1ea1b02f9b | ||
|
818d4b7b91 | ||
|
948134af5e | ||
|
ef7eee951a | ||
|
8ec80c3be6 | ||
|
38650bbf6b | ||
|
ebbd9b4df7 | ||
|
2dadb92b6b | ||
|
2c0bd771b4 | ||
|
b10b364e15 | ||
|
40a1c6ff52 | ||
|
be8ea87c5a | ||
|
dbbf01822b | ||
|
72b4ec2b60 | ||
|
00e2c9d34e | ||
|
c4ee3adeed | ||
|
3bea1eeada | ||
|
88c7f0d3f6 | ||
|
101f9cbeaf | ||
|
0e44559303 | ||
|
517f8b0c3b | ||
|
bfaa9197f7 | ||
|
16dbdc96f6 | ||
|
bf095b87d3 | ||
|
2ed3c45f27 | ||
|
5076359ba6 | ||
|
d8f57c18fa | ||
|
80530e08c5 | ||
|
da933fb889 | ||
|
3f6690a76c | ||
|
dda839d15b | ||
|
37f1d84442 | ||
|
1ce942256d | ||
|
8f8c795666 | ||
|
9ec57ed1fc | ||
|
2bdac1078b | ||
|
9e02960866 | ||
|
ea910e3ad4 | ||
|
8b6629002b | ||
|
1db8e21e35 | ||
|
b30cff8c11 | ||
|
916b4b90e3 | ||
|
0ef9f130fa | ||
|
f5c49ece12 | ||
|
18df8a69c4 | ||
|
3343011071 | ||
|
0524f79273 | ||
|
b5c378621c | ||
|
a103499e09 | ||
|
766400ca14 | ||
|
e2ffd4cc94 | ||
|
6c3ca5dfa6 | ||
|
235becadd8 | ||
|
507c2f2dc5 | ||
|
04861f5102 | ||
|
6729545cde | ||
|
05d22bf317 | ||
|
70b403b46b | ||
|
9e6ae02878 | ||
|
3d239e8b8a | ||
|
7cb52e2750 | ||
|
90a1d5cf21 | ||
|
c98ac5e987 | ||
|
44d853bc0a | ||
|
d1abf80723 | ||
|
3358a27538 | ||
|
314ddf6d4a | ||
|
b91e8f52b0 | ||
|
fbac5f9bca | ||
|
57396166ad | ||
|
473bdc561c | ||
|
ebedea2c18 | ||
|
d00b20e38f | ||
|
a99e71cdc7 | ||
|
12cce9efe0 | ||
|
f17e188860 | ||
|
210d783f42 | ||
|
5f26473e44 | ||
|
49e79e3532 | ||
|
5ebec4fd21 | ||
|
8ed470c7f1 | ||
|
61ddee1921 | ||
|
8671a4f8ec | ||
|
3862a1b70f | ||
|
f7c31b1e79 | ||
|
55b0d953e7 | ||
|
4c6a2cafd0 | ||
|
6c51f019f8 | ||
|
5c9aa83b20 | ||
|
30af4d7327 | ||
|
594a555a35 | ||
|
7fa87ab51a | ||
|
02d1a10cce | ||
|
58061722cc | ||
|
1c9aacf050 | ||
|
1f87faac28 | ||
|
59bc9ddfd5 | ||
|
286660a061 | ||
|
139c7584e2 | ||
|
ee266832e5 | ||
|
ae052be62f | ||
|
98045504c7 | ||
|
97c170d70b | ||
|
44ecceaf69 | ||
|
e4d14b2070 | ||
|
f66710ef6c | ||
|
d6cc766711 | ||
|
9c37b1c855 | ||
|
e518b0e7bb | ||
|
7bf589e898 | ||
|
bc6cb60a8a | ||
|
4db6eea5ea | ||
|
b5ee2f25f6 | ||
|
8d56fe93cf | ||
|
59267481d9 |
3
.eslintignore
Normal file
3
.eslintignore
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/dist/**
|
||||||
|
/coverage/**
|
||||||
|
/node_modules/**
|
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"env": {
|
"env": {
|
||||||
"node": true,
|
"node": true,
|
||||||
"es2021": true,
|
"es6": true,
|
||||||
"jest/globals": true
|
"jest": true
|
||||||
},
|
},
|
||||||
"extends": [
|
"extends": [
|
||||||
"eslint:recommended",
|
"eslint:recommended",
|
||||||
|
"plugin:@typescript-eslint/eslint-recommended",
|
||||||
"plugin:@typescript-eslint/recommended",
|
"plugin:@typescript-eslint/recommended",
|
||||||
"plugin:jest/recommended",
|
"plugin:jest/recommended",
|
||||||
"plugin:prettier/recommended"
|
"plugin:prettier/recommended"
|
||||||
|
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
@@ -1 +0,0 @@
|
|||||||
* @crazy-max
|
|
1
.github/dependabot.yml
vendored
1
.github/dependabot.yml
vendored
@@ -11,6 +11,7 @@ updates:
|
|||||||
directory: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: "daily"
|
interval: "daily"
|
||||||
|
versioning-strategy: "increase"
|
||||||
allow:
|
allow:
|
||||||
- dependency-type: "production"
|
- dependency-type: "production"
|
||||||
labels:
|
labels:
|
||||||
|
104
.github/workflows/ci.yml
vendored
104
.github/workflows/ci.yml
vendored
@@ -1,8 +1,12 @@
|
|||||||
name: ci
|
name: ci
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 */4 * * *' # every 4 hours
|
- cron: '0 10 * * *'
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'master'
|
- 'master'
|
||||||
@@ -10,9 +14,6 @@ on:
|
|||||||
tags:
|
tags:
|
||||||
- 'v*.*.*'
|
- 'v*.*.*'
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
|
||||||
- 'master'
|
|
||||||
- 'releases/v*'
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
DOCKER_IMAGE: localhost:5000/name/app
|
DOCKER_IMAGE: localhost:5000/name/app
|
||||||
@@ -23,7 +24,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -37,6 +38,9 @@ jobs:
|
|||||||
type=ref,event=tag
|
type=ref,event=tag
|
||||||
type=ref,event=pr
|
type=ref,event=pr
|
||||||
type=sha
|
type=sha
|
||||||
|
-
|
||||||
|
name: Print envs
|
||||||
|
run: env|sort
|
||||||
|
|
||||||
tag-schedule:
|
tag-schedule:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -51,7 +55,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -81,7 +85,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -109,7 +113,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -134,7 +138,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -151,7 +155,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -166,7 +170,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -185,7 +189,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -206,7 +210,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
@@ -235,7 +239,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: docker_meta
|
id: docker_meta
|
||||||
@@ -254,15 +258,15 @@ jobs:
|
|||||||
type=sha
|
type=sha
|
||||||
-
|
-
|
||||||
name: Set up QEMU
|
name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@v2
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v2
|
||||||
with:
|
with:
|
||||||
driver-opts: network=host
|
driver-opts: network=host
|
||||||
-
|
-
|
||||||
name: Build and push to local registry
|
name: Build and push to local registry
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: ./test
|
context: ./test
|
||||||
file: ./test/Dockerfile
|
file: ./test/Dockerfile
|
||||||
@@ -282,14 +286,14 @@ jobs:
|
|||||||
-
|
-
|
||||||
name: Dump context
|
name: Dump context
|
||||||
if: always()
|
if: always()
|
||||||
uses: crazy-max/ghaction-dump-context@v1
|
uses: crazy-max/ghaction-dump-context@v2
|
||||||
|
|
||||||
bake:
|
bake:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: docker_meta
|
id: docker_meta
|
||||||
@@ -309,16 +313,72 @@ jobs:
|
|||||||
type=sha
|
type=sha
|
||||||
-
|
-
|
||||||
name: Set up QEMU
|
name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@v2
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v2
|
||||||
-
|
-
|
||||||
name: Build
|
name: Build
|
||||||
uses: docker/bake-action@v1
|
uses: docker/bake-action@v3
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
./test/docker-bake.hcl
|
./test/docker-bake.hcl
|
||||||
${{ steps.docker_meta.outputs.bake-file }}
|
${{ steps.docker_meta.outputs.bake-file }}
|
||||||
targets: |
|
targets: |
|
||||||
release
|
release
|
||||||
|
|
||||||
|
sep-tags:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
sep:
|
||||||
|
- " "
|
||||||
|
- ","
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
${{ env.DOCKER_IMAGE }}
|
||||||
|
ghcr.io/name/app
|
||||||
|
sep-tags: ${{ matrix.sep }}
|
||||||
|
-
|
||||||
|
name: Tags
|
||||||
|
uses: actions/github-script@v6
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
console.log(`${{ steps.meta.outputs.tags }}`);
|
||||||
|
|
||||||
|
output-env:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
${{ env.DOCKER_IMAGE }}
|
||||||
|
ghcr.io/name/app
|
||||||
|
labels: |
|
||||||
|
maintainer=CrazyMax
|
||||||
|
-
|
||||||
|
name: Build
|
||||||
|
uses: docker/build-push-action@v4
|
||||||
|
with:
|
||||||
|
context: ./test
|
||||||
|
file: ./test/output.Dockerfile
|
||||||
|
build-args: |
|
||||||
|
DOCKER_METADATA_OUTPUT_VERSION
|
||||||
|
DOCKER_METADATA_OUTPUT_TAGS
|
||||||
|
DOCKER_METADATA_OUTPUT_LABELS
|
||||||
|
DOCKER_METADATA_OUTPUT_JSON
|
||||||
|
16
.github/workflows/test.yml
vendored
16
.github/workflows/test.yml
vendored
@@ -1,14 +1,15 @@
|
|||||||
name: test
|
name: test
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'master'
|
- 'master'
|
||||||
- 'releases/v*'
|
- 'releases/v*'
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
|
||||||
- 'master'
|
|
||||||
- 'releases/v*'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
@@ -16,15 +17,10 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
-
|
|
||||||
name: Validate
|
|
||||||
uses: docker/bake-action@v1
|
|
||||||
with:
|
|
||||||
targets: validate
|
|
||||||
-
|
-
|
||||||
name: Test
|
name: Test
|
||||||
uses: docker/bake-action@v1
|
uses: docker/bake-action@v3
|
||||||
with:
|
with:
|
||||||
targets: test
|
targets: test
|
||||||
-
|
-
|
||||||
|
45
.github/workflows/validate.yml
vendored
Normal file
45
.github/workflows/validate.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
name: validate
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
- 'releases/v*'
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
prepare:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
targets: ${{ steps.targets.outputs.matrix }}
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Targets matrix
|
||||||
|
id: targets
|
||||||
|
run: |
|
||||||
|
echo "matrix=$(docker buildx bake validate --print | jq -cr '.group.validate.targets')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
validate:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- prepare
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
target: ${{ fromJson(needs.prepare.outputs.targets) }}
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
-
|
||||||
|
name: Validate
|
||||||
|
uses: docker/bake-action@v3
|
||||||
|
with:
|
||||||
|
targets: ${{ matrix.target }}
|
229
README.md
229
README.md
@@ -1,12 +1,14 @@
|
|||||||
[](https://github.com/docker/metadata-action/releases/latest)
|
[](https://github.com/docker/metadata-action/releases/latest)
|
||||||
[](https://github.com/marketplace/actions/docker-metadata-action)
|
[](https://github.com/marketplace/actions/docker-metadata-action)
|
||||||
[](https://github.com/docker/metadata-action/actions?workflow=test)
|
[](https://github.com/docker/metadata-action/actions?workflow=ci)
|
||||||
|
[](https://github.com/docker/metadata-action/actions?workflow=test)
|
||||||
[](https://codecov.io/gh/docker/metadata-action)
|
[](https://codecov.io/gh/docker/metadata-action)
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
GitHub Action to extract metadata from Git reference and GitHub events.
|
GitHub Action to extract metadata from Git reference and GitHub events. This action
|
||||||
This action is particularly useful if used with [Docker Build Push](https://github.com/docker/build-push-action) action to tag and label Docker images.
|
is particularly useful if used with [Docker Build Push](https://github.com/docker/build-push-action)
|
||||||
|
action to tag and label Docker images.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -19,6 +21,8 @@ ___
|
|||||||
* [Customizing](#customizing)
|
* [Customizing](#customizing)
|
||||||
* [inputs](#inputs)
|
* [inputs](#inputs)
|
||||||
* [outputs](#outputs)
|
* [outputs](#outputs)
|
||||||
|
* [environment variables](#environment-variables)
|
||||||
|
* [`context` input](#context-input)
|
||||||
* [`images` input](#images-input)
|
* [`images` input](#images-input)
|
||||||
* [`flavor` input](#flavor-input)
|
* [`flavor` input](#flavor-input)
|
||||||
* [`tags` input](#tags-input)
|
* [`tags` input](#tags-input)
|
||||||
@@ -33,17 +37,18 @@ ___
|
|||||||
* [Notes](#notes)
|
* [Notes](#notes)
|
||||||
* [Image name and tag sanitization](#image-name-and-tag-sanitization)
|
* [Image name and tag sanitization](#image-name-and-tag-sanitization)
|
||||||
* [Latest tag](#latest-tag)
|
* [Latest tag](#latest-tag)
|
||||||
|
* [`priority` attribute](#priority-attribute)
|
||||||
* [Global expressions](#global-expressions)
|
* [Global expressions](#global-expressions)
|
||||||
* [`{{branch}}`](#branch)
|
* [`{{branch}}`](#branch)
|
||||||
* [`{{tag}}`](#tag)
|
* [`{{tag}}`](#tag)
|
||||||
* [`{{sha}}`](#sha)
|
* [`{{sha}}`](#sha)
|
||||||
* [`{{base_ref}}`](#base_ref)
|
* [`{{base_ref}}`](#base_ref)
|
||||||
* [`{{is_default_branch}}`](#is_default_branch)
|
* [`{{is_default_branch}}`](#is_default_branch)
|
||||||
* [`{{date '<format>'}}`](#date-format)
|
* [`{{date '<format>' tz='<timezone>'}}`](#date-format-tztimezone)
|
||||||
* [Major version zero](#major-version-zero)
|
* [Major version zero](#major-version-zero)
|
||||||
* [JSON output object](#json-output-object)
|
* [JSON output object](#json-output-object)
|
||||||
* [Overwrite labels](#overwrite-labels)
|
* [Overwrite labels](#overwrite-labels)
|
||||||
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
|
* [Contributing](#contributing)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@@ -53,6 +58,7 @@ ___
|
|||||||
name: ci
|
name: ci
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'master'
|
- 'master'
|
||||||
@@ -68,7 +74,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
@@ -78,13 +84,13 @@ jobs:
|
|||||||
-
|
-
|
||||||
name: Login to DockerHub
|
name: Login to DockerHub
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
@@ -93,12 +99,13 @@ jobs:
|
|||||||
```
|
```
|
||||||
|
|
||||||
| Event | Ref | Docker Tags |
|
| Event | Ref | Docker Tags |
|
||||||
|-----------------|-------------------------------|-------------------------------------|
|
|---------------------|-------------------------------|----------------------------|
|
||||||
| `pull_request` | `refs/pull/2/merge` | `pr-2` |
|
| `pull_request` | `refs/pull/2/merge` | `pr-2` |
|
||||||
| `push` | `refs/heads/master` | `master` |
|
| `push` | `refs/heads/master` | `master` |
|
||||||
| `push` | `refs/heads/releases/v1` | `releases-v1` |
|
| `push` | `refs/heads/releases/v1` | `releases-v1` |
|
||||||
| `push tag` | `refs/tags/v1.2.3` | `v1.2.3`, `latest` |
|
| `push tag` | `refs/tags/v1.2.3` | `v1.2.3`, `latest` |
|
||||||
| `push tag` | `refs/tags/v2.0.8-beta.67` | `v2.0.8-beta.67`, `latest` |
|
| `push tag` | `refs/tags/v2.0.8-beta.67` | `v2.0.8-beta.67`, `latest` |
|
||||||
|
| `workflow_dispatch` | `refs/heads/master` | `master` |
|
||||||
|
|
||||||
### Semver
|
### Semver
|
||||||
|
|
||||||
@@ -121,7 +128,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
@@ -137,13 +144,13 @@ jobs:
|
|||||||
-
|
-
|
||||||
name: Login to DockerHub
|
name: Login to DockerHub
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
@@ -162,8 +169,8 @@ jobs:
|
|||||||
### Bake definition
|
### Bake definition
|
||||||
|
|
||||||
This action also handles a bake definition file that can be used with the
|
This action also handles a bake definition file that can be used with the
|
||||||
[Docker Bake action](https://github.com/docker/bake-action). You just have to declare an empty target named
|
[Docker Bake action](https://github.com/docker/bake-action). You just have to
|
||||||
`docker-metadata-action` and inherit from it.
|
declare an empty target named `docker-metadata-action` and inherit from it.
|
||||||
|
|
||||||
```hcl
|
```hcl
|
||||||
// docker-bake.hcl
|
// docker-bake.hcl
|
||||||
@@ -199,7 +206,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
@@ -215,7 +222,7 @@ jobs:
|
|||||||
type=sha
|
type=sha
|
||||||
-
|
-
|
||||||
name: Build
|
name: Build
|
||||||
uses: docker/bake-action@v1
|
uses: docker/bake-action@v2
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
./docker-bake.hcl
|
./docker-bake.hcl
|
||||||
@@ -223,7 +230,8 @@ jobs:
|
|||||||
targets: build
|
targets: build
|
||||||
```
|
```
|
||||||
|
|
||||||
Content of `${{ steps.meta.outputs.bake-file }}` file will look like this with `refs/tags/v1.2.3` ref:
|
Content of `${{ steps.meta.outputs.bake-file }}` file will look like this with
|
||||||
|
`refs/tags/v1.2.3` ref:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@@ -269,7 +277,8 @@ Following inputs can be used as `step.with` keys
|
|||||||
> ```
|
> ```
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|---------------------|--------|----------------------------------------------------------|
|
|---------------------|--------|-------------------------------------------------------------------------------|
|
||||||
|
| `context` | String | Where to get context data. Allowed options are: `workflow` (default), `git`. |
|
||||||
| `images` | List | List of Docker images to use as base name for tags |
|
| `images` | List | List of Docker images to use as base name for tags |
|
||||||
| `tags` | List | List of [tags](#tags-input) as key-value pair attributes |
|
| `tags` | List | List of [tags](#tags-input) as key-value pair attributes |
|
||||||
| `flavor` | List | [Flavor](#flavor-input) to apply |
|
| `flavor` | List | [Flavor](#flavor-input) to apply |
|
||||||
@@ -283,12 +292,49 @@ Following inputs can be used as `step.with` keys
|
|||||||
Following outputs are available
|
Following outputs are available
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|---------------|---------|-------------------------------------------------------------------------------|
|
|---------------|---------|--------------------------------------------------------------------------------------------|
|
||||||
| `version` | String | Docker image version |
|
| `version` | String | Docker image version |
|
||||||
| `tags` | String | Docker tags |
|
| `tags` | String | Docker tags |
|
||||||
| `labels` | String | Docker labels |
|
| `labels` | String | Docker labels |
|
||||||
| `json` | String | JSON output of tags and labels |
|
| `json` | String | JSON output of tags and labels |
|
||||||
| `bake-file` | File | [Bake definition file](https://github.com/docker/buildx#file-definition) path |
|
| `bake-file` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path |
|
||||||
|
|
||||||
|
Alternatively, each output is also exported as an environment variable:
|
||||||
|
|
||||||
|
* `DOCKER_METADATA_OUTPUT_VERSION`
|
||||||
|
* `DOCKER_METADATA_OUTPUT_TAGS`
|
||||||
|
* `DOCKER_METADATA_OUTPUT_LABELS`
|
||||||
|
* `DOCKER_METADATA_OUTPUT_JSON`
|
||||||
|
* `DOCKER_METADATA_OUTPUT_BAKE_FILE`
|
||||||
|
|
||||||
|
So it can be used with our [Docker Build Push action](https://github.com/docker/build-push-action/):
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: docker/build-push-action@v4
|
||||||
|
with:
|
||||||
|
build-args: |
|
||||||
|
DOCKER_METADATA_OUTPUT_JSON
|
||||||
|
```
|
||||||
|
|
||||||
|
### environment variables
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-------------------------------|------|------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `DOCKER_METADATA_PR_HEAD_SHA` | Bool | If `true`, set associated head SHA instead of commit SHA that triggered the workflow on pull request event |
|
||||||
|
|
||||||
|
## `context` input
|
||||||
|
|
||||||
|
`context` defines where to get context metadata:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# default
|
||||||
|
context: workflow
|
||||||
|
# or
|
||||||
|
context: git
|
||||||
|
```
|
||||||
|
|
||||||
|
* `workflow`: Get context metadata from the workflow (GitHub context). See https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
|
||||||
|
* `git`: Get context metadata from the workflow and overrides some of them with current Git context, such as `ref` and `sha`.
|
||||||
|
|
||||||
## `images` input
|
## `images` input
|
||||||
|
|
||||||
@@ -325,13 +371,16 @@ flavor: |
|
|||||||
```
|
```
|
||||||
|
|
||||||
* `latest=<auto|true|false>`: Handle [latest tag](#latest-tag) (default `auto`)
|
* `latest=<auto|true|false>`: Handle [latest tag](#latest-tag) (default `auto`)
|
||||||
* `prefix=<string>,onlatest=<true|false>`: A global prefix for each generated tag and optionally for `latest`
|
* `prefix=<string>,onlatest=<true|false>`: A global prefix for each generated
|
||||||
* `suffix=<string>,onlatest=<true|false>`: A global suffix for each generated tag and optionally for `latest`
|
tag and optionally for `latest`
|
||||||
|
* `suffix=<string>,onlatest=<true|false>`: A global suffix for each generated
|
||||||
|
tag and optionally for `latest`
|
||||||
|
|
||||||
## `tags` input
|
## `tags` input
|
||||||
|
|
||||||
`tags` is the core input of this action as everything related to it will reflect the output metadata. This one is in
|
`tags` is the core input of this action as everything related to it will
|
||||||
the form of a key-value pair list in CSV format to remove limitations intrinsically linked to GitHub Actions
|
reflect the output metadata. This one is in the form of a key-value pair list
|
||||||
|
in CSV format to remove limitations intrinsically linked to GitHub Actions
|
||||||
(only string format is handled in the input fields). Here is an example:
|
(only string format is handled in the input fields). Here is an example:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@@ -359,7 +408,7 @@ Each entry is defined by a `type`, which are:
|
|||||||
And global attributes:
|
And global attributes:
|
||||||
|
|
||||||
* `enable=<true|false>` enable this entry (default `true`)
|
* `enable=<true|false>` enable this entry (default `true`)
|
||||||
* `priority=<number>` priority to manage the order of tags
|
* `priority=<number>` set tag [priority](#priority-attribute) order
|
||||||
* `prefix=<string>` add prefix
|
* `prefix=<string>` add prefix
|
||||||
* `suffix=<string>` add suffix
|
* `suffix=<string>` add suffix
|
||||||
|
|
||||||
@@ -383,18 +432,23 @@ tags: |
|
|||||||
type=schedule,pattern=nightly
|
type=schedule,pattern=nightly
|
||||||
# handlebars
|
# handlebars
|
||||||
type=schedule,pattern={{date 'YYYYMMDD'}}
|
type=schedule,pattern={{date 'YYYYMMDD'}}
|
||||||
|
# handlebars with timezone
|
||||||
|
type=schedule,pattern={{date 'YYYYMMDD-hhmmss' tz='Asia/Tokyo'}}
|
||||||
```
|
```
|
||||||
|
|
||||||
Will be used on [schedule event](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#schedule).
|
Will be used on [schedule event](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule).
|
||||||
|
|
||||||
`pattern` is a specially crafted attribute to support [Handlebars' template](https://handlebarsjs.com/guide/) with
|
`pattern` is a specially crafted attribute to support [Handlebars' template](https://handlebarsjs.com/guide/)
|
||||||
the following expressions:
|
with the following expressions:
|
||||||
* `date 'format'` ; render date by its [moment format](https://momentjs.com/docs/#/displaying/format/)
|
|
||||||
|
* `date 'format' tz='Timezone'` ; render date by its [moment format](https://momentjs.com/docs/#/displaying/format/).
|
||||||
|
Default `tz` is UTC.
|
||||||
|
|
||||||
| Pattern | Output |
|
| Pattern | Output |
|
||||||
|--------------------------|----------------------|
|
|----------------------------------------------|-------------------|
|
||||||
| `nightly` | `nightly` |
|
| `nightly` | `nightly` |
|
||||||
| `{{date 'YYYYMMDD'}}` | `20210326` |
|
| `{{date 'YYYYMMDD'}}` | `20200110` |
|
||||||
|
| `{{date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}}` | `20200110-093000` |
|
||||||
|
|
||||||
Extended attributes and default values:
|
Extended attributes and default values:
|
||||||
|
|
||||||
@@ -413,11 +467,13 @@ tags: |
|
|||||||
type=semver,pattern={{version}},value=v1.0.0
|
type=semver,pattern={{version}},value=v1.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
Will be used on a [push tag event](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push)
|
Will be used on a [push tag event](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push)
|
||||||
and requires a valid [semver](https://semver.org/) Git tag, but you can also use a custom value through `value`
|
and requires a valid [semver](https://semver.org/) Git tag, but you can also
|
||||||
attribute.
|
use a custom value through `value` attribute.
|
||||||
|
|
||||||
|
`pattern` attribute supports [Handlebars template](https://handlebarsjs.com/guide/)
|
||||||
|
with the following expressions:
|
||||||
|
|
||||||
`pattern` attribute supports [Handlebars template](https://handlebarsjs.com/guide/) with the following expressions:
|
|
||||||
* `raw` ; the actual tag
|
* `raw` ; the actual tag
|
||||||
* `version` ; shorthand for `{{major}}.{{minor}}.{{patch}}` (can include pre-release)
|
* `version` ; shorthand for `{{major}}.{{minor}}.{{patch}}` (can include pre-release)
|
||||||
* `major` ; major version identifier
|
* `major` ; major version identifier
|
||||||
@@ -436,9 +492,10 @@ attribute.
|
|||||||
| `v2.0.8-beta.67` | `{{version}}` | `2.0.8-beta.67` |
|
| `v2.0.8-beta.67` | `{{version}}` | `2.0.8-beta.67` |
|
||||||
| `v2.0.8-beta.67` | `{{major}}.{{minor}}` | `2.0.8-beta.67`* |
|
| `v2.0.8-beta.67` | `{{major}}.{{minor}}` | `2.0.8-beta.67`* |
|
||||||
|
|
||||||
> *Pre-release (rc, beta, alpha) will only extend `{{version}}` (or `{{raw}}` if specified) as tag
|
> *Pre-release (rc, beta, alpha) will only extend `{{version}}` (or `{{raw}}`
|
||||||
> because they are updated frequently, and contain many breaking changes that are (by the author's design)
|
> if specified) as tag because they are updated frequently, and contain many
|
||||||
> not yet fit for public consumption.
|
> breaking changes that are (by the author's design) not yet fit for public
|
||||||
|
> consumption.
|
||||||
|
|
||||||
Extended attributes and default values:
|
Extended attributes and default values:
|
||||||
|
|
||||||
@@ -457,11 +514,13 @@ tags: |
|
|||||||
type=pep440,pattern={{version}},value=1.0.0
|
type=pep440,pattern={{version}},value=1.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
Will be used on a [push tag event](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push)
|
Will be used on a [push tag event](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push)
|
||||||
and requires a Git tag that conforms to [PEP 440](https://www.python.org/dev/peps/pep-0440/), but you can also use a
|
and requires a Git tag that conforms to [PEP 440](https://www.python.org/dev/peps/pep-0440/),
|
||||||
custom value through `value` attribute.
|
but you can also use a custom value through `value` attribute.
|
||||||
|
|
||||||
|
`pattern` attribute supports [Handlebars template](https://handlebarsjs.com/guide/)
|
||||||
|
with the following expressions:
|
||||||
|
|
||||||
`pattern` attribute supports [Handlebars template](https://handlebarsjs.com/guide/) with the following expressions:
|
|
||||||
* `raw` ; the actual tag
|
* `raw` ; the actual tag
|
||||||
* `version` ; cleaned version
|
* `version` ; cleaned version
|
||||||
* `major` ; major version identifier
|
* `major` ; major version identifier
|
||||||
@@ -482,9 +541,10 @@ custom value through `value` attribute.
|
|||||||
| `1.2.3beta2` | `{{major}}.{{minor}}` | `1.2.3b2`* |
|
| `1.2.3beta2` | `{{major}}.{{minor}}` | `1.2.3b2`* |
|
||||||
| `1.0dev4` | `{{major}}.{{minor}}` | `1.0.dev4`* |
|
| `1.0dev4` | `{{major}}.{{minor}}` | `1.0.dev4`* |
|
||||||
|
|
||||||
> *dev/pre/post release will only extend `{{version}}` (or `{{raw}}` if specified) as tag
|
> *dev/pre/post release will only extend `{{version}}` (or `{{raw}}` if
|
||||||
> because they are updated frequently, and contain many breaking changes that are (by the author's design)
|
> specified) as tag because they are updated frequently, and contain many
|
||||||
> not yet fit for public consumption.
|
> breaking changes that are (by the author's design) not yet fit for public
|
||||||
|
> consumption.
|
||||||
|
|
||||||
Extended attributes and default values:
|
Extended attributes and default values:
|
||||||
|
|
||||||
@@ -505,9 +565,9 @@ tags: |
|
|||||||
type=match,pattern=v(.*),group=1,value=v1.0.0
|
type=match,pattern=v(.*),group=1,value=v1.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
Can create a regular expression for matching Git tag with a pattern and capturing group. Will be used on a
|
Can create a regular expression for matching Git tag with a pattern and
|
||||||
[push tag event](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push) but, you can also use
|
capturing group. Will be used on a [push tag event](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push)
|
||||||
a custom value through `value` attribute.
|
but, you can also use a custom value through `value` attribute.
|
||||||
|
|
||||||
| Git tag | Pattern | Group | Output |
|
| Git tag | Pattern | Group | Output |
|
||||||
|-------------------------|------------------|---------|------------------------|
|
|-------------------------|------------------|---------|------------------------|
|
||||||
@@ -534,9 +594,9 @@ tags: |
|
|||||||
type=edge,branch=main
|
type=edge,branch=main
|
||||||
```
|
```
|
||||||
|
|
||||||
An `edge` tag reflects the last commit of the active branch on your Git repository. I usually prefer to use `edge`
|
An `edge` tag reflects the last commit of the active branch on your Git
|
||||||
as a Docker tag for a better distinction or common pattern. This is also used by official images
|
repository. I usually prefer to use `edge` as a Docker tag for a better
|
||||||
like [Alpine](https://hub.docker.com/_/alpine).
|
distinction or common pattern. This is also used by official images like [Alpine](https://hub.docker.com/_/alpine).
|
||||||
|
|
||||||
Extended attributes and default values:
|
Extended attributes and default values:
|
||||||
|
|
||||||
@@ -558,17 +618,19 @@ tags: |
|
|||||||
```
|
```
|
||||||
|
|
||||||
This type handles Git ref (or reference) for the following events:
|
This type handles Git ref (or reference) for the following events:
|
||||||
|
|
||||||
* `branch` ; eg. `refs/heads/master`
|
* `branch` ; eg. `refs/heads/master`
|
||||||
* `tag` ; eg. `refs/tags/v1.0.0`
|
* `tag` ; eg. `refs/tags/v1.0.0`
|
||||||
* `pr` ; eg. `refs/pull/318/merge`
|
* `pr` ; eg. `refs/pull/318/merge`
|
||||||
|
|
||||||
| Event | Ref | Output |
|
| Event | Ref | Output |
|
||||||
|-----------------|-------------------------------|-------------------------------|
|
|---------------------|-------------------------------|------------------|
|
||||||
| `pull_request` | `refs/pull/2/merge` | `pr-2` |
|
| `pull_request` | `refs/pull/2/merge` | `pr-2` |
|
||||||
| `push` | `refs/heads/master` | `master` |
|
| `push` | `refs/heads/master` | `master` |
|
||||||
| `push` | `refs/heads/my/branch` | `my-branch` |
|
| `push` | `refs/heads/my/branch` | `my-branch` |
|
||||||
| `push tag` | `refs/tags/v1.2.3` | `v1.2.3` |
|
| `push tag` | `refs/tags/v1.2.3` | `v1.2.3` |
|
||||||
| `push tag` | `refs/tags/v2.0.8-beta.67` | `v2.0.8-beta.67` |
|
| `push tag` | `refs/tags/v2.0.8-beta.67` | `v2.0.8-beta.67` |
|
||||||
|
| `workflow_dispatch` | `refs/heads/master` | `master` |
|
||||||
|
|
||||||
Extended attributes and default values:
|
Extended attributes and default values:
|
||||||
|
|
||||||
@@ -628,7 +690,7 @@ tags: |
|
|||||||
|
|
||||||
### Image name and tag sanitization
|
### Image name and tag sanitization
|
||||||
|
|
||||||
In order to comply with [the specification](https://docs.docker.com/engine/reference/commandline/tag/#extended-description),
|
In order to comply with [the specification](https://docs.docker.com/engine/reference/commandline/tag/#description),
|
||||||
the image name components may contain lowercase letters, digits and separators.
|
the image name components may contain lowercase letters, digits and separators.
|
||||||
A separator is defined as a period, one or two underscores, or one or more
|
A separator is defined as a period, one or two underscores, or one or more
|
||||||
dashes. A name component may not start or end with a separator.
|
dashes. A name component may not start or end with a separator.
|
||||||
@@ -644,7 +706,9 @@ To ease the integration in your workflow, this action will automatically:
|
|||||||
|
|
||||||
### Latest tag
|
### Latest tag
|
||||||
|
|
||||||
`latest` tag is handled through the [`flavor` input](#flavor-input). It will be generated by default (`auto` mode) for:
|
`latest` tag is handled through the [`flavor` input](#flavor-input). It will be
|
||||||
|
generated by default (`auto` mode) for:
|
||||||
|
|
||||||
* [`type=ref,event=tag`](#typeref)
|
* [`type=ref,event=tag`](#typeref)
|
||||||
* [`type=semver,pattern=...`](#typesemver)
|
* [`type=semver,pattern=...`](#typesemver)
|
||||||
* [`type=match,pattern=...`](#typematch)
|
* [`type=match,pattern=...`](#typematch)
|
||||||
@@ -667,6 +731,24 @@ tags: |
|
|||||||
type=raw,value=latest,enable={{is_default_branch}}
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `priority` attribute
|
||||||
|
|
||||||
|
`priority=<int>` attribute is used to sort tags in the final list. The higher
|
||||||
|
the value, the higher the priority. The first tag in the list (higher priority)
|
||||||
|
will be used as the image version for generated OCI label and [`version` output](#outputs).
|
||||||
|
Each tags `type` attribute has a default priority:
|
||||||
|
|
||||||
|
| Attribute | Default priority |
|
||||||
|
|------------|------------------|
|
||||||
|
| `schedule` | `1000` |
|
||||||
|
| `semver` | `900` |
|
||||||
|
| `pep440` | `900` |
|
||||||
|
| `match` | `800` |
|
||||||
|
| `edge` | `700` |
|
||||||
|
| `ref` | `600` |
|
||||||
|
| `raw` | `200` |
|
||||||
|
| `sha` | `100` |
|
||||||
|
|
||||||
### Global expressions
|
### Global expressions
|
||||||
|
|
||||||
The following [Handlebars' template](https://handlebarsjs.com/guide/) expressions
|
The following [Handlebars' template](https://handlebarsjs.com/guide/) expressions
|
||||||
@@ -686,7 +768,7 @@ Returns the branch name that triggered the workflow run. Will be empty if not
|
|||||||
a branch reference:
|
a branch reference:
|
||||||
|
|
||||||
| Event | Ref | Output |
|
| Event | Ref | Output |
|
||||||
|-----------------|-------------------------------|---------------------|
|
|----------------|------------------------|-------------|
|
||||||
| `pull_request` | `refs/pull/2/merge` | |
|
| `pull_request` | `refs/pull/2/merge` | |
|
||||||
| `push` | `refs/heads/master` | `master` |
|
| `push` | `refs/heads/master` | `master` |
|
||||||
| `push` | `refs/heads/my/branch` | `my-branch` |
|
| `push` | `refs/heads/my/branch` | `my-branch` |
|
||||||
@@ -731,22 +813,24 @@ workflow run. Will be empty for a branch reference:
|
|||||||
Returns `true` if the branch that triggered the workflow run is the default
|
Returns `true` if the branch that triggered the workflow run is the default
|
||||||
one, otherwise `false`.
|
one, otherwise `false`.
|
||||||
|
|
||||||
#### `{{date '<format>'}}`
|
#### `{{date '<format>' tz='<timezone>'}}`
|
||||||
|
|
||||||
Returns the current date rendered by its [moment format](https://momentjs.com/docs/#/displaying/format/).
|
Returns the current date rendered by its [moment format](https://momentjs.com/docs/#/displaying/format/).
|
||||||
|
Default `tz` is UTC.
|
||||||
|
|
||||||
| Expression | Output example |
|
| Expression | Output example |
|
||||||
|--------------------------------------------|-----------------------------------------|
|
|----------------------------------------------|-----------------------------------------|
|
||||||
| `{{date 'YYYYMMDD'}}` | `20200110` |
|
| `{{date 'YYYYMMDD'}}` | `20200110` |
|
||||||
| `{{date 'dddd, MMMM Do YYYY, h:mm:ss a'}}` | `Friday, January 10th 2020, 3:25:50 pm` |
|
| `{{date 'dddd, MMMM Do YYYY, h:mm:ss a'}}` | `Friday, January 10th 2020, 3:25:50 pm` |
|
||||||
|
| `{{date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}}` | `20200110-093000` |
|
||||||
|
|
||||||
### Major version zero
|
### Major version zero
|
||||||
|
|
||||||
Major version zero (`0.y.z`) is for initial development and **may** change at any time. This means the public API
|
Major version zero (`0.y.z`) is for initial development and **may** change at
|
||||||
[**should not** be considered stable](https://semver.org/#spec-item-4).
|
any time. This means the public API [**should not** be considered stable](https://semver.org/#spec-item-4).
|
||||||
|
|
||||||
In this case, Docker tag `0` **should not** be generated if you're using [`type=semver`](#typesemver) with `{{major}}`
|
In this case, Docker tag `0` **should not** be generated if you're using [`type=semver`](#typesemver)
|
||||||
pattern. You can manage this behavior like this:
|
with `{{major}}` pattern. You can manage this behavior like this:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# refs/tags/v0.1.2
|
# refs/tags/v0.1.2
|
||||||
@@ -761,8 +845,8 @@ tags: |
|
|||||||
|
|
||||||
### JSON output object
|
### JSON output object
|
||||||
|
|
||||||
The `json` output is a JSON object composed of the generated tags and labels so that you can reuse them further in your
|
The `json` output is a JSON object composed of the generated tags and labels so
|
||||||
workflow using the [`fromJSON` function](https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson):
|
that you can reuse them further in your workflow using the [`fromJSON` function](https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson):
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
-
|
-
|
||||||
@@ -773,7 +857,7 @@ workflow using the [`fromJSON` function](https://docs.github.com/en/actions/lear
|
|||||||
images: name/app
|
images: name/app
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
@@ -802,18 +886,7 @@ labels generated are not suitable, you can overwrite them like this:
|
|||||||
org.opencontainers.image.vendor=MyCompany
|
org.opencontainers.image.vendor=MyCompany
|
||||||
```
|
```
|
||||||
|
|
||||||
## Keep up-to-date with GitHub Dependabot
|
## Contributing
|
||||||
|
|
||||||
Since [Dependabot](https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-github-dependabot)
|
Want to contribute? Awesome! You can find information about contributing to
|
||||||
has [native GitHub Actions support](https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#package-ecosystem),
|
this project in the [CONTRIBUTING.md](/.github/CONTRIBUTING.md)
|
||||||
to enable it on your GitHub repo all you need to do is add the `.github/dependabot.yml` file:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
version: 2
|
|
||||||
updates:
|
|
||||||
# Maintain dependencies for GitHub Actions
|
|
||||||
- package-ecosystem: "github-actions"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "daily"
|
|
||||||
```
|
|
||||||
|
27
UPGRADE.md
27
UPGRADE.md
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
## v2 to v3
|
## v2 to v3
|
||||||
|
|
||||||
* Repository has been moved to docker org. Replace `crazy-max/ghaction-docker-meta@v2` with `docker/metadata-action@v4`
|
* Repository has been moved to docker org. Replace `crazy-max/ghaction-docker-meta@v2`
|
||||||
|
with `docker/metadata-action@v4`
|
||||||
* The default bake target has been changed: `ghaction-docker-meta` > `docker-metadata-action`
|
* The default bake target has been changed: `ghaction-docker-meta` > `docker-metadata-action`
|
||||||
|
|
||||||
## v1 to v2
|
## v1 to v2
|
||||||
@@ -132,7 +133,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
@@ -142,13 +143,13 @@ jobs:
|
|||||||
-
|
-
|
||||||
name: Login to DockerHub
|
name: Login to DockerHub
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
@@ -176,7 +177,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
@@ -186,13 +187,13 @@ jobs:
|
|||||||
-
|
-
|
||||||
name: Login to DockerHub
|
name: Login to DockerHub
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
@@ -222,7 +223,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
@@ -235,13 +236,13 @@ jobs:
|
|||||||
-
|
-
|
||||||
name: Login to DockerHub
|
name: Login to DockerHub
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
@@ -269,7 +270,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
-
|
-
|
||||||
name: Docker meta
|
name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
@@ -284,13 +285,13 @@ jobs:
|
|||||||
-
|
-
|
||||||
name: Login to DockerHub
|
name: Login to DockerHub
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
207
__mocks__/@actions/github.ts
Normal file
207
__mocks__/@actions/github.ts
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
import {jest} from '@jest/globals';
|
||||||
|
|
||||||
|
export const context = {
|
||||||
|
repo: {
|
||||||
|
owner: 'docker',
|
||||||
|
repo: 'actions-toolkit'
|
||||||
|
},
|
||||||
|
ref: 'refs/heads/master',
|
||||||
|
runId: 123,
|
||||||
|
payload: {
|
||||||
|
after: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
||||||
|
base_ref: null,
|
||||||
|
before: '5f3331d7f7044c18ca9f12c77d961c4d7cf3276a',
|
||||||
|
commits: [
|
||||||
|
{
|
||||||
|
author: {
|
||||||
|
email: 'crazy-max@users.noreply.github.com',
|
||||||
|
name: 'CrazyMax',
|
||||||
|
username: 'crazy-max'
|
||||||
|
},
|
||||||
|
committer: {
|
||||||
|
email: 'crazy-max@users.noreply.github.com',
|
||||||
|
name: 'CrazyMax',
|
||||||
|
username: 'crazy-max'
|
||||||
|
},
|
||||||
|
distinct: true,
|
||||||
|
id: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
||||||
|
message: 'hello dev',
|
||||||
|
timestamp: '2022-04-19T11:27:24+02:00',
|
||||||
|
tree_id: 'd2c60af597e863787d2d27f569e30495b0b92820',
|
||||||
|
url: 'https://github.com/docker/test-docker-action/commit/860c1904a1ce19322e91ac35af1ab07466440c37'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
compare: 'https://github.com/docker/test-docker-action/compare/5f3331d7f704...860c1904a1ce',
|
||||||
|
created: false,
|
||||||
|
deleted: false,
|
||||||
|
forced: false,
|
||||||
|
head_commit: {
|
||||||
|
author: {
|
||||||
|
email: 'crazy-max@users.noreply.github.com',
|
||||||
|
name: 'CrazyMax',
|
||||||
|
username: 'crazy-max'
|
||||||
|
},
|
||||||
|
committer: {
|
||||||
|
email: 'crazy-max@users.noreply.github.com',
|
||||||
|
name: 'CrazyMax',
|
||||||
|
username: 'crazy-max'
|
||||||
|
},
|
||||||
|
distinct: true,
|
||||||
|
id: '860c1904a1ce19322e91ac35af1ab07466440c37',
|
||||||
|
message: 'hello dev',
|
||||||
|
timestamp: '2022-04-19T11:27:24+02:00',
|
||||||
|
tree_id: 'd2c60af597e863787d2d27f569e30495b0b92820',
|
||||||
|
url: 'https://github.com/docker/test-docker-action/commit/860c1904a1ce19322e91ac35af1ab07466440c37'
|
||||||
|
},
|
||||||
|
organization: {
|
||||||
|
avatar_url: 'https://avatars.githubusercontent.com/u/5429470?v=4',
|
||||||
|
description: 'Docker helps developers bring their ideas to life by conquering the complexity of app development.',
|
||||||
|
events_url: 'https://api.github.com/orgs/docker/events',
|
||||||
|
hooks_url: 'https://api.github.com/orgs/docker/hooks',
|
||||||
|
id: 5429470,
|
||||||
|
issues_url: 'https://api.github.com/orgs/docker/issues',
|
||||||
|
login: 'docker',
|
||||||
|
members_url: 'https://api.github.com/orgs/docker/members{/member}',
|
||||||
|
node_id: 'MDEyOk9yZ2FuaXphdGlvbjU0Mjk0NzA=',
|
||||||
|
public_members_url: 'https://api.github.com/orgs/docker/public_members{/member}',
|
||||||
|
repos_url: 'https://api.github.com/orgs/docker/repos',
|
||||||
|
url: 'https://api.github.com/orgs/docker'
|
||||||
|
},
|
||||||
|
pusher: {
|
||||||
|
email: 'github@crazymax.dev',
|
||||||
|
name: 'crazy-max'
|
||||||
|
},
|
||||||
|
ref: 'refs/heads/dev',
|
||||||
|
repository: {
|
||||||
|
allow_forking: true,
|
||||||
|
archive_url: 'https://api.github.com/repos/docker/test-docker-action/{archive_format}{/ref}',
|
||||||
|
archived: false,
|
||||||
|
assignees_url: 'https://api.github.com/repos/docker/test-docker-action/assignees{/user}',
|
||||||
|
blobs_url: 'https://api.github.com/repos/docker/test-docker-action/git/blobs{/sha}',
|
||||||
|
branches_url: 'https://api.github.com/repos/docker/test-docker-action/branches{/branch}',
|
||||||
|
clone_url: 'https://github.com/docker/test-docker-action.git',
|
||||||
|
collaborators_url: 'https://api.github.com/repos/docker/test-docker-action/collaborators{/collaborator}',
|
||||||
|
comments_url: 'https://api.github.com/repos/docker/test-docker-action/comments{/number}',
|
||||||
|
commits_url: 'https://api.github.com/repos/docker/test-docker-action/commits{/sha}',
|
||||||
|
compare_url: 'https://api.github.com/repos/docker/test-docker-action/compare/{base}...{head}',
|
||||||
|
contents_url: 'https://api.github.com/repos/docker/test-docker-action/contents/{+path}',
|
||||||
|
contributors_url: 'https://api.github.com/repos/docker/test-docker-action/contributors',
|
||||||
|
created_at: 1596792180,
|
||||||
|
default_branch: 'master',
|
||||||
|
deployments_url: 'https://api.github.com/repos/docker/test-docker-action/deployments',
|
||||||
|
description: 'Test "Docker" Actions',
|
||||||
|
disabled: false,
|
||||||
|
downloads_url: 'https://api.github.com/repos/docker/test-docker-action/downloads',
|
||||||
|
events_url: 'https://api.github.com/repos/docker/test-docker-action/events',
|
||||||
|
fork: false,
|
||||||
|
forks: 1,
|
||||||
|
forks_count: 1,
|
||||||
|
forks_url: 'https://api.github.com/repos/docker/test-docker-action/forks',
|
||||||
|
full_name: 'docker/test-docker-action',
|
||||||
|
git_commits_url: 'https://api.github.com/repos/docker/test-docker-action/git/commits{/sha}',
|
||||||
|
git_refs_url: 'https://api.github.com/repos/docker/test-docker-action/git/refs{/sha}',
|
||||||
|
git_tags_url: 'https://api.github.com/repos/docker/test-docker-action/git/tags{/sha}',
|
||||||
|
git_url: 'git://github.com/docker/test-docker-action.git',
|
||||||
|
has_downloads: true,
|
||||||
|
has_issues: true,
|
||||||
|
has_pages: false,
|
||||||
|
has_projects: true,
|
||||||
|
has_wiki: true,
|
||||||
|
homepage: '',
|
||||||
|
hooks_url: 'https://api.github.com/repos/docker/test-docker-action/hooks',
|
||||||
|
html_url: 'https://github.com/docker/test-docker-action',
|
||||||
|
id: 285789493,
|
||||||
|
is_template: false,
|
||||||
|
issue_comment_url: 'https://api.github.com/repos/docker/test-docker-action/issues/comments{/number}',
|
||||||
|
issue_events_url: 'https://api.github.com/repos/docker/test-docker-action/issues/events{/number}',
|
||||||
|
issues_url: 'https://api.github.com/repos/docker/test-docker-action/issues{/number}',
|
||||||
|
keys_url: 'https://api.github.com/repos/docker/test-docker-action/keys{/key_id}',
|
||||||
|
labels_url: 'https://api.github.com/repos/docker/test-docker-action/labels{/name}',
|
||||||
|
language: 'JavaScript',
|
||||||
|
languages_url: 'https://api.github.com/repos/docker/test-docker-action/languages',
|
||||||
|
license: {
|
||||||
|
key: 'mit',
|
||||||
|
name: 'MIT License',
|
||||||
|
node_id: 'MDc6TGljZW5zZTEz',
|
||||||
|
spdx_id: 'MIT',
|
||||||
|
url: 'https://api.github.com/licenses/mit'
|
||||||
|
},
|
||||||
|
master_branch: 'master',
|
||||||
|
merges_url: 'https://api.github.com/repos/docker/test-docker-action/merges',
|
||||||
|
milestones_url: 'https://api.github.com/repos/docker/test-docker-action/milestones{/number}',
|
||||||
|
mirror_url: null,
|
||||||
|
name: 'test-docker-action',
|
||||||
|
node_id: 'MDEwOlJlcG9zaXRvcnkyODU3ODk0OTM=',
|
||||||
|
notifications_url: 'https://api.github.com/repos/docker/test-docker-action/notifications{?since,all,participating}',
|
||||||
|
open_issues: 6,
|
||||||
|
open_issues_count: 6,
|
||||||
|
organization: 'docker',
|
||||||
|
owner: {
|
||||||
|
avatar_url: 'https://avatars.githubusercontent.com/u/5429470?v=4',
|
||||||
|
email: 'info@docker.com',
|
||||||
|
events_url: 'https://api.github.com/users/docker/events{/privacy}',
|
||||||
|
followers_url: 'https://api.github.com/users/docker/followers',
|
||||||
|
following_url: 'https://api.github.com/users/docker/following{/other_user}',
|
||||||
|
gists_url: 'https://api.github.com/users/docker/gists{/gist_id}',
|
||||||
|
gravatar_id: '',
|
||||||
|
html_url: 'https://github.com/docker',
|
||||||
|
id: 5429470,
|
||||||
|
login: 'docker',
|
||||||
|
name: 'docker',
|
||||||
|
node_id: 'MDEyOk9yZ2FuaXphdGlvbjU0Mjk0NzA=',
|
||||||
|
organizations_url: 'https://api.github.com/users/docker/orgs',
|
||||||
|
received_events_url: 'https://api.github.com/users/docker/received_events',
|
||||||
|
repos_url: 'https://api.github.com/users/docker/repos',
|
||||||
|
site_admin: false,
|
||||||
|
starred_url: 'https://api.github.com/users/docker/starred{/owner}{/repo}',
|
||||||
|
subscriptions_url: 'https://api.github.com/users/docker/subscriptions',
|
||||||
|
type: 'Organization',
|
||||||
|
url: 'https://api.github.com/users/docker'
|
||||||
|
},
|
||||||
|
private: true,
|
||||||
|
pulls_url: 'https://api.github.com/repos/docker/test-docker-action/pulls{/number}',
|
||||||
|
pushed_at: 1650360446,
|
||||||
|
releases_url: 'https://api.github.com/repos/docker/test-docker-action/releases{/id}',
|
||||||
|
size: 796,
|
||||||
|
ssh_url: 'git@github.com:docker/test-docker-action.git',
|
||||||
|
stargazers: 0,
|
||||||
|
stargazers_count: 0,
|
||||||
|
stargazers_url: 'https://api.github.com/repos/docker/test-docker-action/stargazers',
|
||||||
|
statuses_url: 'https://api.github.com/repos/docker/test-docker-action/statuses/{sha}',
|
||||||
|
subscribers_url: 'https://api.github.com/repos/docker/test-docker-action/subscribers',
|
||||||
|
subscription_url: 'https://api.github.com/repos/docker/test-docker-action/subscription',
|
||||||
|
svn_url: 'https://github.com/docker/test-docker-action',
|
||||||
|
tags_url: 'https://api.github.com/repos/docker/test-docker-action/tags',
|
||||||
|
teams_url: 'https://api.github.com/repos/docker/test-docker-action/teams',
|
||||||
|
topics: [],
|
||||||
|
trees_url: 'https://api.github.com/repos/docker/test-docker-action/git/trees{/sha}',
|
||||||
|
updated_at: '2022-04-19T09:05:09Z',
|
||||||
|
url: 'https://github.com/docker/test-docker-action',
|
||||||
|
visibility: 'private',
|
||||||
|
watchers: 0,
|
||||||
|
watchers_count: 0
|
||||||
|
},
|
||||||
|
sender: {
|
||||||
|
avatar_url: 'https://avatars.githubusercontent.com/u/1951866?v=4',
|
||||||
|
events_url: 'https://api.github.com/users/crazy-max/events{/privacy}',
|
||||||
|
followers_url: 'https://api.github.com/users/crazy-max/followers',
|
||||||
|
following_url: 'https://api.github.com/users/crazy-max/following{/other_user}',
|
||||||
|
gists_url: 'https://api.github.com/users/crazy-max/gists{/gist_id}',
|
||||||
|
gravatar_id: '',
|
||||||
|
html_url: 'https://github.com/crazy-max',
|
||||||
|
id: 1951866,
|
||||||
|
login: 'crazy-max',
|
||||||
|
node_id: 'MDQ6VXNlcjE5NTE4NjY=',
|
||||||
|
organizations_url: 'https://api.github.com/users/crazy-max/orgs',
|
||||||
|
received_events_url: 'https://api.github.com/users/crazy-max/received_events',
|
||||||
|
repos_url: 'https://api.github.com/users/crazy-max/repos',
|
||||||
|
site_admin: false,
|
||||||
|
starred_url: 'https://api.github.com/users/crazy-max/starred{/owner}{/repo}',
|
||||||
|
subscriptions_url: 'https://api.github.com/users/crazy-max/subscriptions',
|
||||||
|
type: 'User',
|
||||||
|
url: 'https://api.github.com/users/crazy-max'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getOctokit = jest.fn();
|
@@ -1,192 +1,126 @@
|
|||||||
import {beforeEach, describe, expect, it, jest} from '@jest/globals';
|
import {afterEach, beforeEach, describe, expect, test, it, jest} from '@jest/globals';
|
||||||
|
import * as dotenv from 'dotenv';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as os from 'os';
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import {Context} from '@actions/github/lib/context';
|
||||||
|
import {Git} from '@docker/actions-toolkit/lib/git';
|
||||||
|
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
||||||
|
|
||||||
import * as context from '../src/context';
|
import {ContextSource, getContext, getInputs, Inputs} from '../src/context';
|
||||||
|
|
||||||
jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
|
beforeEach(() => {
|
||||||
const tmpDir = path.join('/tmp/.docker-metadata-action-jest').split(path.sep).join(path.posix.sep);
|
jest.clearAllMocks();
|
||||||
if (!fs.existsSync(tmpDir)) {
|
jest.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => {
|
||||||
fs.mkdirSync(tmpDir, {recursive: true});
|
return new Context();
|
||||||
}
|
|
||||||
return tmpDir;
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getInputList', () => {
|
|
||||||
it('single line correctly', async () => {
|
|
||||||
await setInput('foo', 'bar');
|
|
||||||
const res = context.getInputList('foo');
|
|
||||||
expect(res).toEqual(['bar']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('multiline correctly', async () => {
|
|
||||||
setInput('foo', 'bar\nbaz');
|
|
||||||
const res = context.getInputList('foo');
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('empty lines correctly', async () => {
|
|
||||||
setInput('foo', 'bar\n\nbaz');
|
|
||||||
const res = context.getInputList('foo');
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('comment correctly', async () => {
|
|
||||||
setInput('foo', 'bar\n#com\n"#taken"\nhello#comment\nbaz');
|
|
||||||
const res = context.getInputList('foo');
|
|
||||||
expect(res).toEqual(['bar', '#taken', 'hello', 'baz']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('comma correctly', async () => {
|
|
||||||
setInput('foo', 'bar,baz');
|
|
||||||
const res = context.getInputList('foo');
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('empty result correctly', async () => {
|
|
||||||
setInput('foo', 'bar,baz,');
|
|
||||||
const res = context.getInputList('foo');
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('different new lines correctly', async () => {
|
|
||||||
setInput('foo', 'bar\r\nbaz');
|
|
||||||
const res = context.getInputList('foo');
|
|
||||||
expect(res).toEqual(['bar', 'baz']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('different new lines and comma correctly', async () => {
|
|
||||||
setInput('foo', 'bar\r\nbaz,bat');
|
|
||||||
const res = context.getInputList('foo');
|
|
||||||
expect(res).toEqual(['bar', 'baz', 'bat']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('multiline and ignoring comma correctly', async () => {
|
|
||||||
setInput('cache-from', 'user/app:cache\ntype=local,src=path/to/dir');
|
|
||||||
const res = context.getInputList('cache-from', true);
|
|
||||||
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('different new lines and ignoring comma correctly', async () => {
|
|
||||||
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
|
|
||||||
const res = context.getInputList('cache-from', true);
|
|
||||||
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('multiline values', async () => {
|
|
||||||
setInput(
|
|
||||||
'secrets',
|
|
||||||
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
|
|
||||||
"MYSECRET=aaaaaaaa
|
|
||||||
bbbbbbb
|
|
||||||
ccccccccc"
|
|
||||||
FOO=bar`
|
|
||||||
);
|
|
||||||
const res = context.getInputList('secrets', true);
|
|
||||||
expect(res).toEqual([
|
|
||||||
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
|
||||||
`MYSECRET=aaaaaaaa
|
|
||||||
bbbbbbb
|
|
||||||
ccccccccc`,
|
|
||||||
'FOO=bar'
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('multiline values with empty lines', async () => {
|
|
||||||
setInput(
|
|
||||||
'secrets',
|
|
||||||
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
|
|
||||||
"MYSECRET=aaaaaaaa
|
|
||||||
bbbbbbb
|
|
||||||
ccccccccc"
|
|
||||||
FOO=bar
|
|
||||||
"EMPTYLINE=aaaa
|
|
||||||
|
|
||||||
bbbb
|
|
||||||
ccc"`
|
|
||||||
);
|
|
||||||
const res = context.getInputList('secrets', true);
|
|
||||||
expect(res).toEqual([
|
|
||||||
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
|
||||||
`MYSECRET=aaaaaaaa
|
|
||||||
bbbbbbb
|
|
||||||
ccccccccc`,
|
|
||||||
'FOO=bar',
|
|
||||||
`EMPTYLINE=aaaa
|
|
||||||
|
|
||||||
bbbb
|
|
||||||
ccc`
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('multiline values without quotes', async () => {
|
|
||||||
setInput(
|
|
||||||
'secrets',
|
|
||||||
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
|
|
||||||
MYSECRET=aaaaaaaa
|
|
||||||
bbbbbbb
|
|
||||||
ccccccccc
|
|
||||||
FOO=bar`
|
|
||||||
);
|
|
||||||
const res = context.getInputList('secrets', true);
|
|
||||||
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('multiline values escape quotes', async () => {
|
|
||||||
setInput(
|
|
||||||
'secrets',
|
|
||||||
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
|
|
||||||
"MYSECRET=aaaaaaaa
|
|
||||||
bbbb""bbb
|
|
||||||
ccccccccc"
|
|
||||||
FOO=bar`
|
|
||||||
);
|
|
||||||
const res = context.getInputList('secrets', true);
|
|
||||||
expect(res).toEqual([
|
|
||||||
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
|
||||||
`MYSECRET=aaaaaaaa
|
|
||||||
bbbb"bbb
|
|
||||||
ccccccccc`,
|
|
||||||
'FOO=bar'
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('asyncForEach', () => {
|
describe('getInputs', () => {
|
||||||
it('executes async tasks sequentially', async () => {
|
|
||||||
const testValues = [1, 2, 3, 4, 5];
|
|
||||||
const results: number[] = [];
|
|
||||||
|
|
||||||
await context.asyncForEach(testValues, async value => {
|
|
||||||
results.push(value);
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(results).toEqual(testValues);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('setOutput', () => {
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.stdout.write = jest.fn() as typeof process.stdout.write;
|
process.env = Object.keys(process.env).reduce((object, key) => {
|
||||||
|
if (!key.startsWith('INPUT_')) {
|
||||||
|
object[key] = process.env[key];
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
}, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
// eslint-disable-next-line jest/expect-expect
|
// prettier-ignore
|
||||||
it('setOutput produces the correct command', () => {
|
test.each([
|
||||||
context.setOutput('some output', 'some value');
|
[
|
||||||
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]);
|
0,
|
||||||
|
new Map<string, string>([
|
||||||
|
['images', 'moby/buildkit\nghcr.io/moby/mbuildkit'],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
context: ContextSource.workflow,
|
||||||
|
bakeTarget: 'docker-metadata-action',
|
||||||
|
flavor: [],
|
||||||
|
githubToken: '',
|
||||||
|
images: ['moby/buildkit', 'ghcr.io/moby/mbuildkit'],
|
||||||
|
labels: [],
|
||||||
|
sepLabels: '\n',
|
||||||
|
sepTags: '\n',
|
||||||
|
tags: [],
|
||||||
|
} as Inputs
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
new Map<string, string>([
|
||||||
|
['bake-target', 'metadata'],
|
||||||
|
['images', 'moby/buildkit'],
|
||||||
|
['sep-labels', ','],
|
||||||
|
['sep-tags', ','],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
context: ContextSource.workflow,
|
||||||
|
bakeTarget: 'metadata',
|
||||||
|
flavor: [],
|
||||||
|
githubToken: '',
|
||||||
|
images: ['moby/buildkit'],
|
||||||
|
labels: [],
|
||||||
|
sepLabels: ',',
|
||||||
|
sepTags: ',',
|
||||||
|
tags: [],
|
||||||
|
} as Inputs
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2,
|
||||||
|
new Map<string, string>([
|
||||||
|
['images', 'moby/buildkit\n#comment\nghcr.io/moby/mbuildkit'],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
context: ContextSource.workflow,
|
||||||
|
bakeTarget: 'docker-metadata-action',
|
||||||
|
flavor: [],
|
||||||
|
githubToken: '',
|
||||||
|
images: ['moby/buildkit', 'ghcr.io/moby/mbuildkit'],
|
||||||
|
labels: [],
|
||||||
|
sepLabels: '\n',
|
||||||
|
sepTags: '\n',
|
||||||
|
tags: [],
|
||||||
|
} as Inputs
|
||||||
|
],
|
||||||
|
])(
|
||||||
|
'[%d] given %p as inputs, returns %p',
|
||||||
|
async (num: number, inputs: Map<string, string>, expected: Inputs) => {
|
||||||
|
inputs.forEach((value: string, name: string) => {
|
||||||
|
setInput(name, value);
|
||||||
|
});
|
||||||
|
expect(await getInputs()).toEqual(expected);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getContext', () => {
|
||||||
|
const originalEnv = process.env;
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
|
process.env = {
|
||||||
|
...originalEnv,
|
||||||
|
...dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures/event_create_branch.env')))
|
||||||
|
};
|
||||||
|
});
|
||||||
|
afterEach(() => {
|
||||||
|
process.env = originalEnv;
|
||||||
});
|
});
|
||||||
|
|
||||||
// eslint-disable-next-line jest/expect-expect
|
it('workflow', async () => {
|
||||||
it('setOutput handles bools', () => {
|
const context = await getContext(ContextSource.workflow);
|
||||||
context.setOutput('some output', false);
|
expect(context.ref).toEqual('refs/heads/dev');
|
||||||
assertWriteCalls([`::set-output name=some output::false${os.EOL}`]);
|
expect(context.sha).toEqual('5f3331d7f7044c18ca9f12c77d961c4d7cf3276a');
|
||||||
});
|
});
|
||||||
|
|
||||||
// eslint-disable-next-line jest/expect-expect
|
it('git', async () => {
|
||||||
it('setOutput handles numbers', () => {
|
jest.spyOn(Git, 'context').mockImplementation((): Promise<Context> => {
|
||||||
context.setOutput('some output', 1.01);
|
return Promise.resolve({
|
||||||
assertWriteCalls([`::set-output name=some output::1.01${os.EOL}`]);
|
ref: 'refs/heads/git-test',
|
||||||
|
sha: 'git-test-sha'
|
||||||
|
} as Context);
|
||||||
|
});
|
||||||
|
const context = await getContext(ContextSource.git);
|
||||||
|
expect(context.ref).toEqual('refs/heads/git-test');
|
||||||
|
expect(context.sha).toEqual('git-test-sha');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -198,11 +132,3 @@ function getInputName(name: string): string {
|
|||||||
function setInput(name: string, value: string): void {
|
function setInput(name: string, value: string): void {
|
||||||
process.env[getInputName(name)] = value;
|
process.env[getInputName(name)] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert that process.stdout.write calls called only with the given arguments.
|
|
||||||
function assertWriteCalls(calls: string[]): void {
|
|
||||||
expect(process.stdout.write).toHaveBeenCalledTimes(calls.length);
|
|
||||||
for (let i = 0; i < calls.length; i++) {
|
|
||||||
expect(process.stdout.write).toHaveBeenNthCalledWith(i + 1, calls[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import {describe, expect, test} from '@jest/globals';
|
import {describe, expect, test} from '@jest/globals';
|
||||||
|
|
||||||
import {Flavor, Transform} from '../src/flavor';
|
import {Flavor, Transform} from '../src/flavor';
|
||||||
|
|
||||||
describe('transform', () => {
|
describe('transform', () => {
|
||||||
|
@@ -1,14 +0,0 @@
|
|||||||
import {describe, expect, jest, it} from '@jest/globals';
|
|
||||||
import * as github from '../src/github';
|
|
||||||
|
|
||||||
import * as repoFixture from './fixtures/repo.json';
|
|
||||||
jest.spyOn(github, 'repo').mockImplementation((): Promise<github.ReposGetResponseData> => {
|
|
||||||
return <Promise<github.ReposGetResponseData>>(repoFixture as unknown);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('repo', () => {
|
|
||||||
it('returns GitHub repository', async () => {
|
|
||||||
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
|
||||||
expect(repo.name).not.toBeNull();
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,4 +1,5 @@
|
|||||||
import {describe, expect, test} from '@jest/globals';
|
import {describe, expect, test} from '@jest/globals';
|
||||||
|
|
||||||
import {Transform, Image} from '../src/image';
|
import {Transform, Image} from '../src/image';
|
||||||
|
|
||||||
describe('transform', () => {
|
describe('transform', () => {
|
||||||
@@ -86,7 +87,7 @@ describe('transform', () => {
|
|||||||
[
|
[
|
||||||
[`name/foo,name=name/bar,enable=true`], undefined, true
|
[`name/foo,name=name/bar,enable=true`], undefined, true
|
||||||
]
|
]
|
||||||
])('given %p', async (l: string[], expected: Image[], invalid: boolean) => {
|
])('given %p', async (l: string[], expected: Image[] | undefined, invalid: boolean) => {
|
||||||
try {
|
try {
|
||||||
const images = Transform(l);
|
const images = Transform(l);
|
||||||
expect(images).toEqual(expected);
|
expect(images).toEqual(expected);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
|||||||
import {describe, expect, test} from '@jest/globals';
|
import {describe, expect, test} from '@jest/globals';
|
||||||
|
|
||||||
import {Transform, Parse, Tag, Type, RefEvent, ShaFormat, DefaultPriorities} from '../src/tag';
|
import {Transform, Parse, Tag, Type, RefEvent, ShaFormat, DefaultPriorities} from '../src/tag';
|
||||||
|
|
||||||
describe('transform', () => {
|
describe('transform', () => {
|
||||||
@@ -126,6 +127,18 @@ describe('parse', () => {
|
|||||||
} as Tag,
|
} as Tag,
|
||||||
false
|
false
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
`type=schedule,enable=true,pattern={{date 'YYYYMMDD' tz='Asia/Tokyo'}}`,
|
||||||
|
{
|
||||||
|
type: Type.Schedule,
|
||||||
|
attrs: {
|
||||||
|
"priority": DefaultPriorities[Type.Schedule],
|
||||||
|
"enable": "true",
|
||||||
|
"pattern": `{{date 'YYYYMMDD' tz='Asia/Tokyo'}}`
|
||||||
|
}
|
||||||
|
} as Tag,
|
||||||
|
false
|
||||||
|
],
|
||||||
[
|
[
|
||||||
`type=semver,enable=true,pattern={{version}}`,
|
`type=semver,enable=true,pattern={{version}}`,
|
||||||
{
|
{
|
||||||
|
@@ -7,6 +7,10 @@ branding:
|
|||||||
color: 'blue'
|
color: 'blue'
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
|
context:
|
||||||
|
description: 'Where to get context data. Allowed options are "workflow" (default), "git".'
|
||||||
|
default: "workflow"
|
||||||
|
required: true
|
||||||
images:
|
images:
|
||||||
description: 'List of Docker images to use as base name for tags'
|
description: 'List of Docker images to use as base name for tags'
|
||||||
required: true
|
required: true
|
||||||
@@ -46,5 +50,5 @@ outputs:
|
|||||||
description: 'JSON output of tags and labels'
|
description: 'JSON output of tags and labels'
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node20'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
ARG NODE_VERSION=16
|
ARG NODE_VERSION=20
|
||||||
|
|
||||||
FROM node:${NODE_VERSION}-alpine AS base
|
FROM node:${NODE_VERSION}-alpine AS base
|
||||||
RUN apk add --no-cache cpio findutils git
|
RUN apk add --no-cache cpio findutils git
|
||||||
@@ -16,14 +16,14 @@ COPY --from=deps /vendor /
|
|||||||
|
|
||||||
FROM deps AS vendor-validate
|
FROM deps AS vendor-validate
|
||||||
RUN --mount=type=bind,target=.,rw <<EOT
|
RUN --mount=type=bind,target=.,rw <<EOT
|
||||||
set -e
|
set -e
|
||||||
git add -A
|
git add -A
|
||||||
cp -rf /vendor/* .
|
cp -rf /vendor/* .
|
||||||
if [ -n "$(git status --porcelain -- yarn.lock)" ]; then
|
if [ -n "$(git status --porcelain -- yarn.lock)" ]; then
|
||||||
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor-update"'
|
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor-update"'
|
||||||
git status --porcelain -- yarn.lock
|
git status --porcelain -- yarn.lock
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
FROM deps AS build
|
FROM deps AS build
|
||||||
@@ -36,14 +36,14 @@ COPY --from=build /out /
|
|||||||
|
|
||||||
FROM build AS build-validate
|
FROM build AS build-validate
|
||||||
RUN --mount=type=bind,target=.,rw <<EOT
|
RUN --mount=type=bind,target=.,rw <<EOT
|
||||||
set -e
|
set -e
|
||||||
git add -A
|
git add -A
|
||||||
cp -rf /out/* .
|
cp -rf /out/* .
|
||||||
if [ -n "$(git status --porcelain -- dist)" ]; then
|
if [ -n "$(git status --porcelain -- dist)" ]; then
|
||||||
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'
|
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'
|
||||||
git status --porcelain -- dist
|
git status --porcelain -- dist
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
FROM deps AS format
|
FROM deps AS format
|
||||||
@@ -65,7 +65,7 @@ ENV RUNNER_TEMP=/tmp/github_runner
|
|||||||
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
|
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
|
||||||
RUN --mount=type=bind,target=.,rw \
|
RUN --mount=type=bind,target=.,rw \
|
||||||
--mount=type=cache,target=/src/node_modules \
|
--mount=type=cache,target=/src/node_modules \
|
||||||
yarn run test --coverageDirectory=/tmp/coverage
|
yarn run test --coverage --coverageDirectory=/tmp/coverage
|
||||||
|
|
||||||
FROM scratch AS test-coverage
|
FROM scratch AS test-coverage
|
||||||
COPY --from=test /tmp/coverage /
|
COPY --from=test /tmp/coverage /
|
||||||
|
54
dist/index.js
generated
vendored
54
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
1273
dist/licenses.txt
generated
vendored
1273
dist/licenses.txt
generated
vendored
File diff suppressed because it is too large
Load Diff
2
dist/sourcemap-register.js
generated
vendored
2
dist/sourcemap-register.js
generated
vendored
File diff suppressed because one or more lines are too long
@@ -1,5 +1,21 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import os from 'os';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
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')
|
||||||
|
}) as {
|
||||||
|
[key: string]: string;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
clearMocks: true,
|
clearMocks: true,
|
||||||
|
testEnvironment: 'node',
|
||||||
moduleFileExtensions: ['js', 'ts'],
|
moduleFileExtensions: ['js', 'ts'],
|
||||||
setupFiles: ['dotenv/config'],
|
setupFiles: ['dotenv/config'],
|
||||||
testMatch: ['**/*.test.ts'],
|
testMatch: ['**/*.test.ts'],
|
||||||
@@ -9,5 +25,7 @@ module.exports = {
|
|||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
|
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
|
||||||
},
|
},
|
||||||
|
collectCoverageFrom: ['src/**/{!(main.ts),}.ts'],
|
||||||
|
coveragePathIgnorePatterns: ['lib/', 'node_modules/', '__mocks__/', '__tests__/'],
|
||||||
verbose: true
|
verbose: true
|
||||||
};
|
};
|
||||||
|
62
package.json
62
package.json
@@ -4,9 +4,13 @@
|
|||||||
"main": "lib/main.js",
|
"main": "lib/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build src/main.ts --source-map --minify --license licenses.txt",
|
"build": "ncc build src/main.ts --source-map --minify --license licenses.txt",
|
||||||
"lint": "eslint src/**/*.ts __tests__/**/*.ts",
|
"lint": "yarn run prettier && yarn run eslint",
|
||||||
"format": "eslint --fix src/**/*.ts __tests__/**/*.ts",
|
"format": "yarn run prettier:fix && yarn run eslint:fix",
|
||||||
"test": "jest --coverage",
|
"eslint": "eslint --max-warnings=0 .",
|
||||||
|
"eslint:fix": "eslint --fix .",
|
||||||
|
"prettier": "prettier --check \"./**/*.ts\"",
|
||||||
|
"prettier:fix": "prettier --write \"./**/*.ts\"",
|
||||||
|
"test": "jest",
|
||||||
"all": "yarn run build && yarn run format && yarn test"
|
"all": "yarn run build && yarn run format && yarn test"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -20,39 +24,35 @@
|
|||||||
"tag",
|
"tag",
|
||||||
"label"
|
"label"
|
||||||
],
|
],
|
||||||
"author": "Docker",
|
"author": "Docker Inc.",
|
||||||
"contributors": [
|
|
||||||
{
|
|
||||||
"name": "CrazyMax",
|
|
||||||
"url": "https://crazymax.dev"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.6.0",
|
"@actions/core": "^1.10.1",
|
||||||
"@actions/github": "^5.0.1",
|
"@actions/github": "^5.1.1",
|
||||||
|
"@docker/actions-toolkit": "^0.12.0",
|
||||||
"@renovate/pep440": "^1.0.0",
|
"@renovate/pep440": "^1.0.0",
|
||||||
"csv-parse": "^5.0.4",
|
"csv-parse": "^5.5.0",
|
||||||
"handlebars": "^4.7.7",
|
"handlebars": "^4.7.8",
|
||||||
"moment": "^2.29.3",
|
"moment": "^2.29.4",
|
||||||
"semver": "^7.3.7"
|
"moment-timezone": "^0.5.43",
|
||||||
|
"semver": "^7.5.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/csv-parse": "^1.2.2",
|
"@types/csv-parse": "^1.2.2",
|
||||||
"@types/node": "^16.11.26",
|
"@types/node": "^20.5.9",
|
||||||
"@types/semver": "^7.3.9",
|
"@types/semver": "^7.5.1",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.14.0",
|
"@typescript-eslint/eslint-plugin": "^6.6.0",
|
||||||
"@typescript-eslint/parser": "^5.14.0",
|
"@typescript-eslint/parser": "^6.6.0",
|
||||||
"@vercel/ncc": "^0.33.3",
|
"@vercel/ncc": "^0.38.0",
|
||||||
"dotenv": "^16.0.0",
|
"dotenv": "^16.3.1",
|
||||||
"eslint": "^8.11.0",
|
"eslint": "^8.48.0",
|
||||||
"eslint-config-prettier": "^8.5.0",
|
"eslint-config-prettier": "^9.0.0",
|
||||||
"eslint-plugin-jest": "^26.1.1",
|
"eslint-plugin-jest": "^27.2.3",
|
||||||
"eslint-plugin-prettier": "^4.0.0",
|
"eslint-plugin-prettier": "^5.0.0",
|
||||||
"jest": "^27.2.5",
|
"jest": "^29.6.4",
|
||||||
"prettier": "^2.3.1",
|
"prettier": "^3.0.3",
|
||||||
"ts-jest": "^27.1.2",
|
"ts-jest": "^29.1.1",
|
||||||
"ts-node": "^10.7.0",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^4.4.4"
|
"typescript": "^5.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
105
src/context.ts
105
src/context.ts
@@ -1,13 +1,11 @@
|
|||||||
import {parse} from 'csv-parse/sync';
|
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import {issueCommand} from '@actions/core/lib/command';
|
import {Context} from '@actions/github/lib/context';
|
||||||
import * as fs from 'fs';
|
import {Util} from '@docker/actions-toolkit/lib/util';
|
||||||
import * as os from 'os';
|
import {Git} from '@docker/actions-toolkit/lib/git';
|
||||||
import * as path from 'path';
|
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
||||||
|
|
||||||
let _tmpDir: string;
|
|
||||||
|
|
||||||
export interface Inputs {
|
export interface Inputs {
|
||||||
|
context: ContextSource;
|
||||||
images: string[];
|
images: string[];
|
||||||
tags: string[];
|
tags: string[];
|
||||||
flavor: string[];
|
flavor: string[];
|
||||||
@@ -18,63 +16,58 @@ export interface Inputs {
|
|||||||
githubToken: string;
|
githubToken: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tmpDir(): string {
|
|
||||||
if (!_tmpDir) {
|
|
||||||
_tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-metadata-action-')).split(path.sep).join(path.posix.sep);
|
|
||||||
}
|
|
||||||
return _tmpDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getInputs(): Inputs {
|
export function getInputs(): Inputs {
|
||||||
return {
|
return {
|
||||||
images: getInputList('images', true),
|
context: (core.getInput('context') || ContextSource.workflow) as ContextSource,
|
||||||
tags: getInputList('tags', true),
|
images: Util.getInputList('images', {ignoreComma: true, comment: '#'}),
|
||||||
flavor: getInputList('flavor', true),
|
tags: Util.getInputList('tags', {ignoreComma: true, comment: '#'}),
|
||||||
labels: getInputList('labels', true),
|
flavor: Util.getInputList('flavor', {ignoreComma: true, comment: '#'}),
|
||||||
sepTags: core.getInput('sep-tags') || `\n`,
|
labels: Util.getInputList('labels', {ignoreComma: true, comment: '#'}),
|
||||||
sepLabels: core.getInput('sep-labels') || `\n`,
|
sepTags: core.getInput('sep-tags', {trimWhitespace: false}) || `\n`,
|
||||||
|
sepLabels: core.getInput('sep-labels', {trimWhitespace: false}) || `\n`,
|
||||||
bakeTarget: core.getInput('bake-target') || `docker-metadata-action`,
|
bakeTarget: core.getInput('bake-target') || `docker-metadata-action`,
|
||||||
githubToken: core.getInput('github-token')
|
githubToken: core.getInput('github-token')
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getInputList(name: string, ignoreComma?: boolean): string[] {
|
export enum ContextSource {
|
||||||
const res: Array<string> = [];
|
workflow = 'workflow',
|
||||||
|
git = 'git'
|
||||||
const items = core.getInput(name);
|
|
||||||
if (items == '') {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
const records = parse(items, {
|
|
||||||
columns: false,
|
|
||||||
relaxQuotes: true,
|
|
||||||
comment: '#',
|
|
||||||
relaxColumnCount: true,
|
|
||||||
skipEmptyLines: true
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const record of records as Array<string[]>) {
|
|
||||||
if (record.length == 1) {
|
|
||||||
res.push(record[0]);
|
|
||||||
continue;
|
|
||||||
} else if (!ignoreComma) {
|
|
||||||
res.push(...record);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
res.push(record.join(','));
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.filter(item => item).map(pat => pat.trim());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const asyncForEach = async (array, callback) => {
|
export async function getContext(source: ContextSource): Promise<Context> {
|
||||||
for (let index = 0; index < array.length; index++) {
|
switch (source) {
|
||||||
await callback(array[index], index, array);
|
case ContextSource.workflow:
|
||||||
|
return getContextFromWorkflow();
|
||||||
|
case ContextSource.git:
|
||||||
|
return await getContextFromGit();
|
||||||
|
default:
|
||||||
|
throw new Error(`Invalid context source: ${source}`);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
|
function getContextFromWorkflow(): Context {
|
||||||
export function setOutput(name: string, value: unknown): void {
|
const context = GitHub.context;
|
||||||
issueCommand('set-output', {name}, value);
|
|
||||||
|
// Needs to override Git reference with pr ref instead of upstream branch ref
|
||||||
|
// for pull_request_target event
|
||||||
|
// https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
|
||||||
|
if (/pull_request_target/.test(context.eventName)) {
|
||||||
|
context.ref = `refs/pull/${context.payload.number}/merge`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// DOCKER_METADATA_PR_HEAD_SHA env var can be used to set associated head
|
||||||
|
// SHA instead of commit SHA that triggered the workflow on pull request
|
||||||
|
// event.
|
||||||
|
if (/true/i.test(process.env.DOCKER_METADATA_PR_HEAD_SHA || '')) {
|
||||||
|
if ((/pull_request/.test(context.eventName) || /pull_request_target/.test(context.eventName)) && context.payload?.pull_request?.head?.sha != undefined) {
|
||||||
|
context.sha = context.payload.pull_request.head.sha;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getContextFromGit(): Promise<Context> {
|
||||||
|
return await Git.context();
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +0,0 @@
|
|||||||
import * as github from '@actions/github';
|
|
||||||
import {Context} from '@actions/github/lib/context';
|
|
||||||
import {components as OctoOpenApiTypes} from '@octokit/openapi-types';
|
|
||||||
|
|
||||||
export type ReposGetResponseData = OctoOpenApiTypes['schemas']['repository'];
|
|
||||||
|
|
||||||
export function context(): Context {
|
|
||||||
return github.context;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function repo(token: string): Promise<ReposGetResponseData> {
|
|
||||||
return github
|
|
||||||
.getOctokit(token)
|
|
||||||
.rest.repos.get({...github.context.repo})
|
|
||||||
.then(response => response.data as ReposGetResponseData);
|
|
||||||
}
|
|
65
src/main.ts
65
src/main.ts
@@ -1,20 +1,29 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import {getInputs, Inputs, setOutput} from './context';
|
|
||||||
import * as github from './github';
|
|
||||||
import {Meta, Version} from './meta';
|
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import {Context} from '@actions/github/lib/context';
|
import * as actionsToolkit from '@docker/actions-toolkit';
|
||||||
|
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||||
|
|
||||||
async function run() {
|
import {getContext, getInputs, Inputs} from './context';
|
||||||
try {
|
import {Meta, Version} from './meta';
|
||||||
const inputs: Inputs = await getInputs();
|
|
||||||
|
function setOutput(name: string, value: string) {
|
||||||
|
core.setOutput(name, value);
|
||||||
|
core.exportVariable(`DOCKER_METADATA_OUTPUT_${name.replace(/\W/g, '_').toUpperCase()}`, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
actionsToolkit.run(
|
||||||
|
// main
|
||||||
|
async () => {
|
||||||
|
const inputs: Inputs = getInputs();
|
||||||
if (inputs.images.length == 0) {
|
if (inputs.images.length == 0) {
|
||||||
throw new Error(`images input required`);
|
throw new Error(`images input required`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const context: Context = github.context();
|
const toolkit = new Toolkit({githubToken: inputs.githubToken});
|
||||||
const repo: github.ReposGetResponseData = await github.repo(inputs.githubToken);
|
const context = await getContext(inputs.context);
|
||||||
core.startGroup(`Context info`);
|
const repo = await toolkit.github.repoData();
|
||||||
|
|
||||||
|
await core.group(`Context info`, async () => {
|
||||||
core.info(`eventName: ${context.eventName}`);
|
core.info(`eventName: ${context.eventName}`);
|
||||||
core.info(`sha: ${context.sha}`);
|
core.info(`sha: ${context.sha}`);
|
||||||
core.info(`ref: ${context.ref}`);
|
core.info(`ref: ${context.ref}`);
|
||||||
@@ -23,12 +32,12 @@ async function run() {
|
|||||||
core.info(`actor: ${context.actor}`);
|
core.info(`actor: ${context.actor}`);
|
||||||
core.info(`runNumber: ${context.runNumber}`);
|
core.info(`runNumber: ${context.runNumber}`);
|
||||||
core.info(`runId: ${context.runId}`);
|
core.info(`runId: ${context.runId}`);
|
||||||
core.endGroup();
|
});
|
||||||
|
|
||||||
if (core.isDebug()) {
|
if (core.isDebug()) {
|
||||||
core.startGroup(`Webhook payload`);
|
await core.group(`Webhook payload`, async () => {
|
||||||
core.info(JSON.stringify(context.payload, null, 2));
|
core.info(JSON.stringify(context.payload, null, 2));
|
||||||
core.endGroup();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const meta: Meta = new Meta(inputs, context, repo);
|
const meta: Meta = new Meta(inputs, context, repo);
|
||||||
@@ -37,9 +46,9 @@ async function run() {
|
|||||||
if (meta.version.main == undefined || meta.version.main.length == 0) {
|
if (meta.version.main == undefined || meta.version.main.length == 0) {
|
||||||
core.warning(`No Docker image version has been generated. Check tags input.`);
|
core.warning(`No Docker image version has been generated. Check tags input.`);
|
||||||
} else {
|
} else {
|
||||||
core.startGroup(`Docker image version`);
|
await core.group(`Docker image version`, async () => {
|
||||||
core.info(version.main || '');
|
core.info(version.main || '');
|
||||||
core.endGroup();
|
});
|
||||||
}
|
}
|
||||||
setOutput('version', version.main || '');
|
setOutput('version', version.main || '');
|
||||||
|
|
||||||
@@ -48,39 +57,35 @@ async function run() {
|
|||||||
if (tags.length == 0) {
|
if (tags.length == 0) {
|
||||||
core.warning('No Docker tag has been generated. Check tags input.');
|
core.warning('No Docker tag has been generated. Check tags input.');
|
||||||
} else {
|
} else {
|
||||||
core.startGroup(`Docker tags`);
|
await core.group(`Docker tags`, async () => {
|
||||||
for (const tag of tags) {
|
for (const tag of tags) {
|
||||||
core.info(tag);
|
core.info(tag);
|
||||||
}
|
}
|
||||||
core.endGroup();
|
});
|
||||||
}
|
}
|
||||||
setOutput('tags', tags.join(inputs.sepTags));
|
setOutput('tags', tags.join(inputs.sepTags));
|
||||||
|
|
||||||
// Docker labels
|
// Docker labels
|
||||||
const labels: Array<string> = meta.getLabels();
|
const labels: Array<string> = meta.getLabels();
|
||||||
core.startGroup(`Docker labels`);
|
await core.group(`Docker labels`, async () => {
|
||||||
for (const label of labels) {
|
for (const label of labels) {
|
||||||
core.info(label);
|
core.info(label);
|
||||||
}
|
}
|
||||||
core.endGroup();
|
|
||||||
setOutput('labels', labels.join(inputs.sepLabels));
|
setOutput('labels', labels.join(inputs.sepLabels));
|
||||||
|
});
|
||||||
|
|
||||||
// JSON
|
// JSON
|
||||||
const jsonOutput = meta.getJSON();
|
const jsonOutput = meta.getJSON();
|
||||||
core.startGroup(`JSON output`);
|
await core.group(`JSON output`, async () => {
|
||||||
core.info(JSON.stringify(jsonOutput, null, 2));
|
core.info(JSON.stringify(jsonOutput, null, 2));
|
||||||
core.endGroup();
|
setOutput('json', JSON.stringify(jsonOutput));
|
||||||
setOutput('json', jsonOutput);
|
});
|
||||||
|
|
||||||
// Bake definition file
|
// Bake file definition
|
||||||
const bakeFile: string = meta.getBakeFile();
|
const bakeFile: string = meta.getBakeFile();
|
||||||
core.startGroup(`Bake definition file`);
|
await core.group(`Bake file definition`, async () => {
|
||||||
core.info(fs.readFileSync(bakeFile, 'utf8'));
|
core.info(fs.readFileSync(bakeFile, 'utf8'));
|
||||||
core.endGroup();
|
|
||||||
setOutput('bake-file', bakeFile);
|
setOutput('bake-file', bakeFile);
|
||||||
} catch (error) {
|
});
|
||||||
core.setFailed(error.message);
|
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
|
|
||||||
run();
|
|
||||||
|
102
src/meta.ts
102
src/meta.ts
@@ -1,16 +1,18 @@
|
|||||||
import * as handlebars from 'handlebars';
|
import * as handlebars from 'handlebars';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import moment from 'moment';
|
import moment from 'moment-timezone';
|
||||||
import * as pep440 from '@renovate/pep440';
|
import * as pep440 from '@renovate/pep440';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import {Inputs, tmpDir} from './context';
|
import * as core from '@actions/core';
|
||||||
import {ReposGetResponseData} from './github';
|
import {Context} from '@actions/github/lib/context';
|
||||||
|
import {Context as ToolkitContext} from '@docker/actions-toolkit/lib/context';
|
||||||
|
import {GitHubRepo} from '@docker/actions-toolkit/lib/types/github';
|
||||||
|
|
||||||
|
import {Inputs} from './context';
|
||||||
import * as icl from './image';
|
import * as icl from './image';
|
||||||
import * as tcl from './tag';
|
import * as tcl from './tag';
|
||||||
import * as fcl from './flavor';
|
import * as fcl from './flavor';
|
||||||
import * as core from '@actions/core';
|
|
||||||
import {Context} from '@actions/github/lib/context';
|
|
||||||
|
|
||||||
export interface Version {
|
export interface Version {
|
||||||
main: string | undefined;
|
main: string | undefined;
|
||||||
@@ -23,20 +25,13 @@ export class Meta {
|
|||||||
|
|
||||||
private readonly inputs: Inputs;
|
private readonly inputs: Inputs;
|
||||||
private readonly context: Context;
|
private readonly context: Context;
|
||||||
private readonly repo: ReposGetResponseData;
|
private readonly repo: GitHubRepo;
|
||||||
private readonly images: icl.Image[];
|
private readonly images: icl.Image[];
|
||||||
private readonly tags: tcl.Tag[];
|
private readonly tags: tcl.Tag[];
|
||||||
private readonly flavor: fcl.Flavor;
|
private readonly flavor: fcl.Flavor;
|
||||||
private readonly date: Date;
|
private readonly date: Date;
|
||||||
|
|
||||||
constructor(inputs: Inputs, context: Context, repo: ReposGetResponseData) {
|
constructor(inputs: Inputs, context: Context, repo: GitHubRepo) {
|
||||||
// Needs to override Git reference with pr ref instead of upstream branch ref
|
|
||||||
// for pull_request_target event
|
|
||||||
// https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
|
|
||||||
if (/pull_request_target/.test(context.eventName)) {
|
|
||||||
context.ref = `refs/pull/${context.payload.number}/merge`;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.inputs = inputs;
|
this.inputs = inputs;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
@@ -120,8 +115,19 @@ export class Meta {
|
|||||||
const currentDate = this.date;
|
const currentDate = this.date;
|
||||||
const vraw = this.setValue(
|
const vraw = this.setValue(
|
||||||
handlebars.compile(tag.attrs['pattern'])({
|
handlebars.compile(tag.attrs['pattern'])({
|
||||||
date: function (format) {
|
date: function (format, options) {
|
||||||
return moment(currentDate).utc().format(format);
|
const m = moment(currentDate);
|
||||||
|
let tz = 'UTC';
|
||||||
|
Object.keys(options.hash).forEach(key => {
|
||||||
|
switch (key) {
|
||||||
|
case 'tz':
|
||||||
|
tz = options.hash[key];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error(`Unknown ${key} attribute`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return m.tz(tz).format(format);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
tag
|
tag
|
||||||
@@ -148,7 +154,7 @@ export class Meta {
|
|||||||
|
|
||||||
let latest = false;
|
let latest = false;
|
||||||
const sver = semver.parse(vraw, {
|
const sver = semver.parse(vraw, {
|
||||||
includePrerelease: true
|
loose: true
|
||||||
});
|
});
|
||||||
if (semver.prerelease(vraw)) {
|
if (semver.prerelease(vraw)) {
|
||||||
if (Meta.isRawStatement(tag.attrs['pattern'])) {
|
if (Meta.isRawStatement(tag.attrs['pattern'])) {
|
||||||
@@ -301,7 +307,7 @@ export class Meta {
|
|||||||
|
|
||||||
let val = this.context.sha;
|
let val = this.context.sha;
|
||||||
if (tag.attrs['format'] === tcl.ShaFormat.Short) {
|
if (tag.attrs['format'] === tcl.ShaFormat.Short) {
|
||||||
val = this.context.sha.substr(0, 7);
|
val = this.context.sha.substring(0, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
const vraw = this.setValue(val, tag);
|
const vraw = this.setValue(val, tag);
|
||||||
@@ -351,59 +357,70 @@ export class Meta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setGlobalExp(val): string {
|
private setGlobalExp(val): string {
|
||||||
const ctx = this.context;
|
const context = this.context;
|
||||||
const currentDate = this.date;
|
const currentDate = this.date;
|
||||||
return handlebars.compile(val)({
|
return handlebars.compile(val)({
|
||||||
branch: function () {
|
branch: function () {
|
||||||
if (!/^refs\/heads\//.test(ctx.ref)) {
|
if (!/^refs\/heads\//.test(context.ref)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return ctx.ref.replace(/^refs\/heads\//g, '');
|
return context.ref.replace(/^refs\/heads\//g, '');
|
||||||
},
|
},
|
||||||
tag: function () {
|
tag: function () {
|
||||||
if (!/^refs\/tags\//.test(ctx.ref)) {
|
if (!/^refs\/tags\//.test(context.ref)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return ctx.ref.replace(/^refs\/tags\//g, '');
|
return context.ref.replace(/^refs\/tags\//g, '');
|
||||||
},
|
},
|
||||||
sha: function () {
|
sha: function () {
|
||||||
return ctx.sha.substr(0, 7);
|
return context.sha.substring(0, 7);
|
||||||
},
|
},
|
||||||
base_ref: function () {
|
base_ref: function () {
|
||||||
if (/^refs\/tags\//.test(ctx.ref) && ctx.payload?.base_ref != undefined) {
|
if (/^refs\/tags\//.test(context.ref) && context.payload?.base_ref != undefined) {
|
||||||
return ctx.payload.base_ref.replace(/^refs\/heads\//g, '');
|
return context.payload.base_ref.replace(/^refs\/heads\//g, '');
|
||||||
}
|
}
|
||||||
// FIXME: keep this for backward compatibility even if doesn't always seem
|
// FIXME: keep this for backward compatibility even if doesn't always seem
|
||||||
// to return the expected branch. See the comment below.
|
// to return the expected branch. See the comment below.
|
||||||
if (/^refs\/pull\//.test(ctx.ref) && ctx.payload?.pull_request?.base?.ref != undefined) {
|
if (/^refs\/pull\//.test(context.ref) && context.payload?.pull_request?.base?.ref != undefined) {
|
||||||
return ctx.payload.pull_request.base.ref;
|
return context.payload.pull_request.base.ref;
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
is_default_branch: function () {
|
is_default_branch: function () {
|
||||||
const branch = ctx.ref.replace(/^refs\/heads\//g, '');
|
const branch = context.ref.replace(/^refs\/heads\//g, '');
|
||||||
// TODO: "base_ref" is available in the push payload but doesn't always seem to
|
// TODO: "base_ref" is available in the push payload but doesn't always seem to
|
||||||
// return the expected branch when the push tag event occurs. It's also not
|
// return the expected branch when the push tag event occurs. It's also not
|
||||||
// documented in GitHub docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push
|
// documented in GitHub docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push
|
||||||
// more context: https://github.com/docker/metadata-action/pull/192#discussion_r854673012
|
// more context: https://github.com/docker/metadata-action/pull/192#discussion_r854673012
|
||||||
// if (/^refs\/tags\//.test(ctx.ref) && ctx.payload?.base_ref != undefined) {
|
// if (/^refs\/tags\//.test(context.ref) && context.payload?.base_ref != undefined) {
|
||||||
// branch = ctx.payload.base_ref.replace(/^refs\/heads\//g, '');
|
// branch = context.payload.base_ref.replace(/^refs\/heads\//g, '');
|
||||||
// }
|
// }
|
||||||
if (branch == undefined || branch.length == 0) {
|
if (branch == undefined || branch.length == 0) {
|
||||||
return 'false';
|
return 'false';
|
||||||
}
|
}
|
||||||
if (ctx.payload?.repository?.default_branch == branch) {
|
if (context.payload?.repository?.default_branch == branch) {
|
||||||
return 'true';
|
return 'true';
|
||||||
}
|
}
|
||||||
// following events always trigger for last commit on default branch
|
// following events always trigger for last commit on default branch
|
||||||
// https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
|
// https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
|
||||||
if (/create/.test(ctx.eventName) || /discussion/.test(ctx.eventName) || /issues/.test(ctx.eventName) || /schedule/.test(ctx.eventName)) {
|
if (/create/.test(context.eventName) || /discussion/.test(context.eventName) || /issues/.test(context.eventName) || /schedule/.test(context.eventName)) {
|
||||||
return 'true';
|
return 'true';
|
||||||
}
|
}
|
||||||
return 'false';
|
return 'false';
|
||||||
},
|
},
|
||||||
date: function (format) {
|
date: function (format, options) {
|
||||||
return moment(currentDate).utc().format(format);
|
const m = moment(currentDate);
|
||||||
|
let tz = 'UTC';
|
||||||
|
Object.keys(options.hash).forEach(key => {
|
||||||
|
switch (key) {
|
||||||
|
case 'tz':
|
||||||
|
tz = options.hash[key];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error(`Unknown ${key} attribute`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return m.tz(tz).format(format);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -449,7 +466,18 @@ export class Meta {
|
|||||||
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
|
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
|
||||||
];
|
];
|
||||||
labels.push(...this.inputs.labels);
|
labels.push(...this.inputs.labels);
|
||||||
return labels;
|
|
||||||
|
return Array.from(
|
||||||
|
new Map<string, string>(
|
||||||
|
labels
|
||||||
|
.map(label => label.split('='))
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
.filter(([_key, ...values]) => values.length > 0)
|
||||||
|
.map(([key, ...values]) => [key, values.join('=')] as [string, string])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.sort((a, b) => a[0].localeCompare(b[0]))
|
||||||
|
.map(([key, value]) => `${key}=${value}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getJSON(): unknown {
|
public getJSON(): unknown {
|
||||||
@@ -467,7 +495,7 @@ export class Meta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getBakeFile(): string {
|
public getBakeFile(): string {
|
||||||
const bakeFile = path.join(tmpDir(), 'docker-metadata-action-bake.json').split(path.sep).join(path.posix.sep);
|
const bakeFile = path.join(ToolkitContext.tmpDir(), 'docker-metadata-action-bake.json');
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
bakeFile,
|
bakeFile,
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
|
@@ -95,7 +95,7 @@ export function Parse(s: string): Tag {
|
|||||||
for (const field of fields) {
|
for (const field of fields) {
|
||||||
const parts = field
|
const parts = field
|
||||||
.toString()
|
.toString()
|
||||||
.split('=')
|
.split(/(?<=^[^=]+?)=/)
|
||||||
.map(item => item.trim());
|
.map(item => item.trim());
|
||||||
if (parts.length == 1) {
|
if (parts.length == 1) {
|
||||||
tag.attrs['value'] = parts[0];
|
tag.attrs['value'] = parts[0];
|
||||||
|
@@ -1,3 +1,3 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
FROM alpine
|
FROM alpine
|
||||||
|
|
||||||
RUN echo "Hello world!"
|
RUN echo "Hello world!"
|
||||||
|
12
test/output.Dockerfile
Normal file
12
test/output.Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
FROM alpine
|
||||||
|
RUN apk add --no-cache coreutils jq
|
||||||
|
ARG DOCKER_METADATA_OUTPUT_VERSION
|
||||||
|
ARG DOCKER_METADATA_OUTPUT_TAGS
|
||||||
|
ARG DOCKER_METADATA_OUTPUT_LABELS
|
||||||
|
ARG DOCKER_METADATA_OUTPUT_JSON
|
||||||
|
RUN printenv DOCKER_METADATA_OUTPUT_VERSION
|
||||||
|
RUN printenv DOCKER_METADATA_OUTPUT_TAGS
|
||||||
|
RUN printenv DOCKER_METADATA_OUTPUT_LABELS
|
||||||
|
RUN printenv DOCKER_METADATA_OUTPUT_JSON
|
||||||
|
RUN echo $DOCKER_METADATA_OUTPUT_JSON | jq
|
@@ -1,20 +1,22 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"esModuleInterop": true,
|
||||||
"target": "es6",
|
"target": "es6",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
|
"strict": true,
|
||||||
"newLine": "lf",
|
"newLine": "lf",
|
||||||
"outDir": "./lib",
|
"outDir": "./lib",
|
||||||
"rootDir": "./src",
|
"rootDir": "./src",
|
||||||
"esModuleInterop": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"strict": true,
|
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"useUnknownInCatchVariables": false,
|
"useUnknownInCatchVariables": false,
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
|
"./__mocks__/**/*",
|
||||||
|
"./__tests__/**/*",
|
||||||
|
"./lib/**/*",
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"**/*.test.ts",
|
|
||||||
"jest.config.ts"
|
"jest.config.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user