Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b747b8aaa7 | ||
|
585ab8356c | ||
|
9de4428611 | ||
|
4c2760ba7a | ||
|
ef12c77b87 | ||
|
c53f88523a | ||
|
6b4bf4724e | ||
|
d48c7d2917 | ||
|
7cb65aaacb | ||
|
0dca12c226 | ||
|
6f270f37d4 | ||
|
2860e42b1f | ||
|
6a86fe1739 | ||
|
86dc87790d | ||
|
b3281c85e6 | ||
|
9ba75ef142 | ||
|
a017e545d7 |
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
@@ -82,10 +82,18 @@ jobs:
|
||||
|
||||
tag-semver:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
tag-latest:
|
||||
- 'true'
|
||||
- 'false'
|
||||
steps:
|
||||
- name: Checkout
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Docker meta
|
||||
-
|
||||
name: Docker meta
|
||||
uses: ./
|
||||
with:
|
||||
images: |
|
||||
@@ -95,6 +103,7 @@ jobs:
|
||||
{{raw}}
|
||||
{{version}}
|
||||
{{major}}.{{minor}}.{{patch}}
|
||||
tag-latest: ${{ matrix.tag-latest }}
|
||||
|
||||
docker-push:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -114,7 +123,10 @@ jobs:
|
||||
with:
|
||||
images: ${{ env.DOCKER_IMAGE }}
|
||||
tag-sha: true
|
||||
tag-match: '\d{1,3}.\d{1,3}.\d{1,3}'
|
||||
tag-semver: |
|
||||
v{{version}}
|
||||
v{{major}}.{{minor}}
|
||||
v{{major}}
|
||||
-
|
||||
name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
|
23
CHANGELOG.md
23
CHANGELOG.md
@@ -1,5 +1,28 @@
|
||||
# Changelog
|
||||
|
||||
## 1.9.0 (2020/12/04)
|
||||
|
||||
* Allow to add custom tags (#24)
|
||||
* Allow to disable latest tag (#23)
|
||||
* Warn on invalid semver (#22)
|
||||
* Avoid unnecessary calls to version (#21)
|
||||
|
||||
## 1.8.5 (2020/11/24)
|
||||
|
||||
* Use sepLabels when joining labels for output (#17)
|
||||
|
||||
## 1.8.4 (2020/11/20)
|
||||
|
||||
* Pre-release (rc, beta, alpha) will only extend `{{version}}` as tag for `tag-semver`
|
||||
|
||||
## 1.8.3 (2020/11/20)
|
||||
|
||||
* Lowercase image name (#16)
|
||||
|
||||
## 1.8.2 (2020/11/18)
|
||||
|
||||
* Remove duplicated tags
|
||||
|
||||
## 1.8.1 (2020/11/18)
|
||||
|
||||
* Missing input in `action.yml`
|
||||
|
76
README.md
76
README.md
@@ -26,8 +26,8 @@ ___
|
||||
* [outputs](#outputs)
|
||||
* [Notes](#notes)
|
||||
* [Latest tag](#latest-tag)
|
||||
* [`tag-match` examples](#tag-match-examples)
|
||||
* [Handle semver tag](#handle-semver-tag)
|
||||
* [`tag-match` examples](#tag-match-examples)
|
||||
* [Schedule tag](#schedule-tag)
|
||||
* [Overwrite labels](#overwrite-labels)
|
||||
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
|
||||
@@ -168,11 +168,11 @@ jobs:
|
||||
| Event | Ref | Commit SHA | Docker Tags |
|
||||
|-----------------|-------------------------------|------------|-----------------------------------------|
|
||||
| `schedule` | `refs/heads/master` | `45f132a` | `sha-45f132a`, `nightly` |
|
||||
| `pull_request` | `refs/pull/2/merge` | `a123b57` | `sha-45f132a`, `pr-2` |
|
||||
| `push` | `refs/heads/master` | `cf20257` | `sha-45f132a`, `master` |
|
||||
| `push` | `refs/heads/my/branch` | `a5df687` | `sha-45f132a`, `my-branch` |
|
||||
| `push tag` | `refs/tags/v1.2.3` | `ad132f5` | `sha-45f132a`, `1.2.3`, `1.2`, `latest` |
|
||||
| `push tag` | `refs/tags/v2.0.8-beta.67` | `fc89efd` | `sha-45f132a`, `2.0.8-beta.67` |
|
||||
| `pull_request` | `refs/pull/2/merge` | `a123b57` | `sha-a123b57`, `pr-2` |
|
||||
| `push` | `refs/heads/master` | `cf20257` | `sha-cf20257`, `master` |
|
||||
| `push` | `refs/heads/my/branch` | `a5df687` | `sha-a5df687`, `my-branch` |
|
||||
| `push tag` | `refs/tags/v1.2.3` | `ad132f5` | `sha-ad132f5`, `1.2.3`, `1.2`, `latest` |
|
||||
| `push tag` | `refs/tags/v2.0.8-beta.67` | `fc89efd` | `sha-fc89efd`, `2.0.8-beta.67` |
|
||||
|
||||
```yaml
|
||||
name: ci
|
||||
@@ -200,6 +200,7 @@ jobs:
|
||||
uses: crazy-max/ghaction-docker-meta@v1
|
||||
with:
|
||||
images: name/app
|
||||
tag-sha: true
|
||||
tag-semver: |
|
||||
{{version}}
|
||||
{{major}}.{{minor}}
|
||||
@@ -240,16 +241,20 @@ Following inputs can be used as `step.with` keys
|
||||
| `tag-sha` | Bool | Add git short SHA as Docker tag (default `false`) |
|
||||
| `tag-edge` | Bool | Enable edge branch tagging (default `false`) |
|
||||
| `tag-edge-branch` | String | Branch that will be tagged as edge (default `repo.default_branch`) |
|
||||
| `tag-semver` | List | Handle Git tag as semver [template](#handle-semver-tag) if possible |
|
||||
| `tag-semver` | List/CSV | Handle Git tag as semver [template](#handle-semver-tag) if possible |
|
||||
| `tag-match` | String | RegExp to match against a Git tag and use first match as Docker tag |
|
||||
| `tag-match-group` | Number | Group to get if `tag-match` matches (default `0`) |
|
||||
| `tag-match-latest` | Bool | Set `latest` Docker tag if `tag-match` matches or on Git tag event (default `true`) |
|
||||
| `tag-latest` | Bool | Set `latest` Docker tag if `tag-semver`, `tag-match` or Git tag event occurs (default `true`) |
|
||||
| `tag-schedule` | String | [Template](#schedule-tag) to apply to schedule tag (default `nightly`) |
|
||||
| `tag-custom` | List/CSV | List of custom tags |
|
||||
| `tag-custom-only` | Bool | Only use `tag-custom` as Docker tags |
|
||||
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
|
||||
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
|
||||
|
||||
> List/CSV type can be a newline or comma delimited string
|
||||
|
||||
> `tag-semver` and `tag-match` are mutually exclusive
|
||||
|
||||
### outputs
|
||||
|
||||
Following outputs are available
|
||||
@@ -266,37 +271,42 @@ Following outputs are available
|
||||
|
||||
Latest Docker tag will be generated by default on `push tag` event. If for example you push the `v1.2.3` Git tag,
|
||||
you will have at the output of this action the Docker tags `v1.2.3` and `latest`. But you can allow the latest tag to be
|
||||
generated only if the Git tag matches a regular expression with the [`tag-match` input](#tag-match-examples) or if
|
||||
`tag-semver` is valid [semver](https://semver.org/).
|
||||
|
||||
### `tag-match` examples
|
||||
|
||||
| Git tag | `tag-match` | `tag-match-group` | Match | Docker tags |
|
||||
|-------------------------|------------------------------------|-------------------|----------------------|---------------------------|
|
||||
| `v1.2.3` | `\d{1,3}.\d{1,3}.\d{1,3}` | `0` | :white_check_mark: | `1.2.3`, `latest` |
|
||||
| `v2.0.8-beta.67` | `v(.*)` | `1` | :white_check_mark: | `2.0.8-beta.67`, `latest` |
|
||||
| `v2.0.8-beta.67` | `v(\d.\d)` | `1` | :white_check_mark: | `2.0`, `latest` |
|
||||
| `release1` | `\d{1,3}.\d{1,3}` | `0` | :x: | `release1` |
|
||||
| `20200110-RC2` | `\d+` | `0` | :white_check_mark: | `20200110`, `latest` |
|
||||
generated only if `tag-semver` is a valid [semver](https://semver.org/) or if Git tag matches a regular expression
|
||||
with the [`tag-match` input](#tag-match-examples). Can be disabled if `tag-latest` is `false`.
|
||||
|
||||
### Handle semver tag
|
||||
|
||||
If Git tag is a valid [semver](https://semver.org/) you can handle it to output multi Docker tags at once.
|
||||
`tag-semver` supports multi-line [Handlebars template](https://handlebarsjs.com/guide/) with the following inputs:
|
||||
|
||||
| Git tag | `tag-semver` | Valid | Docker tags |
|
||||
|--------------------|----------------------------------------------------------|--------------------|--------------------|
|
||||
| `v1.2.3` | `{{raw}}` | :white_check_mark: | `v1.2.3`, `latest` |
|
||||
| `v1.2.3` | `{{version}}` | :white_check_mark: | `1.2.3`, `latest` |
|
||||
| `v1.2.3` | `{{major}}.{{minor}}` | :white_check_mark: | `1.2`, `latest` |
|
||||
| `v1.2.3` | `v{{major}}` | :white_check_mark: | `v1`, `latest` |
|
||||
| `v1.2.3` | `{{minor}}` | :white_check_mark: | `2`, `latest` |
|
||||
| `v1.2.3` | `{{patch}}` | :white_check_mark: | `3`, `latest` |
|
||||
| `v1.2.3` | `{{major}}.{{minor}}`<br>`{{major}}.{{minor}}.{{patch}}` | :white_check_mark: | `1.2`, `1.2.3`, `latest` |
|
||||
| `v2.0.8-beta.67` | `{{raw}}` | :white_check_mark: | `v2.0.8-beta.67` |
|
||||
| `v2.0.8-beta.67` | `{{version}}` | :white_check_mark: | `2.0.8-beta.67` |
|
||||
| `v2.0.8-beta.67` | `{{major}}.{{minor}}` | :white_check_mark: | `2.0` |
|
||||
| `release1` | `{{raw}}` | :x: | `release1` |
|
||||
| Git tag | `tag-semver` | Valid | Output tags | Output version |
|
||||
|--------------------|----------------------------------------------------------|--------------------|----------------------------|------------------------------|
|
||||
| `v1.2.3` | `{{raw}}` | :white_check_mark: | `v1.2.3`, `latest` | `v1.2.3` |
|
||||
| `v1.2.3` | `{{version}}` | :white_check_mark: | `1.2.3`, `latest` | `1.2.3` |
|
||||
| `v1.2.3` | `{{major}}.{{minor}}` | :white_check_mark: | `1.2`, `latest` | `1.2` |
|
||||
| `v1.2.3` | `v{{major}}` | :white_check_mark: | `v1`, `latest` | `v1` |
|
||||
| `v1.2.3` | `{{minor}}` | :white_check_mark: | `2`, `latest` | `2` |
|
||||
| `v1.2.3` | `{{patch}}` | :white_check_mark: | `3`, `latest` | `3` |
|
||||
| `v1.2.3` | `{{major}}.{{minor}}`<br>`{{major}}.{{minor}}.{{patch}}` | :white_check_mark: | `1.2`, `1.2.3`, `latest` | `1.2`* |
|
||||
| `v2.0.8-beta.67` | `{{raw}}` | :white_check_mark: | `2.0.8-beta.67`** | `2.0.8-beta.67` |
|
||||
| `v2.0.8-beta.67` | `{{version}}` | :white_check_mark: | `2.0.8-beta.67` | `2.0.8-beta.67` |
|
||||
| `v2.0.8-beta.67` | `{{major}}.{{minor}}` | :white_check_mark: | `2.0.8-beta.67`** | `2.0.8-beta.67` |
|
||||
| `release1` | `{{raw}}` | :x: | `release1` | `release1` |
|
||||
|
||||
> *First occurrence of `tag-semver` will be taken as `output.version`
|
||||
|
||||
> **Pre-release (rc, beta, alpha) will only extend `{{version}}` as tag because they are updated frequently,
|
||||
> and contain many breaking changes that are (by the author's design) not yet fit for public consumption.
|
||||
|
||||
### `tag-match` examples
|
||||
|
||||
| Git tag | `tag-match` | `tag-match-group` | Match | Output tags | Output version |
|
||||
|-------------------------|------------------------------------|-------------------|----------------------|---------------------------|------------------------------|
|
||||
| `v1.2.3` | `\d{1,3}.\d{1,3}.\d{1,3}` | `0` | :white_check_mark: | `1.2.3`, `latest` | `1.2.3` |
|
||||
| `v2.0.8-beta.67` | `v(.*)` | `1` | :white_check_mark: | `2.0.8-beta.67`, `latest` | `2.0.8-beta.67` |
|
||||
| `v2.0.8-beta.67` | `v(\d.\d)` | `1` | :white_check_mark: | `2.0`, `latest` | `2.0` |
|
||||
| `release1` | `\d{1,3}.\d{1,3}` | `0` | :x: | `release1` | `release1` |
|
||||
| `20200110-RC2` | `\d+` | `0` | :white_check_mark: | `20200110`, `latest` | `20200110` |
|
||||
|
||||
### Schedule tag
|
||||
|
||||
|
@@ -44,7 +44,7 @@ const tagsLabelsTest = async (envFile: string, inputs: Inputs, exVersion: Versio
|
||||
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
||||
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
||||
|
||||
const version = meta.version();
|
||||
const version = meta.version;
|
||||
console.log('version', version);
|
||||
expect(version).toEqual(exVersion);
|
||||
|
||||
@@ -437,7 +437,7 @@ describe('push tag', () => {
|
||||
{
|
||||
images: ['user/app'],
|
||||
tagMatch: `\\d{8}`,
|
||||
tagMatchLatest: false,
|
||||
tagLatest: false,
|
||||
} as Inputs,
|
||||
{
|
||||
main: '20200110',
|
||||
@@ -464,7 +464,7 @@ describe('push tag', () => {
|
||||
images: ['user/app'],
|
||||
tagMatch: `(.*)-RC`,
|
||||
tagMatchGroup: 1,
|
||||
tagMatchLatest: false,
|
||||
tagLatest: false,
|
||||
} as Inputs,
|
||||
{
|
||||
main: '20200110',
|
||||
@@ -683,11 +683,39 @@ describe('push tag', () => {
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_tag_v1.1.1.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagSemver: ['{{version}}', '{{major}}.{{minor}}.{{patch}}'],
|
||||
} as Inputs,
|
||||
{
|
||||
main: '1.1.1',
|
||||
partial: [],
|
||||
latest: true
|
||||
} as Version,
|
||||
[
|
||||
'org/app:1.1.1',
|
||||
'org/app:latest',
|
||||
'ghcr.io/user/app:1.1.1',
|
||||
'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.1.1",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_tag_v2.0.8-beta.67.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'],
|
||||
tagSemver: ['{{major}}.{{minor}}', '{{major}}'],
|
||||
} as Inputs,
|
||||
{
|
||||
main: '2.0.8-beta.67',
|
||||
@@ -709,6 +737,32 @@ describe('push tag', () => {
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_tag_sometag.env',
|
||||
{
|
||||
images: ['ghcr.io/user/app'],
|
||||
tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'],
|
||||
tagLatest: false,
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'sometag',
|
||||
partial: [],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'ghcr.io/user/app:sometag'
|
||||
],
|
||||
[
|
||||
"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=sometag",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
])('given %p event ', tagsLabelsTest);
|
||||
});
|
||||
|
||||
@@ -878,7 +932,7 @@ describe('latest', () => {
|
||||
'event_tag_v1.1.1.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagMatchLatest: false,
|
||||
tagLatest: false,
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'v1.1.1',
|
||||
@@ -900,6 +954,32 @@ describe('latest', () => {
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_tag_v1.1.1.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/MyUSER/MyApp'],
|
||||
tagLatest: false,
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'v1.1.1',
|
||||
partial: [],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'org/app:v1.1.1',
|
||||
'ghcr.io/myuser/myapp:v1.1.1',
|
||||
],
|
||||
[
|
||||
"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",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
])('given %p event ', tagsLabelsTest);
|
||||
});
|
||||
|
||||
@@ -1149,3 +1229,193 @@ describe('release', () => {
|
||||
],
|
||||
])('given %p event ', tagsLabelsTest);
|
||||
});
|
||||
|
||||
describe('custom', () => {
|
||||
// prettier-ignore
|
||||
test.each([
|
||||
[
|
||||
'event_push.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
tagCustom: ['my', 'custom', 'tags']
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'dev',
|
||||
partial: ['my', 'custom', 'tags'],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'user/app:dev',
|
||||
'user/app:my',
|
||||
'user/app:custom',
|
||||
'user/app:tags'
|
||||
],
|
||||
[
|
||||
"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=dev",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_push.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
tagCustom: ['my']
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'dev',
|
||||
partial: ['my'],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'user/app:dev',
|
||||
'user/app:my'
|
||||
],
|
||||
[
|
||||
"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=dev",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_tag_release1.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
tagCustom: ['my', 'custom', 'tags']
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'release1',
|
||||
partial: ['my', 'custom', 'tags'],
|
||||
latest: true
|
||||
} as Version,
|
||||
[
|
||||
'user/app:release1',
|
||||
'user/app:my',
|
||||
'user/app:custom',
|
||||
'user/app:tags',
|
||||
'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=release1",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_tag_20200110-RC2.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
tagMatch: `\\d{8}`,
|
||||
tagLatest: false,
|
||||
tagCustom: ['my', 'custom', 'tags']
|
||||
} as Inputs,
|
||||
{
|
||||
main: '20200110',
|
||||
partial: ['my', 'custom', 'tags'],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'user/app:20200110',
|
||||
'user/app:my',
|
||||
'user/app:custom',
|
||||
'user/app:tags'
|
||||
],
|
||||
[
|
||||
"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=20200110",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_tag_v1.1.1.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'],
|
||||
tagCustom: ['my', 'custom', 'tags']
|
||||
} as Inputs,
|
||||
{
|
||||
main: '1.1.1',
|
||||
partial: ['1.1', '1', 'my', 'custom', 'tags'],
|
||||
latest: true
|
||||
} as Version,
|
||||
[
|
||||
'org/app:1.1.1',
|
||||
'org/app:1.1',
|
||||
'org/app:1',
|
||||
'org/app:my',
|
||||
'org/app:custom',
|
||||
'org/app:tags',
|
||||
'org/app:latest',
|
||||
'ghcr.io/user/app:1.1.1',
|
||||
'ghcr.io/user/app:1.1',
|
||||
'ghcr.io/user/app:1',
|
||||
'ghcr.io/user/app:my',
|
||||
'ghcr.io/user/app:custom',
|
||||
'ghcr.io/user/app:tags',
|
||||
'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.1.1",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_tag_v1.1.1.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagSemver: ['{{version}}', '{{major}}.{{minor}}.{{patch}}'],
|
||||
tagCustom: ['my', 'custom', 'tags'],
|
||||
tagCustomOnly: true,
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'my',
|
||||
partial: ['custom', 'tags'],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'org/app:my',
|
||||
'org/app:custom',
|
||||
'org/app:tags',
|
||||
'ghcr.io/user/app:my',
|
||||
'ghcr.io/user/app:custom',
|
||||
'ghcr.io/user/app:tags'
|
||||
],
|
||||
[
|
||||
"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=my",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
])('given %p event ', tagsLabelsTest);
|
||||
});
|
||||
|
13
action.yml
13
action.yml
@@ -31,14 +31,25 @@ inputs:
|
||||
description: 'Group to get if tag-match matches (default 0)'
|
||||
default: '0'
|
||||
required: false
|
||||
tag-latest:
|
||||
description: 'Set latest Docker tag if tag-semver, tag-match or Git tag event occurs'
|
||||
default: 'true'
|
||||
required: false
|
||||
tag-match-latest:
|
||||
description: 'Set latest Docker tag if tag-match matches or on Git tag event'
|
||||
deprecationMessage: 'tag-match-latest is deprecated. Use tag-latest instead'
|
||||
description: '(DEPRECATED) Set latest Docker tag if tag-match matches or on Git tag event'
|
||||
default: 'true'
|
||||
required: false
|
||||
tag-schedule:
|
||||
description: 'Template to apply to schedule tag'
|
||||
default: 'nightly'
|
||||
required: false
|
||||
tag-custom:
|
||||
description: 'List of custom tags'
|
||||
required: false
|
||||
tag-custom-only:
|
||||
description: 'Only use tag-custom as Docker tags'
|
||||
required: false
|
||||
sep-tags:
|
||||
description: 'Separator to use for tags output (default \n)'
|
||||
required: false
|
||||
|
61
dist/index.js
generated
vendored
61
dist/index.js
generated
vendored
@@ -28,8 +28,10 @@ function getInputs() {
|
||||
tagSemver: getInputList('tag-semver'),
|
||||
tagMatch: core.getInput('tag-match'),
|
||||
tagMatchGroup: Number(core.getInput('tag-match-group')) || 0,
|
||||
tagMatchLatest: /true/i.test(core.getInput('tag-match-latest') || 'true'),
|
||||
tagLatest: /true/i.test(core.getInput('tag-latest') || core.getInput('tag-match-latest') || 'true'),
|
||||
tagSchedule: core.getInput('tag-schedule') || 'nightly',
|
||||
tagCustom: getInputList('tag-custom'),
|
||||
tagCustomOnly: /true/i.test(core.getInput('tag-custom-only') || 'false'),
|
||||
sepTags: core.getInput('sep-tags') || `\n`,
|
||||
sepLabels: core.getInput('sep-labels') || `\n`,
|
||||
githubToken: core.getInput('github-token')
|
||||
@@ -131,7 +133,7 @@ function run() {
|
||||
core.info(`runId: ${context.runId}`);
|
||||
core.endGroup();
|
||||
const meta = new meta_1.Meta(inputs, context, repo);
|
||||
const version = meta.version();
|
||||
const version = meta.version;
|
||||
core.startGroup(`Docker image version`);
|
||||
core.info(version.main || '');
|
||||
core.endGroup();
|
||||
@@ -149,7 +151,7 @@ function run() {
|
||||
core.info(label);
|
||||
}
|
||||
core.endGroup();
|
||||
core.setOutput('labels', labels.join(inputs.sepTags));
|
||||
core.setOutput('labels', labels.join(inputs.sepLabels));
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
@@ -171,6 +173,7 @@ exports.Meta = void 0;
|
||||
const handlebars = __webpack_require__(7492);
|
||||
const moment = __webpack_require__(9623);
|
||||
const semver = __webpack_require__(1383);
|
||||
const core = __webpack_require__(2186);
|
||||
class Meta {
|
||||
constructor(inputs, context, repo) {
|
||||
this.inputs = inputs;
|
||||
@@ -180,10 +183,11 @@ class Meta {
|
||||
this.context = context;
|
||||
this.repo = repo;
|
||||
this.date = new Date();
|
||||
this.version = this.getVersion();
|
||||
}
|
||||
version() {
|
||||
getVersion() {
|
||||
const currentDate = this.date;
|
||||
const version = {
|
||||
let version = {
|
||||
main: undefined,
|
||||
partial: [],
|
||||
latest: false
|
||||
@@ -197,13 +201,19 @@ class Meta {
|
||||
}
|
||||
else if (/^refs\/tags\//.test(this.context.ref)) {
|
||||
version.main = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||
if (this.inputs.tagSemver.length > 0 && !semver.valid(version.main)) {
|
||||
core.warning(`${version.main} is not a valid semver. More info: https://semver.org/`);
|
||||
}
|
||||
if (this.inputs.tagSemver.length > 0 && semver.valid(version.main)) {
|
||||
const sver = semver.parse(version.main, {
|
||||
includePrerelease: true
|
||||
});
|
||||
version.latest = !semver.prerelease(version.main);
|
||||
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver);
|
||||
if (version.latest) {
|
||||
if (semver.prerelease(version.main)) {
|
||||
version.main = handlebars.compile('{{version}}')(sver);
|
||||
}
|
||||
else {
|
||||
version.latest = this.inputs.tagLatest;
|
||||
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver);
|
||||
for (const semverTpl of this.inputs.tagSemver) {
|
||||
const partial = handlebars.compile(semverTpl)(sver);
|
||||
if (partial == version.main) {
|
||||
@@ -224,11 +234,11 @@ class Meta {
|
||||
}
|
||||
if (tagMatch) {
|
||||
version.main = tagMatch[this.inputs.tagMatchGroup];
|
||||
version.latest = this.inputs.tagMatchLatest;
|
||||
version.latest = this.inputs.tagLatest;
|
||||
}
|
||||
}
|
||||
else {
|
||||
version.latest = this.inputs.tagMatchLatest;
|
||||
version.latest = this.inputs.tagLatest;
|
||||
}
|
||||
}
|
||||
else if (/^refs\/heads\//.test(this.context.ref)) {
|
||||
@@ -240,24 +250,37 @@ class Meta {
|
||||
else if (/^refs\/pull\//.test(this.context.ref)) {
|
||||
version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
|
||||
}
|
||||
if (this.inputs.tagCustom.length > 0) {
|
||||
if (this.inputs.tagCustomOnly) {
|
||||
version = {
|
||||
main: this.inputs.tagCustom.shift(),
|
||||
partial: this.inputs.tagCustom,
|
||||
latest: false
|
||||
};
|
||||
}
|
||||
else {
|
||||
version.partial.push(...this.inputs.tagCustom);
|
||||
}
|
||||
}
|
||||
version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index);
|
||||
return version;
|
||||
}
|
||||
tags() {
|
||||
const version = this.version();
|
||||
if (!version.main) {
|
||||
if (!this.version.main) {
|
||||
return [];
|
||||
}
|
||||
let tags = [];
|
||||
for (const image of this.inputs.images) {
|
||||
tags.push(`${image}:${version.main}`);
|
||||
for (const partial of version.partial) {
|
||||
tags.push(`${image}:${partial}`);
|
||||
const imageLc = image.toLowerCase();
|
||||
tags.push(`${imageLc}:${this.version.main}`);
|
||||
for (const partial of this.version.partial) {
|
||||
tags.push(`${imageLc}:${partial}`);
|
||||
}
|
||||
if (version.latest) {
|
||||
tags.push(`${image}:latest`);
|
||||
if (this.version.latest) {
|
||||
tags.push(`${imageLc}:latest`);
|
||||
}
|
||||
if (this.context.sha && this.inputs.tagSha) {
|
||||
tags.push(`${image}:sha-${this.context.sha.substr(0, 7)}`);
|
||||
tags.push(`${imageLc}:sha-${this.context.sha.substr(0, 7)}`);
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
@@ -269,7 +292,7 @@ class Meta {
|
||||
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
||||
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
||||
`org.opencontainers.image.source=${this.repo.html_url || ''}`,
|
||||
`org.opencontainers.image.version=${this.version().main || ''}`,
|
||||
`org.opencontainers.image.version=${this.version.main || ''}`,
|
||||
`org.opencontainers.image.created=${this.date.toISOString()}`,
|
||||
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
||||
`org.opencontainers.image.licenses=${((_a = this.repo.license) === null || _a === void 0 ? void 0 : _a.spdx_id) || ''}`
|
||||
|
@@ -8,8 +8,10 @@ export interface Inputs {
|
||||
tagSemver: string[];
|
||||
tagMatch: string;
|
||||
tagMatchGroup: number;
|
||||
tagMatchLatest: boolean;
|
||||
tagLatest: boolean;
|
||||
tagSchedule: string;
|
||||
tagCustom: string[];
|
||||
tagCustomOnly: boolean;
|
||||
sepTags: string;
|
||||
sepLabels: string;
|
||||
githubToken: string;
|
||||
@@ -24,8 +26,10 @@ export function getInputs(): Inputs {
|
||||
tagSemver: getInputList('tag-semver'),
|
||||
tagMatch: core.getInput('tag-match'),
|
||||
tagMatchGroup: Number(core.getInput('tag-match-group')) || 0,
|
||||
tagMatchLatest: /true/i.test(core.getInput('tag-match-latest') || 'true'),
|
||||
tagLatest: /true/i.test(core.getInput('tag-latest') || core.getInput('tag-match-latest') || 'true'),
|
||||
tagSchedule: core.getInput('tag-schedule') || 'nightly',
|
||||
tagCustom: getInputList('tag-custom'),
|
||||
tagCustomOnly: /true/i.test(core.getInput('tag-custom-only') || 'false'),
|
||||
sepTags: core.getInput('sep-tags') || `\n`,
|
||||
sepLabels: core.getInput('sep-labels') || `\n`,
|
||||
githubToken: core.getInput('github-token')
|
||||
|
@@ -27,7 +27,7 @@ async function run() {
|
||||
|
||||
const meta: Meta = new Meta(inputs, context, repo);
|
||||
|
||||
const version: Version = meta.version();
|
||||
const version: Version = meta.version;
|
||||
core.startGroup(`Docker image version`);
|
||||
core.info(version.main || '');
|
||||
core.endGroup();
|
||||
@@ -47,7 +47,7 @@ async function run() {
|
||||
core.info(label);
|
||||
}
|
||||
core.endGroup();
|
||||
core.setOutput('labels', labels.join(inputs.sepTags));
|
||||
core.setOutput('labels', labels.join(inputs.sepLabels));
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
54
src/meta.ts
54
src/meta.ts
@@ -2,6 +2,7 @@ import * as handlebars from 'handlebars';
|
||||
import * as moment from 'moment';
|
||||
import * as semver from 'semver';
|
||||
import {Inputs} from './context';
|
||||
import * as core from '@actions/core';
|
||||
import {Context} from '@actions/github/lib/context';
|
||||
import {ReposGetResponseData} from '@octokit/types';
|
||||
|
||||
@@ -12,6 +13,8 @@ export interface Version {
|
||||
}
|
||||
|
||||
export class Meta {
|
||||
public readonly version: Version;
|
||||
|
||||
private readonly inputs: Inputs;
|
||||
private readonly context: Context;
|
||||
private readonly repo: ReposGetResponseData;
|
||||
@@ -25,11 +28,12 @@ export class Meta {
|
||||
this.context = context;
|
||||
this.repo = repo;
|
||||
this.date = new Date();
|
||||
this.version = this.getVersion();
|
||||
}
|
||||
|
||||
public version(): Version {
|
||||
private getVersion(): Version {
|
||||
const currentDate = this.date;
|
||||
const version: Version = {
|
||||
let version: Version = {
|
||||
main: undefined,
|
||||
partial: [],
|
||||
latest: false
|
||||
@@ -43,13 +47,18 @@ export class Meta {
|
||||
});
|
||||
} else if (/^refs\/tags\//.test(this.context.ref)) {
|
||||
version.main = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||
if (this.inputs.tagSemver.length > 0 && !semver.valid(version.main)) {
|
||||
core.warning(`${version.main} is not a valid semver. More info: https://semver.org/`);
|
||||
}
|
||||
if (this.inputs.tagSemver.length > 0 && semver.valid(version.main)) {
|
||||
const sver = semver.parse(version.main, {
|
||||
includePrerelease: true
|
||||
});
|
||||
version.latest = !semver.prerelease(version.main);
|
||||
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver);
|
||||
if (version.latest) {
|
||||
if (semver.prerelease(version.main)) {
|
||||
version.main = handlebars.compile('{{version}}')(sver);
|
||||
} else {
|
||||
version.latest = this.inputs.tagLatest;
|
||||
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver);
|
||||
for (const semverTpl of this.inputs.tagSemver) {
|
||||
const partial = handlebars.compile(semverTpl)(sver);
|
||||
if (partial == version.main) {
|
||||
@@ -68,10 +77,10 @@ export class Meta {
|
||||
}
|
||||
if (tagMatch) {
|
||||
version.main = tagMatch[this.inputs.tagMatchGroup];
|
||||
version.latest = this.inputs.tagMatchLatest;
|
||||
version.latest = this.inputs.tagLatest;
|
||||
}
|
||||
} else {
|
||||
version.latest = this.inputs.tagMatchLatest;
|
||||
version.latest = this.inputs.tagLatest;
|
||||
}
|
||||
} else if (/^refs\/heads\//.test(this.context.ref)) {
|
||||
version.main = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
||||
@@ -82,26 +91,39 @@ export class Meta {
|
||||
version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
|
||||
}
|
||||
|
||||
if (this.inputs.tagCustom.length > 0) {
|
||||
if (this.inputs.tagCustomOnly) {
|
||||
version = {
|
||||
main: this.inputs.tagCustom.shift(),
|
||||
partial: this.inputs.tagCustom,
|
||||
latest: false
|
||||
};
|
||||
} else {
|
||||
version.partial.push(...this.inputs.tagCustom);
|
||||
}
|
||||
}
|
||||
|
||||
version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index);
|
||||
return version;
|
||||
}
|
||||
|
||||
public tags(): Array<string> {
|
||||
const version: Version = this.version();
|
||||
if (!version.main) {
|
||||
if (!this.version.main) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let tags: Array<string> = [];
|
||||
for (const image of this.inputs.images) {
|
||||
tags.push(`${image}:${version.main}`);
|
||||
for (const partial of version.partial) {
|
||||
tags.push(`${image}:${partial}`);
|
||||
const imageLc = image.toLowerCase();
|
||||
tags.push(`${imageLc}:${this.version.main}`);
|
||||
for (const partial of this.version.partial) {
|
||||
tags.push(`${imageLc}:${partial}`);
|
||||
}
|
||||
if (version.latest) {
|
||||
tags.push(`${image}:latest`);
|
||||
if (this.version.latest) {
|
||||
tags.push(`${imageLc}:latest`);
|
||||
}
|
||||
if (this.context.sha && this.inputs.tagSha) {
|
||||
tags.push(`${image}:sha-${this.context.sha.substr(0, 7)}`);
|
||||
tags.push(`${imageLc}:sha-${this.context.sha.substr(0, 7)}`);
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
@@ -113,7 +135,7 @@ export class Meta {
|
||||
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
||||
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
||||
`org.opencontainers.image.source=${this.repo.html_url || ''}`,
|
||||
`org.opencontainers.image.version=${this.version().main || ''}`,
|
||||
`org.opencontainers.image.version=${this.version.main || ''}`,
|
||||
`org.opencontainers.image.created=${this.date.toISOString()}`,
|
||||
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
||||
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
|
||||
|
Reference in New Issue
Block a user