Compare commits
143 Commits
Author | SHA1 | Date |
---|---|---|
|
902fa8ec7d | |
|
c30b9c27e6 | |
|
0698804aab | |
|
bb3eecaaf8 | |
|
94a839cf6a | |
|
ecd51a0f6a | |
|
a85b1dbfe6 | |
|
5a76a0efcf | |
|
1cc4a9856a | |
|
d84de1e022 | |
|
092f0474e9 | |
|
8b68062745 | |
|
0eaca2ee4e | |
|
db44dfae7a | |
|
2bd8a81e96 | |
|
10ff2155d8 | |
|
a1a78f1e24 | |
|
95438bc6e5 | |
|
0e4a06e6a2 | |
|
a550435c60 | |
|
b539e14bf6 | |
|
d931b83008 | |
|
8e1d5461f0 | |
|
2af3007824 | |
|
0d820067b8 | |
|
906ecf0fc0 | |
|
f78c299c14 | |
|
87ff116aea | |
|
b53be03109 | |
|
3da9c47fb9 | |
|
f5d655ce8b | |
|
369eb591f4 | |
|
7d870ce854 | |
|
e44a9cd788 | |
|
8cb0002d6a | |
|
e01ddd3e3c | |
|
861d98a3bd | |
|
359e915ab3 | |
|
0c395ebe62 | |
|
115662203e | |
|
95ea8d0c40 | |
|
a4c10ad2ed | |
|
c85c22ab59 | |
|
526d40319b | |
|
86622a92ee | |
|
44d81d6d2a | |
|
9aaeb628e0 | |
|
32323e53fe | |
|
3d8d1d9406 | |
|
1b250aecdc | |
|
bd26c982ee | |
|
f574002aaf | |
|
30c2f0a1f0 | |
|
0de3687b53 | |
|
3229e62531 | |
|
f829da7245 | |
|
9b90a2e882 | |
|
aa662cf9eb | |
|
c6cb763bee | |
|
bb9c6dd583 | |
|
d31acd5065 | |
|
6df88e4e75 | |
|
70b2cdc648 | |
|
1a52488bd8 | |
|
60a0d343a0 | |
|
b3bc5a6d84 | |
|
e6e95c28a4 | |
|
9ec63a7555 | |
|
6970301b80 | |
|
d155f767a3 | |
|
b5b2c1dec6 | |
|
a64d0487d7 | |
|
68e4cac93d | |
|
7ba3606742 | |
|
2331fdf258 | |
|
24ce540669 | |
|
d729db4f91 | |
|
f7b4ed1238 | |
|
33c4e25305 | |
|
b83177b368 | |
|
839b70f9d5 | |
|
dbacb9a831 | |
|
247cc9691a | |
|
4c92c35ca9 | |
|
9ca1efb941 | |
|
0170173c39 | |
|
dab39f1537 | |
|
f402fd6ae4 | |
|
b0bbce7f66 | |
|
2ee3d3070b | |
|
6e3a986a06 | |
|
4fde7ad49c | |
|
24b670ad98 | |
|
1294d94f8e | |
|
4ab8e580e1 | |
|
3617daf484 | |
|
b5cd5676d4 | |
|
204ddf0626 | |
|
588ab464f7 | |
|
6ed49e6282 | |
|
499da83ec1 | |
|
1bc39885c1 | |
|
c314eea2b2 | |
|
22d80c023d | |
|
38b3677383 | |
|
3c91de3093 | |
|
75359341f6 | |
|
2432cf717c | |
|
c77859c8ba | |
|
60ab7b421c | |
|
7ce1a14667 | |
|
d06e52bc52 | |
|
66f0185bb8 | |
|
232fc64e3a | |
|
1b08479748 | |
|
3a28db68be | |
|
6bb43c8680 | |
|
41050ffe08 | |
|
8e5442c4ef | |
|
eda41b71bf | |
|
388c08f740 | |
|
dbef88086f | |
|
b73e7a71ac | |
|
b9fba690eb | |
|
ac82374ba6 | |
|
c92519a44e | |
|
3b4179d34d | |
|
0784993ef8 | |
|
52c3e9e410 | |
|
82a5e6726c | |
|
41e1fe3437 | |
|
48cce1cba0 | |
|
61879b94bc | |
|
36ea4ee555 | |
|
74fa878183 | |
|
9dc751fe24 | |
|
c94c54c4e6 | |
|
187f09259d | |
|
6d6eaf3451 | |
|
1484a7ec95 | |
|
31cebacef4 | |
|
394bbab10c | |
|
ee4c9054ec |
|
@ -1,2 +1,12 @@
|
|||
/coverage
|
||||
/node_modules
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "latest",
|
||||
"ecmaVersion": 2023,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/.yarn/releases/** binary
|
||||
/.yarn/plugins/** binary
|
||||
/__tests__/fixtures/** -linguist-detectable
|
||||
/dist/** linguist-generated=true
|
||||
/lib/** linguist-generated=true
|
||||
|
|
|
@ -17,14 +17,39 @@ on:
|
|||
|
||||
env:
|
||||
DOCKER_IMAGE: localhost:5000/name/app
|
||||
BUILDX_VERSION: latest
|
||||
|
||||
jobs:
|
||||
context:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
context:
|
||||
- workflow
|
||||
- git
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Docker meta
|
||||
uses: ./
|
||||
with:
|
||||
context: ${{ matrix.context }}
|
||||
|
||||
multi-images:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver: docker
|
||||
-
|
||||
name: Docker meta
|
||||
uses: ./
|
||||
|
@ -56,6 +81,12 @@ jobs:
|
|||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver: docker
|
||||
-
|
||||
name: Docker meta
|
||||
uses: ./
|
||||
|
@ -86,6 +117,12 @@ jobs:
|
|||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver: docker
|
||||
-
|
||||
name: Docker meta
|
||||
uses: ./
|
||||
|
@ -114,6 +151,12 @@ jobs:
|
|||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver: docker
|
||||
-
|
||||
name: Docker meta
|
||||
uses: ./
|
||||
|
@ -139,6 +182,12 @@ jobs:
|
|||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver: docker
|
||||
-
|
||||
name: Docker meta
|
||||
uses: ./
|
||||
|
@ -156,6 +205,12 @@ jobs:
|
|||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver: docker
|
||||
-
|
||||
name: Docker meta
|
||||
uses: ./
|
||||
|
@ -171,6 +226,12 @@ jobs:
|
|||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver: docker
|
||||
-
|
||||
name: Docker meta
|
||||
uses: ./
|
||||
|
@ -195,6 +256,12 @@ jobs:
|
|||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver: docker
|
||||
-
|
||||
name: Docker meta
|
||||
uses: ./
|
||||
|
@ -202,6 +269,8 @@ jobs:
|
|||
images: |
|
||||
${{ env.DOCKER_IMAGE }}
|
||||
ghcr.io/name/app
|
||||
labels: |
|
||||
org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}
|
||||
tags: |
|
||||
type=sha
|
||||
type=raw,value=gexp-branch-{{branch}}
|
||||
|
@ -216,6 +285,12 @@ jobs:
|
|||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver: docker
|
||||
-
|
||||
name: Docker meta
|
||||
id: meta
|
||||
|
@ -245,6 +320,12 @@ jobs:
|
|||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver-opts: network=host
|
||||
-
|
||||
name: Docker meta
|
||||
id: docker_meta
|
||||
|
@ -261,17 +342,9 @@ jobs:
|
|||
type=semver,pattern=v{{major}}.{{minor}}
|
||||
type=semver,pattern=v{{major}}
|
||||
type=sha
|
||||
-
|
||||
name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
driver-opts: network=host
|
||||
-
|
||||
name: Build and push to local registry
|
||||
uses: docker/build-push-action@v5
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ./test
|
||||
file: ./test/Dockerfile
|
||||
|
@ -288,10 +361,6 @@ jobs:
|
|||
name: Check manifest
|
||||
run: |
|
||||
docker buildx imagetools inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }}
|
||||
-
|
||||
name: Dump context
|
||||
if: always()
|
||||
uses: crazy-max/ghaction-dump-context@v2
|
||||
|
||||
bake:
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -299,6 +368,11 @@ jobs:
|
|||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
-
|
||||
name: Docker meta
|
||||
id: docker_meta
|
||||
|
@ -316,20 +390,14 @@ jobs:
|
|||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
type=sha
|
||||
-
|
||||
name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
-
|
||||
name: Build
|
||||
uses: docker/bake-action@v4
|
||||
uses: docker/bake-action@v6
|
||||
with:
|
||||
files: |
|
||||
./test/docker-bake.hcl
|
||||
${{ steps.docker_meta.outputs.bake-file-tags }}
|
||||
${{ steps.docker_meta.outputs.bake-file-labels }}
|
||||
cwd://${{ steps.docker_meta.outputs.bake-file-tags }}
|
||||
cwd://${{ steps.docker_meta.outputs.bake-file-labels }}
|
||||
targets: |
|
||||
release
|
||||
|
||||
|
@ -345,6 +413,12 @@ jobs:
|
|||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver: docker
|
||||
-
|
||||
name: Docker meta
|
||||
id: meta
|
||||
|
@ -367,6 +441,12 @@ jobs:
|
|||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver: docker
|
||||
-
|
||||
name: Docker meta
|
||||
id: meta
|
||||
|
@ -381,7 +461,7 @@ jobs:
|
|||
maintainer=Foo
|
||||
-
|
||||
name: Build
|
||||
uses: docker/build-push-action@v5
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ./test
|
||||
file: ./test/output.Dockerfile
|
||||
|
@ -392,12 +472,43 @@ jobs:
|
|||
DOCKER_METADATA_OUTPUT_ANNOTATIONS
|
||||
DOCKER_METADATA_OUTPUT_JSON
|
||||
|
||||
no-output-env:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DOCKER_METADATA_SET_OUTPUT_ENV: false
|
||||
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
|
||||
annotations: |
|
||||
maintainer=Foo
|
||||
-
|
||||
name: No output environment variables set
|
||||
shell: bash
|
||||
run: |
|
||||
[[ "$(printenv | grep "^DOCKER_METADATA_OUTPUT_" | wc -l)" -eq 0 ]] || exit 1
|
||||
|
||||
bake-annotations:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
-
|
||||
name: Docker meta
|
||||
id: docker_meta
|
||||
|
@ -417,22 +528,14 @@ jobs:
|
|||
type=sha
|
||||
env:
|
||||
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
|
||||
-
|
||||
name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: v0.12.0-rc1
|
||||
-
|
||||
name: Build
|
||||
uses: docker/bake-action@v4
|
||||
uses: docker/bake-action@v6
|
||||
with:
|
||||
files: |
|
||||
./test/docker-bake.hcl
|
||||
${{ steps.docker_meta.outputs.bake-file-tags }}
|
||||
${{ steps.docker_meta.outputs.bake-file-annotations }}
|
||||
cwd://${{ steps.docker_meta.outputs.bake-file-tags }}
|
||||
cwd://${{ steps.docker_meta.outputs.bake-file-annotations }}
|
||||
targets: |
|
||||
release
|
||||
|
||||
|
@ -442,6 +545,12 @@ jobs:
|
|||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver: docker
|
||||
-
|
||||
name: Docker meta
|
||||
uses: ./
|
||||
|
@ -455,3 +564,70 @@ jobs:
|
|||
-
|
||||
name: Print envs
|
||||
run: env|sort
|
||||
|
||||
bake-path-context:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: latest
|
||||
-
|
||||
name: Docker meta
|
||||
id: docker_meta
|
||||
uses: ./
|
||||
-
|
||||
name: Build
|
||||
uses: docker/bake-action@v6
|
||||
with:
|
||||
source: .
|
||||
files: |
|
||||
./test/docker-bake.hcl
|
||||
${{ steps.docker_meta.outputs.bake-file-tags }}
|
||||
${{ steps.docker_meta.outputs.bake-file-labels }}
|
||||
targets: |
|
||||
release
|
||||
|
||||
sha-short:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
short-length:
|
||||
- ''
|
||||
- 16
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ env.BUILDX_VERSION }}
|
||||
driver: docker
|
||||
-
|
||||
name: Docker meta
|
||||
uses: ./
|
||||
with:
|
||||
images: |
|
||||
${{ env.DOCKER_IMAGE }}
|
||||
ghcr.io/name/app
|
||||
tags: |
|
||||
type=sha
|
||||
env:
|
||||
DOCKER_METADATA_SHORT_SHA_LENGTH: ${{ matrix.short-length }}
|
||||
|
||||
dump:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Dump context
|
||||
uses: crazy-max/ghaction-dump-context@v2
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
name: publish
|
||||
|
||||
on:
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
packages: write
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Publish
|
||||
uses: actions/publish-immutable-action@v0.0.4
|
|
@ -15,16 +15,14 @@ jobs:
|
|||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Test
|
||||
uses: docker/bake-action@v4
|
||||
uses: docker/bake-action@v6
|
||||
with:
|
||||
targets: test
|
||||
-
|
||||
name: Upload coverage
|
||||
uses: codecov/codecov-action@v3
|
||||
uses: codecov/codecov-action@v5
|
||||
with:
|
||||
file: ./coverage/clover.xml
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
|
|
|
@ -15,16 +15,17 @@ jobs:
|
|||
prepare:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
targets: ${{ steps.targets.outputs.matrix }}
|
||||
targets: ${{ steps.generate.outputs.targets }}
|
||||
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
|
||||
name: List targets
|
||||
id: generate
|
||||
uses: docker/bake-action/subaction/list-targets@v6
|
||||
with:
|
||||
target: validate
|
||||
|
||||
validate:
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -35,11 +36,8 @@ jobs:
|
|||
matrix:
|
||||
target: ${{ fromJson(needs.prepare.outputs.targets) }}
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Validate
|
||||
uses: docker/bake-action@v4
|
||||
uses: docker/bake-action@v6
|
||||
with:
|
||||
targets: ${{ matrix.target }}
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
/.dev
|
||||
node_modules/
|
||||
lib
|
||||
# https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||
|
||||
# Jetbrains
|
||||
/.idea
|
||||
/*.iml
|
||||
|
||||
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
@ -14,6 +7,7 @@ npm-debug.log*
|
|||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
@ -24,34 +18,14 @@ pids
|
|||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
|
@ -61,36 +35,19 @@ typings/
|
|||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.test
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# yarn v2
|
||||
.yarn/
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,13 @@
|
|||
logFilters:
|
||||
- code: YN0013
|
||||
level: discard
|
||||
- code: YN0019
|
||||
level: discard
|
||||
- code: YN0076
|
||||
level: discard
|
||||
|
||||
nodeLinker: node-modules
|
||||
|
||||
plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
||||
spec: "@yarnpkg/plugin-interactive-tools"
|
92
README.md
92
README.md
|
@ -45,6 +45,7 @@ ___
|
|||
* [`{{base_ref}}`](#base_ref)
|
||||
* [`{{is_default_branch}}`](#is_default_branch)
|
||||
* [`{{date '<format>' tz='<timezone>'}}`](#date-format-tztimezone)
|
||||
* [`{{commit_date '<format>' tz='<timezone>'}}`](#commit_date-format-tztimezone)
|
||||
* [Major version zero](#major-version-zero)
|
||||
* [JSON output object](#json-output-object)
|
||||
* [Overwrite labels and annotations](#overwrite-labels-and-annotations)
|
||||
|
@ -91,7 +92,7 @@ jobs:
|
|||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
-
|
||||
name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
|
@ -151,7 +152,7 @@ jobs:
|
|||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
-
|
||||
name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
|
@ -205,9 +206,6 @@ jobs:
|
|||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Docker meta
|
||||
id: meta
|
||||
|
@ -223,11 +221,11 @@ jobs:
|
|||
type=sha
|
||||
-
|
||||
name: Build
|
||||
uses: docker/bake-action@v3
|
||||
uses: docker/bake-action@v6
|
||||
with:
|
||||
files: |
|
||||
./docker-bake.hcl
|
||||
${{ steps.meta.outputs.bake-file }}
|
||||
cwd://${{ steps.meta.outputs.bake-file }}
|
||||
targets: build
|
||||
```
|
||||
|
||||
|
@ -270,12 +268,12 @@ similar to the previous one:
|
|||
```yaml
|
||||
-
|
||||
name: Build
|
||||
uses: docker/bake-action@v3
|
||||
uses: docker/bake-action@v6
|
||||
with:
|
||||
files: |
|
||||
./docker-bake.hcl
|
||||
${{ steps.meta.outputs.bake-file-tags }}
|
||||
${{ steps.meta.outputs.bake-file-labels }}
|
||||
cwd://${{ steps.meta.outputs.bake-file-tags }}
|
||||
cwd://${{ steps.meta.outputs.bake-file-labels }}
|
||||
targets: build
|
||||
```
|
||||
|
||||
|
@ -300,7 +298,7 @@ The following inputs can be used as `step.with` keys:
|
|||
| `tags` | List | List of [tags](#tags-input) as key-value pair attributes |
|
||||
| `flavor` | List | [Flavor](#flavor-input) to apply |
|
||||
| `labels` | List | List of custom labels |
|
||||
| `annotations` | List | List of custom anntoations |
|
||||
| `annotations` | List | List of custom annotations |
|
||||
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
|
||||
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
|
||||
| `sep-annotations` | String | Separator to use for annotations output (default `\n`) |
|
||||
|
@ -321,7 +319,7 @@ The following outputs are available:
|
|||
| `bake-file-labels` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with labels |
|
||||
| `bake-file-annotations` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
|
||||
|
||||
Alternatively, each output is also exported as an environment variable:
|
||||
Alternatively, each output is also exported as an environment variable when `DOCKER_METADATA_SET_OUTPUT_ENV` is `true`:
|
||||
|
||||
* `DOCKER_METADATA_OUTPUT_VERSION`
|
||||
* `DOCKER_METADATA_OUTPUT_TAGS`
|
||||
|
@ -335,7 +333,7 @@ Alternatively, each output is also exported as an environment variable:
|
|||
So it can be used with our [Docker Build Push action](https://github.com/docker/build-push-action/):
|
||||
|
||||
```yaml
|
||||
- uses: docker/build-push-action@v5
|
||||
- uses: docker/build-push-action@v6
|
||||
with:
|
||||
build-args: |
|
||||
DOCKER_METADATA_OUTPUT_JSON
|
||||
|
@ -343,10 +341,12 @@ So it can be used with our [Docker Build Push action](https://github.com/docker/
|
|||
|
||||
### 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 |
|
||||
| `DOCKER_METADATA_ANNOTATIONS_LEVELS` | String | Comma separated list of annotations levels to set for annotations output separated (default `manifest`) |
|
||||
| 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 |
|
||||
| `DOCKER_METADATA_SHORT_SHA_LENGTH` | Number | Specifies the length of the [short commit SHA](#typesha) to ensure uniqueness. Default is `7`, but can be increased for larger repositories. |
|
||||
| `DOCKER_METADATA_ANNOTATIONS_LEVELS` | String | Comma separated list of annotations levels to set for annotations output separated (default `manifest`) |
|
||||
| `DOCKER_METADATA_SET_OUTPUT_ENV` | Bool | If `true`, sets each output as an environment variable (default `true`) |
|
||||
|
||||
## `context` input
|
||||
|
||||
|
@ -705,7 +705,26 @@ tags: |
|
|||
type=sha,format=long
|
||||
```
|
||||
|
||||
Output Git short commit (or long if specified) as Docker tag like `sha-ad132f5`.
|
||||
Output Git short commit (or long if specified) as Docker tag like
|
||||
`sha-860c190`.
|
||||
|
||||
By default, the length of the short commit SHA is `7` characters. You can
|
||||
increase this length for larger repositories by setting the
|
||||
[`DOCKER_METADATA_SHORT_SHA_LENGTH` environment variable](#environment-variables):
|
||||
|
||||
```yaml
|
||||
-
|
||||
name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
name/app
|
||||
tags: |
|
||||
type=sha
|
||||
env:
|
||||
DOCKER_METADATA_SHORT_SHA_LENGTH: 12
|
||||
```
|
||||
|
||||
Extended attributes and default values:
|
||||
|
||||
|
@ -739,6 +758,7 @@ generated by default (`auto` mode) for:
|
|||
|
||||
* [`type=ref,event=tag`](#typeref)
|
||||
* [`type=semver,pattern=...`](#typesemver)
|
||||
* [`type=pep440,pattern=...`](#typepep440)
|
||||
* [`type=match,pattern=...`](#typematch)
|
||||
|
||||
For conditionally tagging with latest for a specific branch name, e.g. if your
|
||||
|
@ -780,7 +800,8 @@ Each tags `type` attribute has a default priority:
|
|||
### Global expressions
|
||||
|
||||
The following [Handlebars' template](https://handlebarsjs.com/guide/) expressions
|
||||
for `prefix`, `suffix`, `value` and `enable` attributes are available:
|
||||
for `prefix`, `suffix`, `value` and `enable` attributes of `tags` input are
|
||||
available:
|
||||
|
||||
```yaml
|
||||
tags: |
|
||||
|
@ -790,6 +811,13 @@ tags: |
|
|||
type=raw,value=mytag-{{branch}}-{{sha}}
|
||||
```
|
||||
|
||||
They can also be applied to `labels` and `annotations` inputs:
|
||||
|
||||
```yaml
|
||||
labels: |
|
||||
org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}
|
||||
```
|
||||
|
||||
#### `{{branch}}`
|
||||
|
||||
Returns the branch name that triggered the workflow run. Will be empty if not
|
||||
|
@ -852,6 +880,20 @@ Default `tz` is UTC.
|
|||
| `{{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` |
|
||||
|
||||
#### `{{commit_date '<format>' tz='<timezone>'}}`
|
||||
|
||||
Returns the date when the current git commit is committed, rendered by its
|
||||
[moment format](https://momentjs.com/docs/#/displaying/format/). It falls back
|
||||
to the current date if the commit date is not available.
|
||||
|
||||
Default `tz` is UTC.
|
||||
|
||||
| Expression | Output example |
|
||||
|-----------------------------------------------------|-----------------------------------------|
|
||||
| `{{commit_date 'YYYYMMDD'}}` | `20200110` |
|
||||
| `{{commit_date 'dddd, MMMM Do YYYY, h:mm:ss a'}}` | `Friday, January 10th 2020, 3:25:50 pm` |
|
||||
| `{{commit_date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}}` | `20200110-093000` |
|
||||
|
||||
### Major version zero
|
||||
|
||||
Major version zero (`0.y.z`) is for initial development and **may** change at
|
||||
|
@ -885,7 +927,7 @@ that you can reuse them further in your workflow using the [`fromJSON` function]
|
|||
images: name/app
|
||||
-
|
||||
name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
@ -932,7 +974,7 @@ of the `metadata-action`:
|
|||
images: name/app
|
||||
-
|
||||
name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
annotations: ${{ steps.meta.outputs.annotations }}
|
||||
|
@ -948,12 +990,12 @@ The same can be done with the [`bake-action`](https://github.com/docker/bake-act
|
|||
images: name/app
|
||||
-
|
||||
name: Build
|
||||
uses: docker/bake-action@v3
|
||||
uses: docker/bake-action@v6
|
||||
with:
|
||||
files: |
|
||||
./docker-bake.hcl
|
||||
${{ steps.meta.outputs.bake-file-tags }}
|
||||
${{ steps.meta.outputs.bake-file-annotations }}
|
||||
cwd://${{ steps.meta.outputs.bake-file-tags }}
|
||||
cwd://${{ steps.meta.outputs.bake-file-annotations }}
|
||||
targets: build
|
||||
```
|
||||
|
||||
|
@ -979,7 +1021,7 @@ Please consult the documentation of your registry.
|
|||
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
|
||||
-
|
||||
name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
annotations: ${{ steps.meta.outputs.annotations }}
|
||||
|
|
300
UPGRADE.md
300
UPGRADE.md
|
@ -1,300 +0,0 @@
|
|||
# Upgrade notes
|
||||
|
||||
## v2 to v3
|
||||
|
||||
* Repository has been moved to docker org. Replace `crazy-max/ghaction-docker-meta@v2`
|
||||
with `docker/metadata-action@v5`
|
||||
* The default bake target has been changed: `ghaction-docker-meta` > `docker-metadata-action`
|
||||
|
||||
## v1 to v2
|
||||
|
||||
* [inputs](#inputs)
|
||||
* [`tag-sha`](#tag-sha)
|
||||
* [`tag-edge` / `tag-edge-branch`](#tag-edge--tag-edge-branch)
|
||||
* [`tag-semver`](#tag-semver)
|
||||
* [`tag-match` / `tag-match-group`](#tag-match--tag-match-group)
|
||||
* [`tag-latest`](#tag-latest)
|
||||
* [`tag-schedule`](#tag-schedule)
|
||||
* [`tag-custom` / `tag-custom-only`](#tag-custom--tag-custom-only)
|
||||
* [`label-custom`](#label-custom)
|
||||
* [Basic workflow](#basic-workflow)
|
||||
* [Semver workflow](#semver-workflow)
|
||||
|
||||
### inputs
|
||||
|
||||
| New | Unchanged | Removed |
|
||||
|------------|-----------------|--------------------|
|
||||
| `tags` | `images` | `tag-sha` |
|
||||
| `flavor` | `sep-tags` | `tag-edge` |
|
||||
| `labels` | `sep-labels` | `tag-edge-branch` |
|
||||
| | | `tag-semver` |
|
||||
| | | `tag-match` |
|
||||
| | | `tag-match-group` |
|
||||
| | | `tag-latest` |
|
||||
| | | `tag-schedule` |
|
||||
| | | `tag-custom` |
|
||||
| | | `tag-custom-only` |
|
||||
| | | `label-custom` |
|
||||
|
||||
#### `tag-sha`
|
||||
|
||||
```yaml
|
||||
tags: |
|
||||
type=sha
|
||||
```
|
||||
|
||||
#### `tag-edge` / `tag-edge-branch`
|
||||
|
||||
```yaml
|
||||
tags: |
|
||||
# default branch
|
||||
type=edge
|
||||
# specify branch
|
||||
type=edge,branch=main
|
||||
```
|
||||
|
||||
#### `tag-semver`
|
||||
|
||||
```yaml
|
||||
tags: |
|
||||
type=semver,pattern={{version}}
|
||||
```
|
||||
|
||||
#### `tag-match` / `tag-match-group`
|
||||
|
||||
```yaml
|
||||
tags: |
|
||||
type=match,pattern=v(.*),group=1
|
||||
```
|
||||
|
||||
#### `tag-latest`
|
||||
|
||||
`tag-latest` is now handled through the [`flavor` input](README.md#flavor-input):
|
||||
|
||||
```yaml
|
||||
flavor: |
|
||||
latest=auto
|
||||
```
|
||||
|
||||
See also the notes about ["latest tag" behavior](README.md#latest-tag)
|
||||
|
||||
#### `tag-schedule`
|
||||
|
||||
```yaml
|
||||
tags: |
|
||||
# default tag (nightly)
|
||||
type=schedule
|
||||
# specific pattern
|
||||
type=schedule,pattern={{date 'YYYYMMDD'}}
|
||||
```
|
||||
|
||||
#### `tag-custom` / `tag-custom-only`
|
||||
|
||||
```yaml
|
||||
tags: |
|
||||
type=raw,value=foo
|
||||
type=raw,value=bar
|
||||
# or
|
||||
type=raw,foo
|
||||
type=raw,bar
|
||||
# or
|
||||
foo
|
||||
bar
|
||||
```
|
||||
|
||||
#### `label-custom`
|
||||
|
||||
Same behavior for `labels`:
|
||||
|
||||
```yaml
|
||||
labels: |
|
||||
maintainer=CrazyMax
|
||||
```
|
||||
|
||||
### Basic workflow
|
||||
|
||||
```yaml
|
||||
# v1
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'master'
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v1
|
||||
with:
|
||||
images: name/app
|
||||
-
|
||||
name: Login to DockerHub
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
-
|
||||
name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
```
|
||||
|
||||
```yaml
|
||||
# v2
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'master'
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: name/app
|
||||
-
|
||||
name: Login to DockerHub
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
-
|
||||
name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
```
|
||||
|
||||
### Semver workflow
|
||||
|
||||
```yaml
|
||||
# v1
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'master'
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v1
|
||||
with:
|
||||
images: name/app
|
||||
tag-semver: |
|
||||
{{version}}
|
||||
{{major}}.{{minor}}
|
||||
-
|
||||
name: Login to DockerHub
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
-
|
||||
name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
```
|
||||
|
||||
```yaml
|
||||
# v2
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'master'
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: name/app
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
-
|
||||
name: Login to DockerHub
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
-
|
||||
name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
```
|
|
@ -204,4 +204,20 @@ export const context = {
|
|||
}
|
||||
};
|
||||
|
||||
export const getOctokit = jest.fn();
|
||||
export const getOctokit = jest.fn(() => ({
|
||||
rest: {
|
||||
repos: {
|
||||
getCommit: jest.fn(() =>
|
||||
Promise.resolve({
|
||||
data: {
|
||||
commit: {
|
||||
committer: {
|
||||
date: '2024-11-13T13:42:28Z'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -5,9 +5,12 @@ 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 {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||
|
||||
import {ContextSource, getContext, getInputs, Inputs} from '../src/context';
|
||||
|
||||
const toolkit = new Toolkit({githubToken: 'fake-github-token'});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
jest.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => {
|
||||
|
@ -113,9 +116,10 @@ describe('getContext', () => {
|
|||
});
|
||||
|
||||
it('workflow', async () => {
|
||||
const context = await getContext(ContextSource.workflow);
|
||||
const context = await getContext(ContextSource.workflow, toolkit);
|
||||
expect(context.ref).toEqual('refs/heads/dev');
|
||||
expect(context.sha).toEqual('5f3331d7f7044c18ca9f12c77d961c4d7cf3276a');
|
||||
expect(context.commitDate).toEqual(new Date('2024-11-13T13:42:28.000Z'));
|
||||
});
|
||||
|
||||
it('git', async () => {
|
||||
|
@ -125,9 +129,13 @@ describe('getContext', () => {
|
|||
sha: 'git-test-sha'
|
||||
} as Context);
|
||||
});
|
||||
const context = await getContext(ContextSource.git);
|
||||
jest.spyOn(Git, 'commitDate').mockImplementation(async (): Promise<Date> => {
|
||||
return new Date('2023-01-01T13:42:28.000Z');
|
||||
});
|
||||
const context = await getContext(ContextSource.git, toolkit);
|
||||
expect(context.ref).toEqual('refs/heads/git-test');
|
||||
expect(context.sha).toEqual('git-test-sha');
|
||||
expect(context.commitDate).toEqual(new Date('2023-01-01T13:42:28.000Z'));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -2,10 +2,11 @@ import {beforeEach, describe, expect, jest, test} from '@jest/globals';
|
|||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as dotenv from 'dotenv';
|
||||
|
||||
import {Context} from '@actions/github/lib/context';
|
||||
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||
import {GitHubRepo} from '@docker/actions-toolkit/lib/types/github';
|
||||
import {Context} from '@actions/github/lib/context';
|
||||
|
||||
import {ContextSource, getContext, getInputs, Inputs} from '../src/context';
|
||||
import {Meta, Version} from '../src/meta';
|
||||
|
@ -31,8 +32,16 @@ beforeEach(() => {
|
|||
delete process.env[key];
|
||||
}
|
||||
});
|
||||
|
||||
jest.spyOn(GitHub, 'context', 'get').mockImplementation((): Context => {
|
||||
return new Context();
|
||||
//@ts-expect-error partial info
|
||||
return {
|
||||
...new Context(),
|
||||
repo: {
|
||||
owner: 'docker',
|
||||
repo: 'repo'
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -53,7 +62,7 @@ const tagsLabelsTest = async (name: string, envFile: string, inputs: Inputs, exV
|
|||
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||
const toolkit = new Toolkit();
|
||||
const repo = await toolkit.github.repoData();
|
||||
const meta = new Meta({...getInputs(), ...inputs}, await getContext(ContextSource.workflow), repo);
|
||||
const meta = new Meta({...getInputs(), ...inputs}, await getContext(ContextSource.workflow, toolkit), repo);
|
||||
|
||||
const version = meta.version;
|
||||
expect(version).toEqual(exVersion);
|
||||
|
@ -622,6 +631,7 @@ describe('push', () => {
|
|||
tags: [
|
||||
`type=raw,value=mytag-{{branch}}`,
|
||||
`type=raw,value=mytag-{{date 'YYYYMMDD'}}`,
|
||||
`type=raw,value=mytag-cd-{{commit_date 'YYYYMMDD'}}`,
|
||||
`type=raw,value=mytag-{{date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}}`,
|
||||
`type=raw,value=mytag-tag-{{tag}}`,
|
||||
`type=raw,value=mytag-baseref-{{base_ref}}`,
|
||||
|
@ -632,6 +642,7 @@ describe('push', () => {
|
|||
main: 'mytag-master',
|
||||
partial: [
|
||||
'mytag-20200110',
|
||||
"mytag-cd-20200110",
|
||||
'mytag-20200110-093000',
|
||||
'mytag-tag-',
|
||||
'mytag-baseref-',
|
||||
|
@ -642,6 +653,7 @@ describe('push', () => {
|
|||
[
|
||||
'user/app:mytag-master',
|
||||
'user/app:mytag-20200110',
|
||||
'user/app:mytag-cd-20200110',
|
||||
'user/app:mytag-20200110-093000',
|
||||
'user/app:mytag-tag-',
|
||||
'user/app:mytag-baseref-',
|
||||
|
@ -768,16 +780,21 @@ describe('push', () => {
|
|||
`type=raw,value=mytag-{{branch}}`,
|
||||
`type=raw,value=mytag-{{date 'YYYYMMDD'}}`,
|
||||
`type=raw,value=mytag-{{date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}}`,
|
||||
`type=raw,value=mytag-src-{{commit_date 'YYYYMMDD'}}`,
|
||||
`type=raw,value=mytag-tag-{{tag}}`,
|
||||
`type=raw,value=mytag-baseref-{{base_ref}}`,
|
||||
`type=raw,value=mytag-defbranch,enable={{is_default_branch}}`
|
||||
],
|
||||
labels: [
|
||||
"org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}"
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'mytag-master',
|
||||
partial: [
|
||||
'mytag-20200110',
|
||||
'mytag-20200110-093000',
|
||||
'mytag-src-20200110',
|
||||
'mytag-tag-',
|
||||
'mytag-baseref-',
|
||||
'mytag-defbranch'
|
||||
|
@ -788,6 +805,7 @@ describe('push', () => {
|
|||
'mytag-master',
|
||||
'mytag-20200110',
|
||||
'mytag-20200110-093000',
|
||||
'mytag-src-20200110',
|
||||
'mytag-tag-',
|
||||
'mytag-baseref-',
|
||||
'mytag-defbranch'
|
||||
|
@ -2621,6 +2639,35 @@ describe('pr', () => {
|
|||
],
|
||||
undefined
|
||||
],
|
||||
[
|
||||
'pr12',
|
||||
'event_pull_request.env',
|
||||
{
|
||||
images: ['org/app'],
|
||||
tags: [
|
||||
`type=raw,value={{commit_date YYYY-MM-DD-HHmmSS}}`,
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
main: "2020-01-10T00-30-00Z",
|
||||
partial: [],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'org/app:2020-01-10T00-30-00Z'
|
||||
],
|
||||
[
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.description=This your first repo!",
|
||||
"org.opencontainers.image.licenses=MIT",
|
||||
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
|
||||
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
|
||||
"org.opencontainers.image.title=Hello-World",
|
||||
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||
"org.opencontainers.image.version=2020-01-10T00-30-00Z"
|
||||
],
|
||||
undefined
|
||||
],
|
||||
])('given %p with %p event', tagsLabelsTest);
|
||||
});
|
||||
|
||||
|
@ -2969,13 +3016,41 @@ describe('pr-head-sha', () => {
|
|||
"org.opencontainers.image.version=mytag-master"
|
||||
]
|
||||
],
|
||||
[
|
||||
'pr12',
|
||||
'event_pull_request.env',
|
||||
{
|
||||
images: ['org/app'],
|
||||
tags: [
|
||||
`type=raw,value=src-{{commit_date YYYY-MM-DD}}`,
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
main: "src-2020-01-10T00-30-00Z",
|
||||
partial: [],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
"org/app:src-2020-01-10T00-30-00Z",
|
||||
],
|
||||
[
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.description=This your first repo!",
|
||||
"org.opencontainers.image.licenses=MIT",
|
||||
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
|
||||
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
|
||||
"org.opencontainers.image.title=Hello-World",
|
||||
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||
"org.opencontainers.image.version=src-2020-01-10T00-30-00Z",
|
||||
]
|
||||
],
|
||||
])('given %p with %p event', async (name: string, envFile: string, inputs: Inputs, exVersion: Version, exTags: Array<string>, exLabelsAnnotations: Array<string>) => {
|
||||
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||
process.env.DOCKER_METADATA_PR_HEAD_SHA = 'true';
|
||||
|
||||
const toolkit = new Toolkit();
|
||||
const repo = await toolkit.github.repoData();
|
||||
const meta = new Meta({...getInputs(), ...inputs}, await getContext(ContextSource.workflow), repo);
|
||||
const meta = new Meta({...getInputs(), ...inputs}, await getContext(ContextSource.workflow, toolkit), repo);
|
||||
|
||||
const version = meta.version;
|
||||
expect(version).toEqual(exVersion);
|
||||
|
@ -3028,16 +3103,20 @@ describe('schedule', () => {
|
|||
{
|
||||
images: ['user/app'],
|
||||
tags: [
|
||||
`type=schedule,pattern={{date 'YYYYMMDD'}}`
|
||||
`type=schedule,pattern={{date 'YYYYMMDD'}}`,
|
||||
`type=schedule,pattern=source-date-{{commit_date 'YYYY-MM-DD'}}`
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
main: '20200110',
|
||||
partial: [],
|
||||
partial: [
|
||||
"source-date-2020-01-10",
|
||||
],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'user/app:20200110'
|
||||
'user/app:20200110',
|
||||
'user/app:source-date-2020-01-10'
|
||||
],
|
||||
[
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
|
@ -3221,16 +3300,20 @@ describe('schedule', () => {
|
|||
{
|
||||
images: ['user/app'],
|
||||
tags: [
|
||||
`type=schedule,pattern={{date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}}`
|
||||
`type=schedule,pattern={{date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}}`,
|
||||
`type=schedule,pattern=src-{{commit_date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}}`,
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
main: '20200110-093000',
|
||||
partial: [],
|
||||
partial: [
|
||||
"src-20200110-093000",
|
||||
],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'user/app:20200110-093000'
|
||||
'user/app:20200110-093000',
|
||||
'user/app:src-20200110-093000'
|
||||
],
|
||||
[
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
|
@ -3312,6 +3395,39 @@ describe('release', () => {
|
|||
"org.opencontainers.image.version=v1.1.1"
|
||||
],
|
||||
undefined
|
||||
],
|
||||
[
|
||||
'release03',
|
||||
'event_release_created.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
tags: [
|
||||
`type=raw,value=src-{{commit_date 'YYYYMMDD-HHmmss'}}`,
|
||||
`type=raw,value={{date 'YYYYMMDD-HHmmss'}}`,
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
"main": "src-20200110-003000",
|
||||
partial: [
|
||||
"20200110-003000",
|
||||
],
|
||||
"latest": false,
|
||||
} as Version,
|
||||
[
|
||||
"user/app:src-20200110-003000",
|
||||
"user/app:20200110-003000",
|
||||
],
|
||||
[
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.description=This your first repo!",
|
||||
"org.opencontainers.image.licenses=MIT",
|
||||
"org.opencontainers.image.revision=860c1904a1ce19322e91ac35af1ab07466440c37",
|
||||
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
|
||||
"org.opencontainers.image.title=Hello-World",
|
||||
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||
"org.opencontainers.image.version=src-20200110-003000",
|
||||
],
|
||||
undefined
|
||||
]
|
||||
])('given %s with %p event', tagsLabelsTest);
|
||||
});
|
||||
|
@ -4012,7 +4128,7 @@ describe('json', () => {
|
|||
|
||||
const toolkit = new Toolkit();
|
||||
const repo = await toolkit.github.repoData();
|
||||
const meta = new Meta({...getInputs(), ...inputs}, await getContext(ContextSource.workflow), repo);
|
||||
const meta = new Meta({...getInputs(), ...inputs}, await getContext(ContextSource.workflow,toolkit), repo);
|
||||
|
||||
const jsonOutput = meta.getJSON(['manifest']);
|
||||
expect(jsonOutput).toEqual(exJSON);
|
||||
|
@ -4528,7 +4644,7 @@ describe('bakeFile', () => {
|
|||
|
||||
const toolkit = new Toolkit();
|
||||
const repo = await toolkit.github.repoData();
|
||||
const meta = new Meta({...getInputs(), ...inputs}, await getContext(ContextSource.workflow), repo);
|
||||
const meta = new Meta({...getInputs(), ...inputs}, await getContext(ContextSource.workflow,toolkit), repo);
|
||||
|
||||
const bakeFileTags = meta.getBakeFile('tags');
|
||||
expect(JSON.parse(fs.readFileSync(bakeFileTags, 'utf8'))).toEqual(exBakeTags);
|
||||
|
@ -4592,7 +4708,7 @@ describe('bakeFileTagsLabels', () => {
|
|||
|
||||
const toolkit = new Toolkit();
|
||||
const repo = await toolkit.github.repoData();
|
||||
const meta = new Meta({...getInputs(), ...inputs}, await getContext(ContextSource.workflow), repo);
|
||||
const meta = new Meta({...getInputs(), ...inputs}, await getContext(ContextSource.workflow,toolkit), repo);
|
||||
|
||||
const bakeFile = meta.getBakeFileTagsLabels();
|
||||
expect(JSON.parse(fs.readFileSync(bakeFile, 'utf8'))).toEqual(exBakeDefinition);
|
||||
|
@ -4638,8 +4754,10 @@ describe('sepTags', () => {
|
|||
process.env = dotenv.parse(fs.readFileSync(path.join(__dirname, 'fixtures', envFile)));
|
||||
|
||||
const toolkit = new Toolkit();
|
||||
|
||||
const repo = await toolkit.github.repoData();
|
||||
const meta = new Meta({...getInputs(), ...inputs}, await getContext(ContextSource.workflow), repo);
|
||||
|
||||
const meta = new Meta({...getInputs(), ...inputs}, await getContext(ContextSource.workflow, toolkit), repo);
|
||||
|
||||
expect(meta.getTags().join(inputs.sepTags)).toEqual(expTags);
|
||||
});
|
||||
|
|
|
@ -59,7 +59,7 @@ outputs:
|
|||
bake-file-labels:
|
||||
description: 'Bake definition file with labels'
|
||||
bake-file-annotations:
|
||||
description: 'Bake definiton file with annotations'
|
||||
description: 'Bake definition file with annotations'
|
||||
bake-file:
|
||||
description: 'Bake definition file with tags and labels'
|
||||
|
||||
|
|
|
@ -5,9 +5,16 @@ ARG NODE_VERSION=20
|
|||
FROM node:${NODE_VERSION}-alpine AS base
|
||||
RUN apk add --no-cache cpio findutils git
|
||||
WORKDIR /src
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/.yarn/cache <<EOT
|
||||
corepack enable
|
||||
yarn --version
|
||||
yarn config set --home enableTelemetry 0
|
||||
EOT
|
||||
|
||||
FROM base AS deps
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/.yarn/cache \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn install && mkdir /vendor && cp yarn.lock /vendor
|
||||
|
||||
|
@ -20,7 +27,7 @@ RUN --mount=type=bind,target=.,rw <<EOT
|
|||
git add -A
|
||||
cp -rf /vendor/* .
|
||||
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"'
|
||||
git status --porcelain -- yarn.lock
|
||||
exit 1
|
||||
fi
|
||||
|
@ -28,6 +35,7 @@ EOT
|
|||
|
||||
FROM deps AS build
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/.yarn/cache \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn run build && mkdir /out && cp -Rf dist /out/
|
||||
|
||||
|
@ -48,22 +56,23 @@ EOT
|
|||
|
||||
FROM deps AS format
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/.yarn/cache \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn run format \
|
||||
&& mkdir /out && find . -name '*.ts' -not -path './node_modules/*' | cpio -pdm /out
|
||||
&& mkdir /out && find . -name '*.ts' -not -path './node_modules/*' -not -path './.yarn/*' | cpio -pdm /out
|
||||
|
||||
FROM scratch AS format-update
|
||||
COPY --from=format /out /
|
||||
|
||||
FROM deps AS lint
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/.yarn/cache \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn run lint
|
||||
|
||||
FROM deps AS test
|
||||
ENV RUNNER_TEMP=/tmp/github_runner
|
||||
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/.yarn/cache \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn run test --coverage --coverageDirectory=/tmp/coverage
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -1,9 +1,15 @@
|
|||
target "_common" {
|
||||
args = {
|
||||
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
|
||||
}
|
||||
}
|
||||
|
||||
group "default" {
|
||||
targets = ["build"]
|
||||
}
|
||||
|
||||
group "pre-checkin" {
|
||||
targets = ["vendor-update", "format", "build"]
|
||||
targets = ["vendor", "format", "build"]
|
||||
}
|
||||
|
||||
group "validate" {
|
||||
|
@ -11,42 +17,49 @@ group "validate" {
|
|||
}
|
||||
|
||||
target "build" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "build-update"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "build-validate" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "build-validate"
|
||||
output = ["type=cacheonly"]
|
||||
}
|
||||
|
||||
target "format" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "format-update"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "lint" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "lint"
|
||||
output = ["type=cacheonly"]
|
||||
}
|
||||
|
||||
target "vendor-update" {
|
||||
target "vendor" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "vendor-update"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "vendor-validate" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "vendor-validate"
|
||||
output = ["type=cacheonly"]
|
||||
}
|
||||
|
||||
target "test" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "test-coverage"
|
||||
output = ["./coverage"]
|
||||
|
|
50
package.json
50
package.json
|
@ -1,17 +1,16 @@
|
|||
{
|
||||
"name": "docker-metadata-action",
|
||||
"description": "GitHub Action to extract metadata (tags, labels) for Docker",
|
||||
"main": "lib/main.js",
|
||||
"main": "src/main.ts",
|
||||
"scripts": {
|
||||
"build": "ncc build src/main.ts --source-map --minify --license licenses.txt",
|
||||
"build": "ncc build --source-map --minify --license licenses.txt",
|
||||
"lint": "yarn run prettier && yarn run eslint",
|
||||
"format": "yarn run prettier:fix && yarn run eslint:fix",
|
||||
"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"
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -26,33 +25,34 @@
|
|||
],
|
||||
"author": "Docker Inc.",
|
||||
"license": "Apache-2.0",
|
||||
"packageManager": "yarn@3.6.3",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/core": "^1.11.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@docker/actions-toolkit": "^0.14.0",
|
||||
"@docker/actions-toolkit": "^0.56.0",
|
||||
"@renovate/pep440": "^1.0.0",
|
||||
"csv-parse": "^5.5.2",
|
||||
"csv-parse": "^5.6.0",
|
||||
"handlebars": "^4.7.8",
|
||||
"moment": "^2.29.4",
|
||||
"moment-timezone": "^0.5.43",
|
||||
"semver": "^7.5.4"
|
||||
"moment": "^2.30.1",
|
||||
"moment-timezone": "^0.5.47",
|
||||
"semver": "^7.7.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/csv-parse": "^1.2.2",
|
||||
"@types/node": "^20.5.9",
|
||||
"@types/semver": "^7.5.1",
|
||||
"@typescript-eslint/eslint-plugin": "^6.6.0",
|
||||
"@typescript-eslint/parser": "^6.6.0",
|
||||
"@vercel/ncc": "^0.38.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"eslint": "^8.48.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-jest": "^27.2.3",
|
||||
"eslint-plugin-prettier": "^5.0.0",
|
||||
"jest": "^29.6.4",
|
||||
"prettier": "^3.0.3",
|
||||
"ts-jest": "^29.1.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.2.2"
|
||||
"@types/node": "^20.12.12",
|
||||
"@types/semver": "^7.5.8",
|
||||
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
||||
"@typescript-eslint/parser": "^7.9.0",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"dotenv": "^16.4.5",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-jest": "^28.5.0",
|
||||
"eslint-plugin-prettier": "^5.1.3",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^3.2.5",
|
||||
"ts-jest": "^29.1.2",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.4.5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
import * as core from '@actions/core';
|
||||
import {Context} from '@actions/github/lib/context';
|
||||
import {Context as GithubContext} from '@actions/github/lib/context';
|
||||
import {Util} from '@docker/actions-toolkit/lib/util';
|
||||
import {Git} from '@docker/actions-toolkit/lib/git';
|
||||
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||
|
||||
export interface Context extends GithubContext {
|
||||
commitDate: Date;
|
||||
}
|
||||
|
||||
export interface Inputs {
|
||||
context: ContextSource;
|
||||
|
@ -39,10 +44,10 @@ export enum ContextSource {
|
|||
git = 'git'
|
||||
}
|
||||
|
||||
export async function getContext(source: ContextSource): Promise<Context> {
|
||||
export async function getContext(source: ContextSource, toolkit: Toolkit): Promise<Context> {
|
||||
switch (source) {
|
||||
case ContextSource.workflow:
|
||||
return getContextFromWorkflow();
|
||||
return await getContextFromWorkflow(toolkit);
|
||||
case ContextSource.git:
|
||||
return await getContextFromGit();
|
||||
default:
|
||||
|
@ -50,7 +55,7 @@ export async function getContext(source: ContextSource): Promise<Context> {
|
|||
}
|
||||
}
|
||||
|
||||
function getContextFromWorkflow(): Context {
|
||||
async function getContextFromWorkflow(toolkit: Toolkit): Promise<Context> {
|
||||
const context = GitHub.context;
|
||||
|
||||
// Needs to override Git reference with pr ref instead of upstream branch ref
|
||||
|
@ -69,9 +74,63 @@ function getContextFromWorkflow(): Context {
|
|||
}
|
||||
}
|
||||
|
||||
return context;
|
||||
return {
|
||||
commitDate: await getCommitDateFromWorkflow(context.sha, toolkit),
|
||||
...context
|
||||
} as Context;
|
||||
}
|
||||
|
||||
async function getContextFromGit(): Promise<Context> {
|
||||
return await Git.context();
|
||||
const ctx = await Git.context();
|
||||
|
||||
return {
|
||||
commitDate: await Git.commitDate(ctx.sha),
|
||||
...ctx
|
||||
} as Context;
|
||||
}
|
||||
|
||||
async function getCommitDateFromWorkflow(sha: string, toolkit: Toolkit): Promise<Date> {
|
||||
const event = GitHub.context.payload as unknown as {
|
||||
// branch push
|
||||
commits?: Array<{
|
||||
timestamp: string;
|
||||
// commit sha
|
||||
id: string;
|
||||
}>;
|
||||
// tags
|
||||
head_commit?: {
|
||||
timestamp: string;
|
||||
// commit sha
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
if (event.commits) {
|
||||
const commitDate = event.commits.find(x => x.id === sha)?.timestamp;
|
||||
if (commitDate) {
|
||||
return new Date(commitDate);
|
||||
}
|
||||
}
|
||||
|
||||
if (event.head_commit) {
|
||||
if (event.head_commit.id === sha) {
|
||||
return new Date(event.head_commit.timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to github api for commit date
|
||||
try {
|
||||
const commit = await toolkit.github.octokit.rest.repos.getCommit({
|
||||
owner: GitHub.context.repo.owner,
|
||||
repo: GitHub.context.repo.repo,
|
||||
ref: sha
|
||||
});
|
||||
if (commit.data.commit.committer?.date) {
|
||||
return new Date(commit.data.commit.committer.date);
|
||||
}
|
||||
throw new Error('Committer date not found');
|
||||
} catch (error) {
|
||||
core.debug(`Failed to get commit date from GitHub API: ${error.message}`);
|
||||
return new Date();
|
||||
}
|
||||
}
|
||||
|
|
24
src/main.ts
24
src/main.ts
|
@ -2,22 +2,19 @@ import * as fs from 'fs';
|
|||
import * as core from '@actions/core';
|
||||
import * as actionsToolkit from '@docker/actions-toolkit';
|
||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||
import {Util} from '@docker/actions-toolkit/lib/util';
|
||||
|
||||
import {getContext, getInputs, Inputs} from './context';
|
||||
import {Meta, Version} from './meta';
|
||||
|
||||
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();
|
||||
const toolkit = new Toolkit({githubToken: inputs.githubToken});
|
||||
const context = await getContext(inputs.context);
|
||||
const context = await getContext(inputs.context, toolkit);
|
||||
const repo = await toolkit.github.repoData();
|
||||
const setOutput = outputEnvEnabled() ? setOutputAndEnv : core.setOutput;
|
||||
|
||||
await core.group(`Context info`, async () => {
|
||||
core.info(`eventName: ${context.eventName}`);
|
||||
|
@ -28,6 +25,7 @@ actionsToolkit.run(
|
|||
core.info(`actor: ${context.actor}`);
|
||||
core.info(`runNumber: ${context.runNumber}`);
|
||||
core.info(`runId: ${context.runId}`);
|
||||
core.info(`commitDate: ${context.commitDate}`);
|
||||
});
|
||||
|
||||
if (core.isDebug()) {
|
||||
|
@ -105,6 +103,18 @@ actionsToolkit.run(
|
|||
}
|
||||
|
||||
// Bake file with tags and labels
|
||||
setOutput(`bake-file`, meta.getBakeFileTagsLabels());
|
||||
setOutput(`bake-file`, `${meta.getBakeFileTagsLabels()}`);
|
||||
}
|
||||
);
|
||||
|
||||
function setOutputAndEnv(name: string, value: string) {
|
||||
core.setOutput(name, value);
|
||||
core.exportVariable(`DOCKER_METADATA_OUTPUT_${name.replace(/\W/g, '_').toUpperCase()}`, value);
|
||||
}
|
||||
|
||||
function outputEnvEnabled(): boolean {
|
||||
if (process.env.DOCKER_METADATA_SET_OUTPUT_ENV) {
|
||||
return Util.parseBool(process.env.DOCKER_METADATA_SET_OUTPUT_ENV);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
155
src/meta.ts
155
src/meta.ts
|
@ -5,15 +5,16 @@ import moment from 'moment-timezone';
|
|||
import * as pep440 from '@renovate/pep440';
|
||||
import * as semver from 'semver';
|
||||
import * as core from '@actions/core';
|
||||
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 {Inputs, Context} from './context';
|
||||
import * as icl from './image';
|
||||
import * as tcl from './tag';
|
||||
import * as fcl from './flavor';
|
||||
|
||||
const defaultShortShaLength = 7;
|
||||
|
||||
export interface Version {
|
||||
main: string | undefined;
|
||||
partial: string[];
|
||||
|
@ -113,6 +114,7 @@ export class Meta {
|
|||
}
|
||||
|
||||
const currentDate = this.date;
|
||||
const commitDate = this.context.commitDate;
|
||||
const vraw = this.setValue(
|
||||
handlebars.compile(tag.attrs['pattern'])({
|
||||
date: function (format, options) {
|
||||
|
@ -128,6 +130,20 @@ export class Meta {
|
|||
}
|
||||
});
|
||||
return m.tz(tz).format(format);
|
||||
},
|
||||
commit_date: function (format, options) {
|
||||
const m = moment(commitDate);
|
||||
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
|
||||
|
@ -307,7 +323,7 @@ export class Meta {
|
|||
|
||||
let val = this.context.sha;
|
||||
if (tag.attrs['format'] === tcl.ShaFormat.Short) {
|
||||
val = this.context.sha.substring(0, 7);
|
||||
val = Meta.shortSha(this.context.sha);
|
||||
}
|
||||
|
||||
const vraw = this.setValue(val, tag);
|
||||
|
@ -356,9 +372,10 @@ export class Meta {
|
|||
return val;
|
||||
}
|
||||
|
||||
private setGlobalExp(val): string {
|
||||
private setGlobalExp(val: string): string {
|
||||
const context = this.context;
|
||||
const currentDate = this.date;
|
||||
const commitDate = this.context.commitDate;
|
||||
return handlebars.compile(val)({
|
||||
branch: function () {
|
||||
if (!/^refs\/heads\//.test(context.ref)) {
|
||||
|
@ -373,7 +390,7 @@ export class Meta {
|
|||
return context.ref.replace(/^refs\/tags\//g, '');
|
||||
},
|
||||
sha: function () {
|
||||
return context.sha.substring(0, 7);
|
||||
return Meta.shortSha(context.sha);
|
||||
},
|
||||
base_ref: function () {
|
||||
if (/^refs\/tags\//.test(context.ref) && context.payload?.base_ref != undefined) {
|
||||
|
@ -386,6 +403,20 @@ export class Meta {
|
|||
}
|
||||
return '';
|
||||
},
|
||||
commit_date: function (format, options) {
|
||||
const m = moment(commitDate);
|
||||
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);
|
||||
},
|
||||
is_default_branch: function () {
|
||||
const branch = context.ref.replace(/^refs\/heads\//g, '');
|
||||
// TODO: "base_ref" is available in the push payload but doesn't always seem to
|
||||
|
@ -486,7 +517,9 @@ export class Meta {
|
|||
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
||||
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
|
||||
];
|
||||
res.push(...extra);
|
||||
extra.forEach(label => {
|
||||
res.push(this.setGlobalExp(label));
|
||||
});
|
||||
|
||||
return Array.from(
|
||||
new Map<string, string>(
|
||||
|
@ -522,70 +555,66 @@ export class Meta {
|
|||
|
||||
public getBakeFile(kind: string): string {
|
||||
if (kind == 'tags') {
|
||||
return this.generateBakeFile(kind, {
|
||||
tags: this.getTags(),
|
||||
args: {
|
||||
DOCKER_META_IMAGES: this.getImageNames().join(','),
|
||||
DOCKER_META_VERSION: this.version.main
|
||||
}
|
||||
});
|
||||
} else if (kind == 'labels') {
|
||||
return this.generateBakeFile(kind, {
|
||||
labels: this.getLabels().reduce((res, label) => {
|
||||
const matches = label.match(/([^=]*)=(.*)/);
|
||||
if (!matches) {
|
||||
return res;
|
||||
return this.generateBakeFile(
|
||||
{
|
||||
tags: this.getTags(),
|
||||
args: {
|
||||
DOCKER_META_IMAGES: this.getImageNames().join(','),
|
||||
DOCKER_META_VERSION: this.version.main
|
||||
}
|
||||
res[matches[1]] = matches[2];
|
||||
return res;
|
||||
}, {})
|
||||
});
|
||||
},
|
||||
kind
|
||||
);
|
||||
} else if (kind == 'labels') {
|
||||
return this.generateBakeFile(
|
||||
{
|
||||
labels: this.getLabels().reduce((res, label) => {
|
||||
const matches = label.match(/([^=]*)=(.*)/);
|
||||
if (!matches) {
|
||||
return res;
|
||||
}
|
||||
res[matches[1]] = matches[2];
|
||||
return res;
|
||||
}, {})
|
||||
},
|
||||
kind
|
||||
);
|
||||
} else if (kind.startsWith('annotations:')) {
|
||||
const name = kind.split(':')[0];
|
||||
const annotations: Array<string> = [];
|
||||
for (const level of kind.split(':')[1].split(',')) {
|
||||
annotations.push(...this.getAnnotations().map(label => `${level}:${label}`));
|
||||
}
|
||||
return this.generateBakeFile(name, {
|
||||
annotations: annotations
|
||||
});
|
||||
return this.generateBakeFile(
|
||||
{
|
||||
annotations: annotations
|
||||
},
|
||||
name
|
||||
);
|
||||
}
|
||||
throw new Error(`Unknown bake file type: ${kind}`);
|
||||
}
|
||||
|
||||
public getBakeFileTagsLabels(): string {
|
||||
const bakeFile = path.join(ToolkitContext.tmpDir(), 'docker-metadata-action-bake.json');
|
||||
fs.writeFileSync(
|
||||
bakeFile,
|
||||
JSON.stringify(
|
||||
{
|
||||
target: {
|
||||
[this.inputs.bakeTarget]: {
|
||||
tags: this.getTags(),
|
||||
labels: this.getLabels().reduce((res, label) => {
|
||||
const matches = label.match(/([^=]*)=(.*)/);
|
||||
if (!matches) {
|
||||
return res;
|
||||
}
|
||||
res[matches[1]] = matches[2];
|
||||
return res;
|
||||
}, {}),
|
||||
args: {
|
||||
DOCKER_META_IMAGES: this.getImageNames().join(','),
|
||||
DOCKER_META_VERSION: this.version.main
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
return bakeFile;
|
||||
return this.generateBakeFile({
|
||||
tags: this.getTags(),
|
||||
labels: this.getLabels().reduce((res, label) => {
|
||||
const matches = label.match(/([^=]*)=(.*)/);
|
||||
if (!matches) {
|
||||
return res;
|
||||
}
|
||||
res[matches[1]] = matches[2];
|
||||
return res;
|
||||
}, {}),
|
||||
args: {
|
||||
DOCKER_META_IMAGES: this.getImageNames().join(','),
|
||||
DOCKER_META_VERSION: this.version.main
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private generateBakeFile(name: string, dt): string {
|
||||
const bakeFile = path.join(ToolkitContext.tmpDir(), `docker-metadata-action-bake-${name}.json`);
|
||||
private generateBakeFile(dt, suffix?: string): string {
|
||||
const bakeFile = path.join(ToolkitContext.tmpDir(), `docker-metadata-action-bake${suffix ? `-${suffix}` : ''}.json`);
|
||||
fs.writeFileSync(bakeFile, JSON.stringify({target: {[this.inputs.bakeTarget]: dt}}, null, 2));
|
||||
return bakeFile;
|
||||
}
|
||||
|
@ -597,4 +626,18 @@ export class Meta {
|
|||
private static sanitizeTag(tag: string): string {
|
||||
return tag.replace(/[^a-zA-Z0-9._-]+/g, '-');
|
||||
}
|
||||
|
||||
private static shortSha(sha: string): string {
|
||||
let shortShaLength = defaultShortShaLength;
|
||||
if (process.env.DOCKER_METADATA_SHORT_SHA_LENGTH) {
|
||||
if (isNaN(Number(process.env.DOCKER_METADATA_SHORT_SHA_LENGTH))) {
|
||||
throw new Error(`DOCKER_METADATA_SHORT_SHA_LENGTH is not a valid number: ${process.env.DOCKER_METADATA_SHORT_SHA_LENGTH}`);
|
||||
}
|
||||
shortShaLength = Number(process.env.DOCKER_METADATA_SHORT_SHA_LENGTH);
|
||||
}
|
||||
if (shortShaLength >= sha.length) {
|
||||
return sha;
|
||||
}
|
||||
return sha.substring(0, shortShaLength);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue