Compare commits

..

22 Commits

Author SHA1 Message Date
CrazyMax
f02d9f4f9b Update CHANGELOG 2021-05-08 01:20:23 +02:00
CrazyMax
400bd87b5a Major version zero doc (#74)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-05-08 00:01:13 +02:00
dependabot[bot]
e4fc7e9e11 Bump hosted-git-info from 2.8.8 to 2.8.9 (#73)
Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.8.8 to 2.8.9.
- [Release notes](https://github.com/npm/hosted-git-info/releases)
- [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md)
- [Commits](https://github.com/npm/hosted-git-info/compare/v2.8.8...v2.8.9)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2021-05-07 21:59:27 +02:00
dependabot[bot]
9583a0f404 Bump lodash from 4.17.20 to 4.17.21 (#72)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.20 to 4.17.21.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.20...4.17.21)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-07 21:55:33 +02:00
CrazyMax
5e6d5157fb Handle global expressions (#71)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-05-07 21:53:30 +02:00
CrazyMax
e09df4df3c Update CHANGELOG 2021-04-30 00:54:35 +02:00
CrazyMax
72e5d60481 Add bake-target input (#69)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-04-30 00:51:48 +02:00
CrazyMax
ae431178c1 Fix setOutput (#67)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-04-24 00:44:38 +02:00
Teppei Yano
34ebfd6e6b Fix upgrade notes (#66) 2021-04-22 12:06:16 +02:00
dependabot[bot]
94641ff1bb Bump csv-parse from 4.15.3 to 4.15.4 (#65)
* Bump csv-parse from 4.15.3 to 4.15.4

Bumps [csv-parse](https://github.com/wdavidw/node-csv-parse) from 4.15.3 to 4.15.4.
- [Release notes](https://github.com/wdavidw/node-csv-parse/releases)
- [Changelog](https://github.com/adaltas/node-csv-parse/blob/master/CHANGELOG.md)
- [Commits](https://github.com/wdavidw/node-csv-parse/compare/v4.15.3...v4.15.4)

Signed-off-by: dependabot[bot] <support@github.com>

* Update generated content

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
Co-authored-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2021-04-16 10:49:42 +02:00
dependabot[bot]
40bfc8b527 Bump @actions/core from 1.2.6 to 1.2.7 (#64)
* Bump @actions/core from 1.2.6 to 1.2.7

Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.6 to 1.2.7.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>

* Update generated content

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-04-16 10:32:55 +02:00
CrazyMax
2e1a5c7fa4 Update CHANGELOG 2021-04-07 21:00:00 +02:00
CrazyMax
1a678de43d Allow to override flavor (#63)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-04-07 20:54:35 +02:00
CrazyMax
84b9e75d44 Prefix/suffix not taken into account (#62)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-04-07 20:31:35 +02:00
CrazyMax
f39f06a624 Update CHANGELOG 2021-04-05 21:30:44 +02:00
CrazyMax
36ae18e02c Skip and display warning if tag does not match (#59)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-04-05 21:19:05 +02:00
CrazyMax
e87dd9466c Fix workflow 2021-04-03 18:44:12 +02:00
CrazyMax
9da1e66de9 Update CHANGELOG 2021-04-03 18:21:52 +02:00
CrazyMax
521a3c5ada Fix README (#56) 2021-04-03 18:18:32 +02:00
CrazyMax
7433b42479 Improve logging (#58)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-04-03 18:15:27 +02:00
CrazyMax
1a8a264b95 Update README 2021-03-31 10:01:20 +02:00
CrazyMax
e04b4d01a9 Cleanup 2021-03-30 13:57:33 +02:00
18 changed files with 770 additions and 428 deletions

View File

@@ -72,9 +72,9 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
include: include:
- tag-match: '\d{1,3}.\d{1,3}.\d{1,3}' - tag-match: '\d.\d.\d'
tag-match-group: '0' tag-match-group: '0'
- tag-match: '\d{1,3}.\d{1,3}' - tag-match: '\d.\d'
tag-match-group: '0' tag-match-group: '0'
- tag-match: 'v(.*)' - tag-match: 'v(.*)'
tag-match-group: '1' tag-match-group: '1'

View File

@@ -1,9 +1,6 @@
name: label-sponsor name: label-sponsor
on: on:
pull_request:
types:
- 'opened'
issues: issues:
types: types:
- 'opened' - 'opened'

View File

@@ -1,5 +1,33 @@
# Changelog # Changelog
## 2.5.0 (2021/05/08)
* Major version zero doc (#74)
* Bump hosted-git-info from 2.8.8 to 2.8.9 (#73)
* Bump lodash from 4.17.20 to 4.17.21 (#72)
* Handle global expressions (#71)
## 2.4.0 (2021/04/30)
* Add `bake-target` input (#69)
* Fix setOutput (#67)
* Bump csv-parse from 4.15.3 to 4.15.4 (#65)
* Bump @actions/core from 1.2.6 to 1.2.7 (#64)
## 2.3.0 (2021/04/07)
* Allow overriding flavor (#63)
* Prefix/suffix not taken into account for `match`, `semver` and `schedule` types (#62)
## 2.2.1 (2021/04/05)
* Skip and display warning if tag does not match (#59)
## 2.2.0 (2021/04/03)
* Improve logging (#58)
* Fix README (#56)
## 2.1.1 (2021/03/30) ## 2.1.1 (2021/03/30)
* Fix `enable` tag attribute (#53) * Fix `enable` tag attribute (#53)

View File

@@ -38,6 +38,8 @@ ___
* [`type=sha`](#typesha) * [`type=sha`](#typesha)
* [Notes](#notes) * [Notes](#notes)
* [Latest tag](#latest-tag) * [Latest tag](#latest-tag)
* [Global expressions](#global-expressions)
* [Major version zero](#major-version-zero)
* [Overwrite labels](#overwrite-labels) * [Overwrite labels](#overwrite-labels)
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot) * [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
* [Contributing](#contributing) * [Contributing](#contributing)
@@ -252,7 +254,7 @@ Following inputs can be used as `step.with` keys
> `List` type is a newline-delimited string > `List` type is a newline-delimited string
> ```yaml > ```yaml
> label-custom: | > labels: |
> org.opencontainers.image.title=MyCustomTitle > org.opencontainers.image.title=MyCustomTitle
> org.opencontainers.image.description=Another description > org.opencontainers.image.description=Another description
> org.opencontainers.image.vendor=MyCompany > org.opencontainers.image.vendor=MyCompany
@@ -271,6 +273,7 @@ Following inputs can be used as `step.with` keys
| `labels` | List | List of custom labels | | `labels` | List | List of custom labels |
| `sep-tags` | String | Separator to use for tags output (default `\n`) | | `sep-tags` | String | Separator to use for tags output (default `\n`) |
| `sep-labels` | String | Separator to use for labels output (default `\n`) | | `sep-labels` | String | Separator to use for labels output (default `\n`) |
| `bake-target` | String | Bake target name (default `ghaction-docker-meta`) |
### outputs ### outputs
@@ -420,9 +423,7 @@ tags: |
```yaml ```yaml
tags: | tags: |
# minimal # minimal
type=match,pattern=\d{8} type=match,pattern=\d.\d.\d
# double quotes if comma in pattern
type=match,"pattern=\d{1,3}.\d{1,3}.\d{1,3}"
# define match group # define match group
type=match,pattern=v(.*),group=1 type=match,pattern=v(.*),group=1
# use custom value instead of git tag # use custom value instead of git tag
@@ -435,16 +436,17 @@ a custom value through `value` attribute.
| Git tag | Pattern | Group | Output | | Git tag | Pattern | Group | Output |
|-------------------------|-------------------------------|---------|------------------------| |-------------------------|-------------------------------|---------|------------------------|
| `v1.2.3` | `\d{1,3}.\d{1,3}.\d{1,3}` | `0` | `1.2.3` | | `v1.2.3` | `\d.\d.\d` | `0` | `1.2.3` |
| `v2.0.8-beta.67` | `v(.*)` | `1` | `2.0.8-beta.67` | | `v2.0.8-beta.67` | `v(.*)` | `1` | `2.0.8-beta.67` |
| `v2.0.8-beta.67` | `v(\d.\d)` | `1` | `2.0` | | `v2.0.8-beta.67` | `v(\d.\d)` | `1` | `2.0` |
| `20200110-RC2` | `\d+` | `0` | `20200110` | | `20200110-RC2` | `\d+` | `0` | `20200110` |
| `p1/v1.2.3` | `p1-v(\d.\d.\d)` | `1` | `1.2.3` |
Extended attributes and default values: Extended attributes and default values:
```yaml ```yaml
tags: | tags: |
type=group,enable=true,priority=800,prefix=,suffix=,pattern=,group=0,value= type=match,enable=true,priority=800,prefix=,suffix=,pattern=,group=0,value=
``` ```
### `type=edge` ### `type=edge`
@@ -472,11 +474,11 @@ tags: |
```yaml ```yaml
tags: | tags: |
# minimal branch event # branch event
type=ref,event=branch type=ref,event=branch
# minimal tag event # tag event
type=ref,event=tag type=ref,event=tag
# minimal pull request event # pull request event
type=ref,event=pr type=ref,event=pr
``` ```
@@ -497,11 +499,11 @@ Extended attributes and default values:
```yaml ```yaml
tags: | tags: |
# event branch # branch event
type=ref,enable=true,priority=600,prefix=,suffix=,event= type=ref,enable=true,priority=600,prefix=,suffix=,event=
# event tag # tag event
type=ref,enable=true,priority=600,prefix=,suffix=,event= type=ref,enable=true,priority=600,prefix=,suffix=,event=
# event pr # pull request event
type=ref,enable=true,priority=600,prefix=pr-,suffix=,event= type=ref,enable=true,priority=600,prefix=pr-,suffix=,event=
``` ```
@@ -554,6 +556,44 @@ tags: |
* [`type=semver,pattern=...`](#typesemver) * [`type=semver,pattern=...`](#typesemver)
* [`type=match,pattern=...`](#typematch) * [`type=match,pattern=...`](#typematch)
### Global expressions
The following [Handlebars template](https://handlebarsjs.com/guide/) expressions for `prefix`, `suffix` and `value`
attributes are available:
| Expression | Output |
|--------------------------|----------------------|
| `{{branch}}` | `master` |
| `{{tag}}` | `v1.2.3` |
| `{{sha}}` | `90dd603` |
```yaml
tags: |
# dynamically set the branch name as a prefix
type=sha,prefix={{branch}}-
# dynamically set the branch name and sha as a custom tag
type=raw,value=mytag-{{branch}}-{{sha}}
```
### Major version zero
Major version zero (`0.y.z`) is for initial development and **may** change at 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}}`
pattern. You can manage this behavior like this:
```yaml
# refs/tags/v0.1.2
tags: |
# output 0.1.2
type=semver,pattern={{version}}
# output 0.1
type=semver,pattern={{major}}.{{minor}}
# disabled if major zero
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
```
### Overwrite labels ### Overwrite labels
If some of the [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md) If some of the [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md)

View File

@@ -147,8 +147,8 @@ jobs:
with: with:
context: . context: .
push: ${{ github.event_name != 'pull_request' }} push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
``` ```
```yaml ```yaml

View File

@@ -1,4 +1,5 @@
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 * as context from '../src/context'; import * as context from '../src/context';
@@ -171,6 +172,27 @@ describe('asyncForEach', () => {
}); });
}); });
describe('setOutput', () => {
beforeEach(() => {
process.stdout.write = jest.fn();
});
it('setOutput produces the correct command', () => {
context.setOutput('some output', 'some value');
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]);
});
it('setOutput handles bools', () => {
context.setOutput('some output', false);
assertWriteCalls([`::set-output name=some output::false${os.EOL}`]);
});
it('setOutput handles numbers', () => {
context.setOutput('some output', 1.01);
assertWriteCalls([`::set-output name=some output::1.01${os.EOL}`]);
});
});
// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67 // See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
function getInputName(name: string): string { function getInputName(name: string): string {
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
@@ -179,3 +201,11 @@ 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]);
}
}

View File

@@ -0,0 +1,23 @@
GITHUB_ACTION=crazy-maxghaction-dump-context
GITHUB_ACTIONS=true
GITHUB_ACTION_PATH=/home/runner/work/_actions/crazy-max/ghaction-dump-context/v1
GITHUB_ACTOR=crazy-max
GITHUB_API_URL=https://api.github.com
GITHUB_BASE_REF=
GITHUB_ENV=/home/runner/work/_temp/_runner_file_commands/set_env_6ee180c2-b331-434a-a867-89534cbefd83
GITHUB_EVENT_NAME=push
#GITHUB_EVENT_PATH=/home/runner/work/_temp/_github_workflow/event.json
GITHUB_GRAPHQL_URL=https://api.github.com/graphql
GITHUB_HEAD_REF=
GITHUB_JOB=event
GITHUB_PATH=/home/runner/work/_temp/_runner_file_commands/add_path_6ee180c2-b331-434a-a867-89534cbefd83
GITHUB_REF=refs/tags/p1/v1.0.0
GITHUB_REPOSITORY=crazy-max/test-docker-action
GITHUB_REPOSITORY_OWNER=crazy-max
GITHUB_RETENTION_DAYS=90
GITHUB_RUN_ID=325968230
GITHUB_RUN_NUMBER=4
GITHUB_SERVER_URL=https://github.com
GITHUB_SHA=90dd6032fac8bda1b6c4436a2e65de27961ed071
GITHUB_WORKFLOW=event
GITHUB_WORKSPACE=/home/runner/work/test-docker-action/test-docker-action

View File

@@ -89,7 +89,8 @@ describe('null', () => {
{ {
images: ['user/app'], images: ['user/app'],
tags: [ tags: [
`type=sha` `type=sha`,
`type=raw,{{branch}}`,
] ]
} as Inputs, } as Inputs,
{ {
@@ -557,6 +558,65 @@ describe('push', () => {
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071", "org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT" "org.opencontainers.image.licenses=MIT"
] ]
],
[
'push16',
'event_push_defbranch.env',
{
images: ['user/app'],
tags: [
`type=match,enable=false,pattern=v(.*),group=1,value=v1.2.3`,
`type=edge`
],
} as Inputs,
{
main: 'edge',
partial: [],
latest: false
} as Version,
[
'user/app:edge'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=edge",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'push17',
'event_push_defbranch.env',
{
images: ['user/app'],
tags: [
`type=raw,value=mytag-{{branch}}`,
`type=raw,value=mytag-{{tag}}`
],
} as Inputs,
{
main: 'mytag-master',
partial: ['mytag-'],
latest: false
} as Version,
[
'user/app:mytag-master',
'user/app:mytag-'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=mytag-master",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
] ]
])('given %p with %p event', tagsLabelsTest); ])('given %p with %p event', tagsLabelsTest);
}); });
@@ -684,7 +744,7 @@ describe('tag', () => {
{ {
images: ['org/app', 'ghcr.io/user/app'], images: ['org/app', 'ghcr.io/user/app'],
tags: [ tags: [
`type=match,"pattern=\\d{1,3}.\\d{1,3}.\\d{1,3}"` `type=match,"pattern=\\d.\\d.\\d"`
] ]
} as Inputs, } as Inputs,
{ {
@@ -715,7 +775,7 @@ describe('tag', () => {
{ {
images: ['org/app', 'ghcr.io/user/app'], images: ['org/app', 'ghcr.io/user/app'],
tags: [ tags: [
`type=match,"pattern=^v(\\d{1,3}.\\d{1,3}.\\d{1,3})$",group=1` `type=match,"pattern=^v(\\d.\\d.\\d)$",group=1`
] ]
} as Inputs, } as Inputs,
{ {
@@ -746,7 +806,7 @@ describe('tag', () => {
{ {
images: ['org/app', 'ghcr.io/user/app'], images: ['org/app', 'ghcr.io/user/app'],
tags: [ tags: [
`type=match,"pattern=\\d{1,3}.\\d{1,3}.\\d{1,3}-(alpha|beta).\\d{1,3}"` `type=match,"pattern=\\d.\\d.\\d-(alpha|beta).\\d+"`
] ]
} as Inputs, } as Inputs,
{ {
@@ -777,7 +837,7 @@ describe('tag', () => {
{ {
images: ['org/app', 'ghcr.io/user/app'], images: ['org/app', 'ghcr.io/user/app'],
tags: [ tags: [
`type=match,"pattern=\\d{1,3}.\\d{1,3}"` `type=match,"pattern=\\d.\\d"`
] ]
} as Inputs, } as Inputs,
{ {
@@ -808,24 +868,29 @@ describe('tag', () => {
{ {
images: ['org/app', 'ghcr.io/user/app'], images: ['org/app', 'ghcr.io/user/app'],
tags: [ tags: [
`type=match,"pattern=/^v(\\d{1,3}.\\d{1,3}.\\d{1,3})$/ig",group=1`, `type=match,"pattern=v(.*)-beta.(.*)",group=1`,
`type=match,"pattern=v(.*)-beta.(.*)",group=2`,
] ]
} as Inputs, } as Inputs,
{ {
main: 'v2.0.8-beta.67', main: '2.0.8',
partial: [], partial: ['67'],
latest: false latest: true
} as Version, } as Version,
[ [
'org/app:v2.0.8-beta.67', 'org/app:2.0.8',
'ghcr.io/user/app:v2.0.8-beta.67' 'org/app:67',
'org/app:latest',
'ghcr.io/user/app:2.0.8',
'ghcr.io/user/app:67',
'ghcr.io/user/app:latest'
], ],
[ [
"org.opencontainers.image.title=Hello-World", "org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!", "org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=v2.0.8-beta.67", "org.opencontainers.image.version=2.0.8",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z", "org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071", "org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT" "org.opencontainers.image.licenses=MIT"
@@ -837,24 +902,21 @@ describe('tag', () => {
{ {
images: ['org/app', 'ghcr.io/user/app'], images: ['org/app', 'ghcr.io/user/app'],
tags: [ tags: [
`type=match,"pattern=\\d{1,3}.\\d{1,3}"` `type=match,"pattern=\\d.\\d"`
] ]
} as Inputs, } as Inputs,
{ {
main: 'sometag', main: undefined,
partial: [], partial: [],
latest: false latest: false
} as Version, } as Version,
[ [],
'org/app:sometag',
'ghcr.io/user/app:sometag'
],
[ [
"org.opencontainers.image.title=Hello-World", "org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!", "org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=sometag", "org.opencontainers.image.version=",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z", "org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071", "org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT" "org.opencontainers.image.licenses=MIT"
@@ -1001,7 +1063,7 @@ describe('tag', () => {
tags: [ tags: [
`type=raw,priority=2000,foo`, `type=raw,priority=2000,foo`,
`type=semver,pattern={{version}}`, `type=semver,pattern={{version}}`,
`type=match,"pattern=\\d{1,3}.\\d{1,3}"` `type=match,"pattern=\\d.\\d"`
] ]
} as Inputs, } as Inputs,
{ {
@@ -1060,6 +1122,154 @@ describe('tag', () => {
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071", "org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT" "org.opencontainers.image.licenses=MIT"
] ]
],
[
'tag17',
'event_tag_p1-v1.0.0.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,"pattern=/^v(\\d.\\d.\\d)$/ig",group=1`,
`type=match,pattern=\\d.\\d.\\d`,
`type=match,pattern=\\d.\\d`,
`type=ref,event=pr`,
`type=sha`
]
} as Inputs,
{
main: '1.0.0',
partial: ['1.0', 'sha-90dd603'],
latest: true
} as Version,
[
'org/app:1.0.0',
'org/app:1.0',
'org/app:sha-90dd603',
'org/app:latest',
'ghcr.io/user/app:1.0.0',
'ghcr.io/user/app:1.0',
'ghcr.io/user/app:sha-90dd603',
'ghcr.io/user/app:latest'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=1.0.0",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'tag18',
'event_tag_p1-v1.0.0.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,pattern=p1-v(\\d.\\d.\\d),group=1`,
`type=match,pattern=p1-v(\\d.\\d),group=1`,
`type=match,pattern=p1-v(\\d.\\d),group=3`,
`type=ref,event=pr`,
`type=sha`
]
} as Inputs,
{
main: '1.0.0',
partial: ['1.0', 'sha-90dd603'],
latest: true
} as Version,
[
'org/app:1.0.0',
'org/app:1.0',
'org/app:sha-90dd603',
'org/app:latest',
'ghcr.io/user/app:1.0.0',
'ghcr.io/user/app:1.0',
'ghcr.io/user/app:sha-90dd603',
'ghcr.io/user/app:latest'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=1.0.0",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'tag19',
'event_tag_p1-v1.0.0.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,pattern=p1-v(\\d.\\d.\\d),group=1`,
`type=match,pattern=p1-v(\\d.\\d),group=1,suffix=`,
`type=ref,event=pr`,
`type=sha`
],
flavor: [
`suffix=-dev`
]
} as Inputs,
{
main: '1.0.0-dev',
partial: ['1.0', 'sha-90dd603-dev'],
latest: true
} as Version,
[
'org/app:1.0.0-dev',
'org/app:1.0',
'org/app:sha-90dd603-dev',
'org/app:latest',
'ghcr.io/user/app:1.0.0-dev',
'ghcr.io/user/app:1.0',
'ghcr.io/user/app:sha-90dd603-dev',
'ghcr.io/user/app:latest'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=1.0.0-dev",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'tag20',
'event_tag_v1.1.1.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=raw,{{tag}}-{{sha}}-foo`
]
} as Inputs,
{
main: 'v1.1.1-90dd603-foo',
partial: [],
latest: false
} as Version,
[
'org/app:v1.1.1-90dd603-foo',
'ghcr.io/user/app:v1.1.1-90dd603-foo'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=v1.1.1-90dd603-foo",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
] ]
])('given %p with %p event', tagsLabelsTest); ])('given %p with %p event', tagsLabelsTest);
}); });
@@ -1160,7 +1370,7 @@ describe('latest', () => {
{ {
images: ['user/app'], images: ['user/app'],
tags: [ tags: [
`type=match,"pattern=\\d{1,3}.\\d{1,3}.\\d{1,3}"` `type=match,"pattern=\\d.\\d.\\d"`
] ]
} as Inputs, } as Inputs,
{ {
@@ -1217,7 +1427,7 @@ describe('latest', () => {
{ {
images: ['org/app', 'ghcr.io/user/app'], images: ['org/app', 'ghcr.io/user/app'],
tags: [ tags: [
`type=match,"pattern=\\d{1,3}.\\d{1,3}.\\d{1,3}"` `type=match,"pattern=\\d.\\d.\\d"`
] ]
} as Inputs, } as Inputs,
{ {
@@ -1469,6 +1679,72 @@ describe('pr', () => {
"org.opencontainers.image.licenses=MIT" "org.opencontainers.image.licenses=MIT"
] ]
], ],
[
'pr05',
'event_pull_request.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=ref,event=pr`
],
flavor: [
`prefix=glo-`,
`suffix=-bal`
]
} as Inputs,
{
main: 'pr-2-bal',
partial: [],
latest: false
} as Version,
[
'org/app:pr-2-bal',
'ghcr.io/user/app:pr-2-bal'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=pr-2-bal",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=1e9249f05bfc090e0688b8fb9c1b347586add504",
"org.opencontainers.image.licenses=MIT"
]
],
[
'pr06',
'event_pull_request.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=ref,event=pr,prefix=`
],
flavor: [
`prefix=glo-`,
`suffix=-bal`
]
} as Inputs,
{
main: '2-bal',
partial: [],
latest: false
} as Version,
[
'org/app:2-bal',
'ghcr.io/user/app:2-bal'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=2-bal",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=1e9249f05bfc090e0688b8fb9c1b347586add504",
"org.opencontainers.image.licenses=MIT"
]
]
])('given %p with %p event', tagsLabelsTest); ])('given %p with %p event', tagsLabelsTest);
}); });
@@ -1649,6 +1925,39 @@ describe('schedule', () => {
"org.opencontainers.image.licenses=MIT" "org.opencontainers.image.licenses=MIT"
] ]
], ],
[
'schedule07',
'event_schedule.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=schedule`,
],
flavor: [
`prefix=glo-`,
`suffix=-bal`
]
} as Inputs,
{
main: 'glo-nightly-bal',
partial: [],
latest: false
} as Version,
[
'org/app:glo-nightly-bal',
'ghcr.io/user/app:glo-nightly-bal'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=glo-nightly-bal",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
])('given %p with %p event', tagsLabelsTest); ])('given %p with %p event', tagsLabelsTest);
}); });
@@ -2143,11 +2452,12 @@ describe('bake', () => {
`type=raw,my`, `type=raw,my`,
`type=raw,custom`, `type=raw,custom`,
`type=raw,tags` `type=raw,tags`
] ],
bakeTarget: "meta"
} as Inputs, } as Inputs,
{ {
"target": { "target": {
"ghaction-docker-meta": { "meta": {
"tags": [ "tags": [
"user/app:release1", "user/app:release1",
"user/app:my", "user/app:my",
@@ -2358,40 +2668,3 @@ describe('bake', () => {
expect(JSON.parse(fs.readFileSync(bakeFile, 'utf8'))).toEqual(exBakeDefinition); expect(JSON.parse(fs.readFileSync(bakeFile, 'utf8'))).toEqual(exBakeDefinition);
}); });
}); });
describe('push', () => {
// prettier-ignore
test.each([
[
'push15',
'event_push_defbranch.env',
{
images: ['user/app'],
tags: [
`type=match,pattern=v(.*),group=1,value=v1.2.3`,
`type=edge`
],
} as Inputs,
{
main: '1.2.3',
partial: ['edge'],
latest: true
} as Version,
[
'user/app:1.2.3',
'user/app:edge',
'user/app:latest'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=1.2.3",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
]
])('given %p with %p event', tagsLabelsTest);
});

View File

@@ -13,7 +13,7 @@ describe('transform', () => {
`type=raw,foo`, `type=raw,foo`,
`type=edge`, `type=edge`,
`type=semver,pattern={{version}}`, `type=semver,pattern={{version}}`,
`type=match,"pattern=\\d{1,3}.\\d{1,3}.\\d{1,3}"` `type=match,"pattern=\\d.\\d.\\d",group=0`
], ],
[ [
{ {
@@ -21,8 +21,6 @@ describe('transform', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Schedule], "priority": DefaultPriorities[Type.Schedule],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"pattern": "nightly" "pattern": "nightly"
} }
}, },
@@ -31,8 +29,6 @@ describe('transform', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Semver], "priority": DefaultPriorities[Type.Semver],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{version}}", "pattern": "{{version}}",
"value": "" "value": ""
} }
@@ -42,9 +38,7 @@ describe('transform', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Match], "priority": DefaultPriorities[Type.Match],
"enable": "true", "enable": "true",
"prefix": "", "pattern": "\\d.\\d.\\d",
"suffix": "",
"pattern": "\\d{1,3}.\\d{1,3}.\\d{1,3}",
"group": "0", "group": "0",
"value": "" "value": ""
} }
@@ -54,8 +48,6 @@ describe('transform', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Edge], "priority": DefaultPriorities[Type.Edge],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"branch": "" "branch": ""
} }
}, },
@@ -64,8 +56,6 @@ describe('transform', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Ref], "priority": DefaultPriorities[Type.Ref],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"event": RefEvent.Branch "event": RefEvent.Branch
} }
}, },
@@ -74,8 +64,6 @@ describe('transform', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Ref], "priority": DefaultPriorities[Type.Ref],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"event": RefEvent.Tag "event": RefEvent.Tag
} }
}, },
@@ -85,7 +73,6 @@ describe('transform', () => {
"priority": DefaultPriorities[Type.Ref], "priority": DefaultPriorities[Type.Ref],
"enable": "true", "enable": "true",
"prefix": "pr-", "prefix": "pr-",
"suffix": "",
"event": RefEvent.PR "event": RefEvent.PR
} }
}, },
@@ -94,8 +81,6 @@ describe('transform', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Raw], "priority": DefaultPriorities[Type.Raw],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"value": "foo" "value": "foo"
} }
}, },
@@ -104,8 +89,7 @@ describe('transform', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Sha], "priority": DefaultPriorities[Type.Sha],
"enable": "true", "enable": "true",
"prefix": "sha-", "prefix": "sha-"
"suffix": ""
} }
} }
] as Tag[], ] as Tag[],
@@ -135,8 +119,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Schedule], "priority": DefaultPriorities[Type.Schedule],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{date 'YYYYMMDD'}}" "pattern": "{{date 'YYYYMMDD'}}"
} }
} as Tag, } as Tag,
@@ -149,8 +131,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Semver], "priority": DefaultPriorities[Type.Semver],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{version}}", "pattern": "{{version}}",
"value": "" "value": ""
} }
@@ -164,8 +144,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": "1", "priority": "1",
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{version}}", "pattern": "{{version}}",
"value": "" "value": ""
} }
@@ -179,8 +157,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": "1", "priority": "1",
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{version}}", "pattern": "{{version}}",
"value": "v1.0.0" "value": "v1.0.0"
} }
@@ -194,8 +170,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Match], "priority": DefaultPriorities[Type.Match],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"pattern": "v(.*)", "pattern": "v(.*)",
"group": "1", "group": "1",
"value": "" "value": ""
@@ -204,15 +178,13 @@ describe('parse', () => {
false false
], ],
[ [
`type=match,enable=true,"pattern=^v(\\d{1,3}.\\d{1,3}.\\d{1,3})$",group=1`, `type=match,enable=true,"pattern=^v(\\d.\\d.\\d)$",group=1`,
{ {
type: Type.Match, type: Type.Match,
attrs: { attrs: {
"priority": DefaultPriorities[Type.Match], "priority": DefaultPriorities[Type.Match],
"enable": "true", "enable": "true",
"prefix": "", "pattern": "^v(\\d.\\d.\\d)$",
"suffix": "",
"pattern": "^v(\\d{1,3}.\\d{1,3}.\\d{1,3})$",
"group": "1", "group": "1",
"value": "" "value": ""
} }
@@ -226,8 +198,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": "700", "priority": "700",
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"pattern": "v(.*)", "pattern": "v(.*)",
"group": "1", "group": "1",
"value": "" "value": ""
@@ -242,8 +212,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Match], "priority": DefaultPriorities[Type.Match],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"pattern": "v(.*)", "pattern": "v(.*)",
"group": "1", "group": "1",
"value": "v1.2.3" "value": "v1.2.3"
@@ -263,8 +231,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Edge], "priority": DefaultPriorities[Type.Edge],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"branch": "" "branch": ""
} }
} as Tag, } as Tag,
@@ -277,8 +243,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Edge], "priority": DefaultPriorities[Type.Edge],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"branch": "master" "branch": "master"
} }
} as Tag, } as Tag,
@@ -291,8 +255,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Ref], "priority": DefaultPriorities[Type.Ref],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"event": RefEvent.Tag "event": RefEvent.Tag
} }
} as Tag, } as Tag,
@@ -305,8 +267,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Ref], "priority": DefaultPriorities[Type.Ref],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"event": RefEvent.Branch "event": RefEvent.Branch
} }
} as Tag, } as Tag,
@@ -320,7 +280,6 @@ describe('parse', () => {
"priority": DefaultPriorities[Type.Ref], "priority": DefaultPriorities[Type.Ref],
"enable": "true", "enable": "true",
"prefix": "pr-", "prefix": "pr-",
"suffix": "",
"event": RefEvent.PR "event": RefEvent.PR
} }
} as Tag, } as Tag,
@@ -343,8 +302,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Raw], "priority": DefaultPriorities[Type.Raw],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"value": "acustomtag" "value": "acustomtag"
} }
} as Tag, } as Tag,
@@ -362,8 +319,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Raw], "priority": DefaultPriorities[Type.Raw],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"value": "acustomtag2" "value": "acustomtag2"
} }
} as Tag, } as Tag,
@@ -376,8 +331,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Raw], "priority": DefaultPriorities[Type.Raw],
"enable": "true", "enable": "true",
"prefix": "",
"suffix": "",
"value": "acustomtag4" "value": "acustomtag4"
} }
} as Tag, } as Tag,
@@ -390,8 +343,6 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Raw], "priority": DefaultPriorities[Type.Raw],
"enable": "false", "enable": "false",
"prefix": "",
"suffix": "",
"value": "acustomtag5" "value": "acustomtag5"
} }
} as Tag, } as Tag,
@@ -404,8 +355,7 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Sha], "priority": DefaultPriorities[Type.Sha],
"enable": "true", "enable": "true",
"prefix": "sha-", "prefix": "sha-"
"suffix": ""
} }
} as Tag, } as Tag,
false false
@@ -417,8 +367,7 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Sha], "priority": DefaultPriorities[Type.Sha],
"enable": "true", "enable": "true",
"prefix": "", "prefix": ""
"suffix": ""
} }
} as Tag, } as Tag,
false false
@@ -430,8 +379,7 @@ describe('parse', () => {
attrs: { attrs: {
"priority": DefaultPriorities[Type.Sha], "priority": DefaultPriorities[Type.Sha],
"enable": "false", "enable": "false",
"prefix": "sha-", "prefix": "sha-"
"suffix": ""
} }
} as Tag, } as Tag,
false false

View File

@@ -25,6 +25,9 @@ inputs:
sep-labels: sep-labels:
description: 'Separator to use for labels output (default \n)' description: 'Separator to use for labels output (default \n)'
required: false required: false
bake-target:
description: 'Bake target name (default ghaction-docker-meta)'
required: false
github-token: github-token:
description: 'GitHub Token as provided by secrets' description: 'GitHub Token as provided by secrets'
default: ${{ github.token }} default: ${{ github.token }}

281
dist/index.js generated vendored
View File

@@ -39,9 +39,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.asyncForEach = exports.getInputList = exports.getInputs = exports.tmpDir = void 0; exports.setOutput = exports.asyncForEach = exports.getInputList = exports.getInputs = exports.tmpDir = void 0;
const sync_1 = __importDefault(__webpack_require__(8750)); const sync_1 = __importDefault(__webpack_require__(8750));
const core = __importStar(__webpack_require__(2186)); const core = __importStar(__webpack_require__(2186));
const command_1 = __webpack_require__(7351);
const fs = __importStar(__webpack_require__(5747)); const fs = __importStar(__webpack_require__(5747));
const os = __importStar(__webpack_require__(2087)); const os = __importStar(__webpack_require__(2087));
const path = __importStar(__webpack_require__(5622)); const path = __importStar(__webpack_require__(5622));
@@ -61,6 +62,7 @@ function getInputs() {
labels: getInputList('labels', true), labels: getInputList('labels', true),
sepTags: core.getInput('sep-tags') || `\n`, sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`, sepLabels: core.getInput('sep-labels') || `\n`,
bakeTarget: core.getInput('bake-target') || `ghaction-docker-meta`,
githubToken: core.getInput('github-token') githubToken: core.getInput('github-token')
}; };
} }
@@ -94,17 +96,42 @@ exports.asyncForEach = (array, callback) => __awaiter(void 0, void 0, void 0, fu
yield callback(array[index], index, array); yield callback(array[index], index, array);
} }
}); });
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
function setOutput(name, value) {
command_1.issueCommand('set-output', { name }, value);
}
exports.setOutput = setOutput;
//# sourceMappingURL=context.js.map //# sourceMappingURL=context.js.map
/***/ }), /***/ }),
/***/ 3716: /***/ 3716:
/***/ ((__unused_webpack_module, exports) => { /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict"; "use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Transform = void 0; exports.Transform = void 0;
const core = __importStar(__webpack_require__(2186));
function Transform(inputs) { function Transform(inputs) {
const flavor = { const flavor = {
latest: 'auto', latest: 'auto',
@@ -137,6 +164,11 @@ function Transform(inputs) {
} }
} }
} }
core.startGroup(`Processing flavor input`);
core.info(`latest=${flavor.latest}`);
core.info(`prefix=${flavor.prefix}`);
core.info(`suffix=${flavor.suffix}`);
core.endGroup();
return flavor; return flavor;
} }
exports.Transform = Transform; exports.Transform = Transform;
@@ -267,7 +299,7 @@ function run() {
core.info(version.main || ''); core.info(version.main || '');
core.endGroup(); core.endGroup();
} }
core.setOutput('version', version.main || ''); context_1.setOutput('version', version.main || '');
// Docker tags // Docker tags
const tags = meta.getTags(); const tags = meta.getTags();
if (tags.length == 0) { if (tags.length == 0) {
@@ -280,7 +312,7 @@ function run() {
} }
core.endGroup(); core.endGroup();
} }
core.setOutput('tags', tags.join(inputs.sepTags)); context_1.setOutput('tags', tags.join(inputs.sepTags));
// Docker labels // Docker labels
const labels = meta.getLabels(); const labels = meta.getLabels();
core.startGroup(`Docker labels`); core.startGroup(`Docker labels`);
@@ -288,13 +320,13 @@ function run() {
core.info(label); core.info(label);
} }
core.endGroup(); core.endGroup();
core.setOutput('labels', labels.join(inputs.sepLabels)); context_1.setOutput('labels', labels.join(inputs.sepLabels));
// Bake definition file // Bake definition file
const bakeFile = meta.getBakeFile(); const bakeFile = meta.getBakeFile();
core.startGroup(`Bake definition file`); core.startGroup(`Bake definition file`);
core.info(fs.readFileSync(bakeFile, 'utf8')); core.info(fs.readFileSync(bakeFile, 'utf8'));
core.endGroup(); core.endGroup();
core.setOutput('bake-file', bakeFile); context_1.setOutput('bake-file', bakeFile);
} }
catch (error) { catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
@@ -361,7 +393,7 @@ class Meta {
latest: undefined latest: undefined
}; };
for (const tag of this.tags) { for (const tag of this.tags) {
if (tag.attrs['enable'] == 'false') { if (!/true/i.test(tag.attrs['enable'])) {
continue; continue;
} }
switch (tag.type) { switch (tag.type) {
@@ -414,21 +446,12 @@ class Meta {
return version; return version;
} }
const currentDate = this.date; const currentDate = this.date;
const vraw = handlebars.compile(tag.attrs['pattern'])({ const vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])({
date: function (format) { date: function (format) {
return moment_1.default(currentDate).utc().format(format); return moment_1.default(currentDate).utc().format(format);
} }
}); }), tag);
if (version.main == undefined) { return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
version.main = vraw;
}
else if (vraw !== version.main) {
version.partial.push(vraw);
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
}
return version;
} }
procSemver(version, tag) { procSemver(version, tag) {
if (!/^refs\/tags\//.test(this.context.ref) && tag.attrs['value'].length == 0) { if (!/^refs\/tags\//.test(this.context.ref) && tag.attrs['value'].length == 0) {
@@ -436,7 +459,7 @@ class Meta {
} }
let vraw; let vraw;
if (tag.attrs['value'].length > 0) { if (tag.attrs['value'].length > 0) {
vraw = tag.attrs['value']; vraw = this.setGlobalExp(tag.attrs['value']);
} }
else { else {
vraw = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'); vraw = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
@@ -450,28 +473,13 @@ class Meta {
includePrerelease: true includePrerelease: true
}); });
if (semver.prerelease(vraw)) { if (semver.prerelease(vraw)) {
vraw = handlebars.compile('{{version}}')(sver); vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
if (version.main == undefined) {
version.main = vraw;
}
else if (vraw !== version.main) {
version.partial.push(vraw);
}
} }
else { else {
vraw = handlebars.compile(tag.attrs['pattern'])(sver); vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
if (version.main == undefined) {
version.main = vraw;
}
else if (vraw !== version.main) {
version.partial.push(vraw);
}
latest = true; latest = true;
} }
if (version.latest == undefined) { return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true');
version.latest = this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true';
}
return version;
} }
procMatch(version, tag) { procMatch(version, tag) {
if (!/^refs\/tags\//.test(this.context.ref) && tag.attrs['value'].length == 0) { if (!/^refs\/tags\//.test(this.context.ref) && tag.attrs['value'].length == 0) {
@@ -479,7 +487,7 @@ class Meta {
} }
let vraw; let vraw;
if (tag.attrs['value'].length > 0) { if (tag.attrs['value'].length > 0) {
vraw = tag.attrs['value']; vraw = this.setGlobalExp(tag.attrs['value']);
} }
else { else {
vraw = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'); vraw = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
@@ -493,68 +501,37 @@ class Meta {
else { else {
tmatch = vraw.match(tag.attrs['pattern']); tmatch = vraw.match(tag.attrs['pattern']);
} }
if (tmatch) { if (!tmatch) {
vraw = tmatch[tag.attrs['group']]; core.warning(`${tag.attrs['pattern']} does not match ${vraw}.`);
latest = true; return version;
} }
if (version.main == undefined) { if (typeof tmatch[tag.attrs['group']] === 'undefined') {
version.main = vraw; core.warning(`Group ${tag.attrs['group']} does not exist for ${tag.attrs['pattern']} pattern.`);
return version;
} }
else if (vraw !== version.main) { vraw = this.setValue(tmatch[tag.attrs['group']], tag);
version.partial.push(vraw); return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? true : this.flavor.latest == 'true');
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true';
}
return version;
} }
procRefBranch(version, tag) { procRefBranch(version, tag) {
if (!/^refs\/heads\//.test(this.context.ref)) { if (!/^refs\/heads\//.test(this.context.ref)) {
return version; return version;
} }
const vraw = this.setFlavor(this.context.ref.replace(/^refs\/heads\//g, '').replace(/[^a-zA-Z0-9._-]+/g, '-'), tag); const vraw = this.setValue(this.context.ref.replace(/^refs\/heads\//g, '').replace(/[^a-zA-Z0-9._-]+/g, '-'), tag);
if (version.main == undefined) { return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
version.main = vraw;
}
else if (vraw !== version.main) {
version.partial.push(vraw);
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
}
return version;
} }
procRefTag(version, tag) { procRefTag(version, tag) {
if (!/^refs\/tags\//.test(this.context.ref)) { if (!/^refs\/tags\//.test(this.context.ref)) {
return version; return version;
} }
const vraw = this.setFlavor(this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'), tag); const vraw = this.setValue(this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'), tag);
if (version.main == undefined) { return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? true : this.flavor.latest == 'true');
version.main = vraw;
}
else if (vraw !== version.main) {
version.partial.push(vraw);
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? true : this.flavor.latest == 'true';
}
return version;
} }
procRefPr(version, tag) { procRefPr(version, tag) {
if (!/^refs\/pull\//.test(this.context.ref)) { if (!/^refs\/pull\//.test(this.context.ref)) {
return version; return version;
} }
const vraw = this.setFlavor(this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag); const vraw = this.setValue(this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag);
if (version.main == undefined) { return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
version.main = vraw;
}
else if (vraw !== version.main) {
version.partial.push(vraw);
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
}
return version;
} }
procEdge(version, tag) { procEdge(version, tag) {
if (!/^refs\/heads\//.test(this.context.ref)) { if (!/^refs\/heads\//.test(this.context.ref)) {
@@ -567,62 +544,70 @@ class Meta {
if (tag.attrs['branch'] === val) { if (tag.attrs['branch'] === val) {
val = 'edge'; val = 'edge';
} }
const vraw = this.setFlavor(val, tag); const vraw = this.setValue(val, tag);
if (version.main == undefined) { return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
version.main = vraw;
}
else if (vraw !== version.main) {
version.partial.push(vraw);
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
}
return version;
} }
procRaw(version, tag) { procRaw(version, tag) {
const vraw = this.setFlavor(tag.attrs['value'], tag); const vraw = this.setValue(this.setGlobalExp(tag.attrs['value']), tag);
if (version.main == undefined) { return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
version.main = vraw;
}
else if (vraw !== version.main) {
version.partial.push(vraw);
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
}
return version;
} }
procSha(version, tag) { procSha(version, tag) {
if (!this.context.sha) { if (!this.context.sha) {
return version; return version;
} }
const vraw = this.setFlavor(this.context.sha.substr(0, 7), tag); const vraw = this.setValue(this.context.sha.substr(0, 7), tag);
if (version.main == undefined) { return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
version.main = vraw; }
static setVersion(version, val, latest) {
if (val.length == 0) {
return version;
} }
else if (vraw !== version.main) { if (version.main == undefined) {
version.partial.push(vraw); version.main = val;
}
else if (val !== version.main) {
version.partial.push(val);
} }
if (version.latest == undefined) { if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true'; version.latest = latest;
} }
return version; return version;
} }
setFlavor(val, tag) { setValue(val, tag) {
if (tag.attrs['prefix'].length > 0) { if (tag.attrs.hasOwnProperty('prefix')) {
val = `${tag.attrs['prefix']}${val}`; val = `${this.setGlobalExp(tag.attrs['prefix'])}${val}`;
} }
else if (this.flavor.prefix.length > 0) { else if (this.flavor.prefix.length > 0) {
val = `${this.flavor.prefix}${val}`; val = `${this.setGlobalExp(this.flavor.prefix)}${val}`;
} }
if (tag.attrs['suffix'].length > 0) { if (tag.attrs.hasOwnProperty('suffix')) {
val = `${val}${tag.attrs['suffix']}`; val = `${val}${this.setGlobalExp(tag.attrs['suffix'])}`;
} }
else if (this.flavor.suffix.length > 0) { else if (this.flavor.suffix.length > 0) {
val = `${val}${this.flavor.suffix}`; val = `${val}${this.setGlobalExp(this.flavor.suffix)}`;
} }
return val; return val;
} }
setGlobalExp(val) {
const ctx = this.context;
return handlebars.compile(val)({
branch: function () {
if (!/^refs\/heads\//.test(ctx.ref)) {
return '';
}
return ctx.ref.replace(/^refs\/heads\//g, '').replace(/[^a-zA-Z0-9._-]+/g, '-');
},
tag: function () {
if (!/^refs\/tags\//.test(ctx.ref)) {
return '';
}
return ctx.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
},
sha: function () {
return ctx.sha.substr(0, 7);
}
});
}
getTags() { getTags() {
if (!this.version.main) { if (!this.version.main) {
return []; return [];
@@ -667,7 +652,7 @@ class Meta {
const bakeFile = path.join(context_1.tmpDir(), 'ghaction-docker-meta-bake.json').split(path.sep).join(path.posix.sep); const bakeFile = path.join(context_1.tmpDir(), 'ghaction-docker-meta-bake.json').split(path.sep).join(path.posix.sep);
fs.writeFileSync(bakeFile, JSON.stringify({ fs.writeFileSync(bakeFile, JSON.stringify({
target: { target: {
'ghaction-docker-meta': { [this.inputs.bakeTarget]: {
tags: this.getTags(), tags: this.getTags(),
labels: jsonLabels, labels: jsonLabels,
args: { args: {
@@ -690,12 +675,32 @@ exports.Meta = Meta;
"use strict"; "use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) { var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Parse = exports.Transform = exports.DefaultPriorities = exports.RefEvent = exports.Type = void 0; exports.Parse = exports.Transform = exports.DefaultPriorities = exports.Tag = exports.RefEvent = exports.Type = void 0;
const sync_1 = __importDefault(__webpack_require__(8750)); const sync_1 = __importDefault(__webpack_require__(8750));
const core = __importStar(__webpack_require__(2186));
var Type; var Type;
(function (Type) { (function (Type) {
Type["Schedule"] = "schedule"; Type["Schedule"] = "schedule";
@@ -712,6 +717,19 @@ var RefEvent;
RefEvent["Tag"] = "tag"; RefEvent["Tag"] = "tag";
RefEvent["PR"] = "pr"; RefEvent["PR"] = "pr";
})(RefEvent = exports.RefEvent || (exports.RefEvent = {})); })(RefEvent = exports.RefEvent || (exports.RefEvent = {}));
class Tag {
constructor() {
this.attrs = {};
}
toString() {
const out = [`type=${this.type}`];
for (let attr in this.attrs) {
out.push(`${attr}=${this.attrs[attr]}`);
}
return out.join(',');
}
}
exports.Tag = Tag;
exports.DefaultPriorities = { exports.DefaultPriorities = {
[Type.Schedule]: '1000', [Type.Schedule]: '1000',
[Type.Semver]: '900', [Type.Semver]: '900',
@@ -735,7 +753,7 @@ function Transform(inputs) {
for (const input of inputs) { for (const input of inputs) {
tags.push(Parse(input)); tags.push(Parse(input));
} }
return tags.sort((tag1, tag2) => { const sorted = tags.sort((tag1, tag2) => {
if (Number(tag1.attrs['priority']) < Number(tag2.attrs['priority'])) { if (Number(tag1.attrs['priority']) < Number(tag2.attrs['priority'])) {
return 1; return 1;
} }
@@ -744,6 +762,12 @@ function Transform(inputs) {
} }
return 0; return 0;
}); });
core.startGroup(`Processing tags input`);
for (const tag of sorted) {
core.info(tag.toString());
}
core.endGroup();
return sorted;
} }
exports.Transform = Transform; exports.Transform = Transform;
function Parse(s) { function Parse(s) {
@@ -751,9 +775,7 @@ function Parse(s) {
relaxColumnCount: true, relaxColumnCount: true,
skipLinesWithEmptyValues: true skipLinesWithEmptyValues: true
})[0]; })[0];
const tag = { const tag = new Tag();
attrs: {}
};
for (const field of fields) { for (const field of fields) {
const parts = field.toString().split('=', 2); const parts = field.toString().split('=', 2);
if (parts.length == 1) { if (parts.length == 1) {
@@ -850,12 +872,6 @@ function Parse(s) {
if (!tag.attrs.hasOwnProperty('priority')) { if (!tag.attrs.hasOwnProperty('priority')) {
tag.attrs['priority'] = exports.DefaultPriorities[tag.type]; tag.attrs['priority'] = exports.DefaultPriorities[tag.type];
} }
if (!tag.attrs.hasOwnProperty('prefix')) {
tag.attrs['prefix'] = '';
}
if (!tag.attrs.hasOwnProperty('suffix')) {
tag.attrs['suffix'] = '';
}
if (!['true', 'false'].includes(tag.attrs['enable'])) { if (!['true', 'false'].includes(tag.attrs['enable'])) {
throw new Error(`Invalid value for enable attribute: ${tag.attrs['enable']}`); throw new Error(`Invalid value for enable attribute: ${tag.attrs['enable']}`);
} }
@@ -1062,6 +1078,7 @@ exports.getInput = getInput;
*/ */
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
function setOutput(name, value) { function setOutput(name, value) {
process.stdout.write(os.EOL);
command_1.issueCommand('set-output', { name }, value); command_1.issueCommand('set-output', { name }, value);
} }
exports.setOutput = setOutput; exports.setOutput = setOutput;
@@ -5463,7 +5480,7 @@ class Parser extends Transform {
for(let i = 0, l = record.length; i < l; i++){ for(let i = 0, l = record.length; i < l; i++){
if(columns[i] === undefined || columns[i].disabled) continue if(columns[i] === undefined || columns[i].disabled) continue
// Turn duplicate columns into an array // Turn duplicate columns into an array
if (columns_duplicates_to_array === true && obj[columns[i].name]) { if (columns_duplicates_to_array === true && obj[columns[i].name] !== undefined) {
if (Array.isArray(obj[columns[i].name])) { if (Array.isArray(obj[columns[i].name])) {
obj[columns[i].name] = obj[columns[i].name].concat(record[i]) obj[columns[i].name] = obj[columns[i].name].concat(record[i])
} else { } else {

View File

@@ -23,9 +23,9 @@
"author": "CrazyMax", "author": "CrazyMax",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6", "@actions/core": "^1.2.7",
"@actions/github": "^4.0.0", "@actions/github": "^4.0.0",
"csv-parse": "^4.15.3", "csv-parse": "^4.15.4",
"handlebars": "^4.7.7", "handlebars": "^4.7.7",
"moment": "^2.29.1", "moment": "^2.29.1",
"semver": "^7.3.5" "semver": "^7.3.5"

View File

@@ -1,5 +1,6 @@
import csvparse from 'csv-parse/lib/sync'; import csvparse from 'csv-parse/lib/sync';
import * as core from '@actions/core'; import * as core from '@actions/core';
import {issueCommand} from '@actions/core/lib/command';
import * as fs from 'fs'; import * as fs from 'fs';
import * as os from 'os'; import * as os from 'os';
import * as path from 'path'; import * as path from 'path';
@@ -13,6 +14,7 @@ export interface Inputs {
labels: string[]; labels: string[];
sepTags: string; sepTags: string;
sepLabels: string; sepLabels: string;
bakeTarget: string;
githubToken: string; githubToken: string;
} }
@@ -31,6 +33,7 @@ export function getInputs(): Inputs {
labels: getInputList('labels', true), labels: getInputList('labels', true),
sepTags: core.getInput('sep-tags') || `\n`, sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`, sepLabels: core.getInput('sep-labels') || `\n`,
bakeTarget: core.getInput('bake-target') || `ghaction-docker-meta`,
githubToken: core.getInput('github-token') githubToken: core.getInput('github-token')
}; };
} }
@@ -66,3 +69,8 @@ export const asyncForEach = async (array, callback) => {
await callback(array[index], index, array); await callback(array[index], index, array);
} }
}; };
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
export function setOutput(name: string, value: any): void {
issueCommand('set-output', {name}, value);
}

View File

@@ -1,3 +1,5 @@
import * as core from '@actions/core';
export interface Flavor { export interface Flavor {
latest: string; latest: string;
prefix: string; prefix: string;
@@ -38,5 +40,11 @@ export function Transform(inputs: string[]): Flavor {
} }
} }
core.startGroup(`Processing flavor input`);
core.info(`latest=${flavor.latest}`);
core.info(`prefix=${flavor.prefix}`);
core.info(`suffix=${flavor.suffix}`);
core.endGroup();
return flavor; return flavor;
} }

View File

@@ -1,5 +1,5 @@
import * as fs from 'fs'; import * as fs from 'fs';
import {getInputs, Inputs} from './context'; import {getInputs, Inputs, setOutput} from './context';
import * as github from './github'; import * as github from './github';
import {Meta, Version} from './meta'; import {Meta, Version} from './meta';
import * as core from '@actions/core'; import * as core from '@actions/core';
@@ -36,7 +36,7 @@ async function run() {
core.info(version.main || ''); core.info(version.main || '');
core.endGroup(); core.endGroup();
} }
core.setOutput('version', version.main || ''); setOutput('version', version.main || '');
// Docker tags // Docker tags
const tags: Array<string> = meta.getTags(); const tags: Array<string> = meta.getTags();
@@ -49,7 +49,7 @@ async function run() {
} }
core.endGroup(); core.endGroup();
} }
core.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();
@@ -58,14 +58,14 @@ async function run() {
core.info(label); core.info(label);
} }
core.endGroup(); core.endGroup();
core.setOutput('labels', labels.join(inputs.sepLabels)); setOutput('labels', labels.join(inputs.sepLabels));
// Bake definition file // Bake definition file
const bakeFile: string = meta.getBakeFile(); const bakeFile: string = meta.getBakeFile();
core.startGroup(`Bake definition file`); core.startGroup(`Bake definition file`);
core.info(fs.readFileSync(bakeFile, 'utf8')); core.info(fs.readFileSync(bakeFile, 'utf8'));
core.endGroup(); core.endGroup();
core.setOutput('bake-file', bakeFile); setOutput('bake-file', bakeFile);
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }

View File

@@ -44,10 +44,9 @@ export class Meta {
}; };
for (const tag of this.tags) { for (const tag of this.tags) {
if (tag.attrs['enable'] == 'false') { if (!/true/i.test(tag.attrs['enable'])) {
continue; continue;
} }
switch (tag.type) { switch (tag.type) {
case tcl.Type.Schedule: { case tcl.Type.Schedule: {
version = this.procSchedule(version, tag); version = this.procSchedule(version, tag);
@@ -100,22 +99,16 @@ export class Meta {
} }
const currentDate = this.date; const currentDate = this.date;
const vraw = handlebars.compile(tag.attrs['pattern'])({ const vraw = this.setValue(
date: function (format) { handlebars.compile(tag.attrs['pattern'])({
return moment(currentDate).utc().format(format); date: function (format) {
} return moment(currentDate).utc().format(format);
}); }
}),
tag
);
if (version.main == undefined) { return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
version.main = vraw;
} else if (vraw !== version.main) {
version.partial.push(vraw);
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
}
return version;
} }
private procSemver(version: Version, tag: tcl.Tag): Version { private procSemver(version: Version, tag: tcl.Tag): Version {
@@ -125,7 +118,7 @@ export class Meta {
let vraw: string; let vraw: string;
if (tag.attrs['value'].length > 0) { if (tag.attrs['value'].length > 0) {
vraw = tag.attrs['value']; vraw = this.setGlobalExp(tag.attrs['value']);
} else { } else {
vraw = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'); vraw = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
} }
@@ -139,26 +132,13 @@ export class Meta {
includePrerelease: true includePrerelease: true
}); });
if (semver.prerelease(vraw)) { if (semver.prerelease(vraw)) {
vraw = handlebars.compile('{{version}}')(sver); vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
if (version.main == undefined) {
version.main = vraw;
} else if (vraw !== version.main) {
version.partial.push(vraw);
}
} else { } else {
vraw = handlebars.compile(tag.attrs['pattern'])(sver); vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
if (version.main == undefined) {
version.main = vraw;
} else if (vraw !== version.main) {
version.partial.push(vraw);
}
latest = true; latest = true;
} }
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true';
}
return version; return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true');
} }
private procMatch(version: Version, tag: tcl.Tag): Version { private procMatch(version: Version, tag: tcl.Tag): Version {
@@ -168,7 +148,7 @@ export class Meta {
let vraw: string; let vraw: string;
if (tag.attrs['value'].length > 0) { if (tag.attrs['value'].length > 0) {
vraw = tag.attrs['value']; vraw = this.setGlobalExp(tag.attrs['value']);
} else { } else {
vraw = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'); vraw = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
} }
@@ -181,75 +161,41 @@ export class Meta {
} else { } else {
tmatch = vraw.match(tag.attrs['pattern']); tmatch = vraw.match(tag.attrs['pattern']);
} }
if (tmatch) { if (!tmatch) {
vraw = tmatch[tag.attrs['group']]; core.warning(`${tag.attrs['pattern']} does not match ${vraw}.`);
latest = true; return version;
}
if (typeof tmatch[tag.attrs['group']] === 'undefined') {
core.warning(`Group ${tag.attrs['group']} does not exist for ${tag.attrs['pattern']} pattern.`);
return version;
} }
if (version.main == undefined) { vraw = this.setValue(tmatch[tag.attrs['group']], tag);
version.main = vraw; return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? true : this.flavor.latest == 'true');
} else if (vraw !== version.main) {
version.partial.push(vraw);
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true';
}
return version;
} }
private procRefBranch(version: Version, tag: tcl.Tag): Version { private procRefBranch(version: Version, tag: tcl.Tag): Version {
if (!/^refs\/heads\//.test(this.context.ref)) { if (!/^refs\/heads\//.test(this.context.ref)) {
return version; return version;
} }
const vraw = this.setValue(this.context.ref.replace(/^refs\/heads\//g, '').replace(/[^a-zA-Z0-9._-]+/g, '-'), tag);
const vraw = this.setFlavor(this.context.ref.replace(/^refs\/heads\//g, '').replace(/[^a-zA-Z0-9._-]+/g, '-'), tag); return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
if (version.main == undefined) {
version.main = vraw;
} else if (vraw !== version.main) {
version.partial.push(vraw);
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
}
return version;
} }
private procRefTag(version: Version, tag: tcl.Tag): Version { private procRefTag(version: Version, tag: tcl.Tag): Version {
if (!/^refs\/tags\//.test(this.context.ref)) { if (!/^refs\/tags\//.test(this.context.ref)) {
return version; return version;
} }
const vraw = this.setValue(this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'), tag);
const vraw = this.setFlavor(this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'), tag); return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? true : this.flavor.latest == 'true');
if (version.main == undefined) {
version.main = vraw;
} else if (vraw !== version.main) {
version.partial.push(vraw);
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? true : this.flavor.latest == 'true';
}
return version;
} }
private procRefPr(version: Version, tag: tcl.Tag): Version { private procRefPr(version: Version, tag: tcl.Tag): Version {
if (!/^refs\/pull\//.test(this.context.ref)) { if (!/^refs\/pull\//.test(this.context.ref)) {
return version; return version;
} }
const vraw = this.setValue(this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag);
const vraw = this.setFlavor(this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag); return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
if (version.main == undefined) {
version.main = vraw;
} else if (vraw !== version.main) {
version.partial.push(vraw);
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
}
return version;
} }
private procEdge(version: Version, tag: tcl.Tag): Version { private procEdge(version: Version, tag: tcl.Tag): Version {
@@ -265,65 +211,73 @@ export class Meta {
val = 'edge'; val = 'edge';
} }
const vraw = this.setFlavor(val, tag); const vraw = this.setValue(val, tag);
if (version.main == undefined) { return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
version.main = vraw;
} else if (vraw !== version.main) {
version.partial.push(vraw);
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
}
return version;
} }
private procRaw(version: Version, tag: tcl.Tag): Version { private procRaw(version: Version, tag: tcl.Tag): Version {
const vraw = this.setFlavor(tag.attrs['value'], tag); const vraw = this.setValue(this.setGlobalExp(tag.attrs['value']), tag);
if (version.main == undefined) { return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
version.main = vraw;
} else if (vraw !== version.main) {
version.partial.push(vraw);
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
}
return version;
} }
private procSha(version: Version, tag: tcl.Tag): Version { private procSha(version: Version, tag: tcl.Tag): Version {
if (!this.context.sha) { if (!this.context.sha) {
return version; return version;
} }
const vraw = this.setValue(this.context.sha.substr(0, 7), tag);
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
}
const vraw = this.setFlavor(this.context.sha.substr(0, 7), tag); private static setVersion(version: Version, val: string, latest: boolean): Version {
if (val.length == 0) {
return version;
}
if (version.main == undefined) { if (version.main == undefined) {
version.main = vraw; version.main = val;
} else if (vraw !== version.main) { } else if (val !== version.main) {
version.partial.push(vraw); version.partial.push(val);
} }
if (version.latest == undefined) { if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true'; version.latest = latest;
} }
return version; return version;
} }
private setFlavor(val: string, tag: tcl.Tag): string { private setValue(val: string, tag: tcl.Tag): string {
if (tag.attrs['prefix'].length > 0) { if (tag.attrs.hasOwnProperty('prefix')) {
val = `${tag.attrs['prefix']}${val}`; val = `${this.setGlobalExp(tag.attrs['prefix'])}${val}`;
} else if (this.flavor.prefix.length > 0) { } else if (this.flavor.prefix.length > 0) {
val = `${this.flavor.prefix}${val}`; val = `${this.setGlobalExp(this.flavor.prefix)}${val}`;
} }
if (tag.attrs['suffix'].length > 0) { if (tag.attrs.hasOwnProperty('suffix')) {
val = `${val}${tag.attrs['suffix']}`; val = `${val}${this.setGlobalExp(tag.attrs['suffix'])}`;
} else if (this.flavor.suffix.length > 0) { } else if (this.flavor.suffix.length > 0) {
val = `${val}${this.flavor.suffix}`; val = `${val}${this.setGlobalExp(this.flavor.suffix)}`;
} }
return val; return val;
} }
private setGlobalExp(val): string {
const ctx = this.context;
return handlebars.compile(val)({
branch: function () {
if (!/^refs\/heads\//.test(ctx.ref)) {
return '';
}
return ctx.ref.replace(/^refs\/heads\//g, '').replace(/[^a-zA-Z0-9._-]+/g, '-');
},
tag: function () {
if (!/^refs\/tags\//.test(ctx.ref)) {
return '';
}
return ctx.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
},
sha: function () {
return ctx.sha.substr(0, 7);
}
});
}
public getTags(): Array<string> { public getTags(): Array<string> {
if (!this.version.main) { if (!this.version.main) {
return []; return [];
@@ -374,7 +328,7 @@ export class Meta {
JSON.stringify( JSON.stringify(
{ {
target: { target: {
'ghaction-docker-meta': { [this.inputs.bakeTarget]: {
tags: this.getTags(), tags: this.getTags(),
labels: jsonLabels, labels: jsonLabels,
args: { args: {

View File

@@ -1,4 +1,5 @@
import csvparse from 'csv-parse/lib/sync'; import csvparse from 'csv-parse/lib/sync';
import * as core from '@actions/core';
export enum Type { export enum Type {
Schedule = 'schedule', Schedule = 'schedule',
@@ -16,9 +17,21 @@ export enum RefEvent {
PR = 'pr' PR = 'pr'
} }
export interface Tag { export class Tag {
type: Type; public type?: Type;
attrs: Record<string, string>; public attrs: Record<string, string>;
constructor() {
this.attrs = {};
}
public toString(): string {
const out: string[] = [`type=${this.type}`];
for (let attr in this.attrs) {
out.push(`${attr}=${this.attrs[attr]}`);
}
return out.join(',');
}
} }
export const DefaultPriorities: Record<Type, string> = { export const DefaultPriorities: Record<Type, string> = {
@@ -42,10 +55,11 @@ export function Transform(inputs: string[]): Tag[] {
`type=ref,event=${RefEvent.PR}` `type=ref,event=${RefEvent.PR}`
]; ];
} }
for (const input of inputs) { for (const input of inputs) {
tags.push(Parse(input)); tags.push(Parse(input));
} }
return tags.sort((tag1, tag2) => { const sorted = tags.sort((tag1, tag2) => {
if (Number(tag1.attrs['priority']) < Number(tag2.attrs['priority'])) { if (Number(tag1.attrs['priority']) < Number(tag2.attrs['priority'])) {
return 1; return 1;
} }
@@ -54,6 +68,14 @@ export function Transform(inputs: string[]): Tag[] {
} }
return 0; return 0;
}); });
core.startGroup(`Processing tags input`);
for (const tag of sorted) {
core.info(tag.toString());
}
core.endGroup();
return sorted;
} }
export function Parse(s: string): Tag { export function Parse(s: string): Tag {
@@ -62,10 +84,7 @@ export function Parse(s: string): Tag {
skipLinesWithEmptyValues: true skipLinesWithEmptyValues: true
})[0]; })[0];
const tag = { const tag = new Tag();
attrs: {}
} as Tag;
for (const field of fields) { for (const field of fields) {
const parts = field.toString().split('=', 2); const parts = field.toString().split('=', 2);
if (parts.length == 1) { if (parts.length == 1) {
@@ -166,12 +185,6 @@ export function Parse(s: string): Tag {
if (!tag.attrs.hasOwnProperty('priority')) { if (!tag.attrs.hasOwnProperty('priority')) {
tag.attrs['priority'] = DefaultPriorities[tag.type]; tag.attrs['priority'] = DefaultPriorities[tag.type];
} }
if (!tag.attrs.hasOwnProperty('prefix')) {
tag.attrs['prefix'] = '';
}
if (!tag.attrs.hasOwnProperty('suffix')) {
tag.attrs['suffix'] = '';
}
if (!['true', 'false'].includes(tag.attrs['enable'])) { if (!['true', 'false'].includes(tag.attrs['enable'])) {
throw new Error(`Invalid value for enable attribute: ${tag.attrs['enable']}`); throw new Error(`Invalid value for enable attribute: ${tag.attrs['enable']}`);
} }

View File

@@ -2,10 +2,10 @@
# yarn lockfile v1 # yarn lockfile v1
"@actions/core@^1.2.6": "@actions/core@^1.2.7":
version "1.2.6" version "1.2.7"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.6.tgz#a78d49f41a4def18e88ce47c2cac615d5694bf09" resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.7.tgz#594f8c45b213f0146e4be7eda8ae5cf4e198e5ab"
integrity sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA== integrity sha512-kzLFD5BgEvq6ubcxdgPbRKGD2Qrgya/5j+wh4LZzqT915I0V3rED+MvjH6NXghbvk1MXknpNNQ3uKjXSEN00Ig==
"@actions/github@^4.0.0": "@actions/github@^4.0.0":
version "4.0.0" version "4.0.0"
@@ -1176,10 +1176,10 @@ cssstyle@^2.2.0:
dependencies: dependencies:
cssom "~0.3.6" cssom "~0.3.6"
csv-parse@^4.15.3: csv-parse@^4.15.4:
version "4.15.3" version "4.15.4"
resolved "https://registry.yarnpkg.com/csv-parse/-/csv-parse-4.15.3.tgz#8a62759617a920c328cb31c351b05053b8f92b10" resolved "https://registry.yarnpkg.com/csv-parse/-/csv-parse-4.15.4.tgz#ad1ec62aaf71a642982dfcb81f1848184d691db5"
integrity sha512-jlTqDvLdHnYMSr08ynNfk4IAUSJgJjTKy2U5CQBSu4cN9vQOJonLVZP4Qo4gKKrIgIQ5dr07UwOJdi+lRqT12w== integrity sha512-OdBbFc0yZhOm17lSxqkirrHlFFVpKRT0wp4DAGoJelsP3LbGzV9LNr7XmM/lrr0uGkCtaqac9UhP8PDHXOAbMg==
dashdash@^1.12.0: dashdash@^1.12.0:
version "1.14.1" version "1.14.1"
@@ -1701,9 +1701,9 @@ has@^1.0.3:
function-bind "^1.1.1" function-bind "^1.1.1"
hosted-git-info@^2.1.4: hosted-git-info@^2.1.4:
version "2.8.8" version "2.8.9"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz#7539bd4bc1e0e0a895815a2e0262420b12858488" resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9"
integrity sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg== integrity sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==
html-encoding-sniffer@^2.0.1: html-encoding-sniffer@^2.0.1:
version "2.0.1" version "2.0.1"
@@ -2546,9 +2546,9 @@ lodash.sortby@^4.7.0:
integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg= integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=
lodash@^4.17.19: lodash@^4.17.19:
version "4.17.20" version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
lru-cache@^6.0.0: lru-cache@^6.0.0:
version "6.0.0" version "6.0.0"