Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b747b8aaa7 | ||
|
585ab8356c | ||
|
9de4428611 | ||
|
4c2760ba7a | ||
|
ef12c77b87 | ||
|
c53f88523a | ||
|
6b4bf4724e | ||
|
d48c7d2917 |
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
@@ -82,10 +82,18 @@ jobs:
|
|||||||
|
|
||||||
tag-semver:
|
tag-semver:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
tag-latest:
|
||||||
|
- 'true'
|
||||||
|
- 'false'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
-
|
||||||
|
name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Docker meta
|
-
|
||||||
|
name: Docker meta
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
images: |
|
images: |
|
||||||
@@ -95,6 +103,7 @@ jobs:
|
|||||||
{{raw}}
|
{{raw}}
|
||||||
{{version}}
|
{{version}}
|
||||||
{{major}}.{{minor}}.{{patch}}
|
{{major}}.{{minor}}.{{patch}}
|
||||||
|
tag-latest: ${{ matrix.tag-latest }}
|
||||||
|
|
||||||
docker-push:
|
docker-push:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -114,7 +123,10 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
images: ${{ env.DOCKER_IMAGE }}
|
images: ${{ env.DOCKER_IMAGE }}
|
||||||
tag-sha: true
|
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
|
name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@v1
|
||||||
|
11
CHANGELOG.md
11
CHANGELOG.md
@@ -1,5 +1,16 @@
|
|||||||
# Changelog
|
# 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)
|
## 1.8.4 (2020/11/20)
|
||||||
|
|
||||||
* Pre-release (rc, beta, alpha) will only extend `{{version}}` as tag for `tag-semver`
|
* Pre-release (rc, beta, alpha) will only extend `{{version}}` as tag for `tag-semver`
|
||||||
|
19
README.md
19
README.md
@@ -168,11 +168,11 @@ jobs:
|
|||||||
| Event | Ref | Commit SHA | Docker Tags |
|
| Event | Ref | Commit SHA | Docker Tags |
|
||||||
|-----------------|-------------------------------|------------|-----------------------------------------|
|
|-----------------|-------------------------------|------------|-----------------------------------------|
|
||||||
| `schedule` | `refs/heads/master` | `45f132a` | `sha-45f132a`, `nightly` |
|
| `schedule` | `refs/heads/master` | `45f132a` | `sha-45f132a`, `nightly` |
|
||||||
| `pull_request` | `refs/pull/2/merge` | `a123b57` | `sha-45f132a`, `pr-2` |
|
| `pull_request` | `refs/pull/2/merge` | `a123b57` | `sha-a123b57`, `pr-2` |
|
||||||
| `push` | `refs/heads/master` | `cf20257` | `sha-45f132a`, `master` |
|
| `push` | `refs/heads/master` | `cf20257` | `sha-cf20257`, `master` |
|
||||||
| `push` | `refs/heads/my/branch` | `a5df687` | `sha-45f132a`, `my-branch` |
|
| `push` | `refs/heads/my/branch` | `a5df687` | `sha-a5df687`, `my-branch` |
|
||||||
| `push tag` | `refs/tags/v1.2.3` | `ad132f5` | `sha-45f132a`, `1.2.3`, `1.2`, `latest` |
|
| `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-45f132a`, `2.0.8-beta.67` |
|
| `push tag` | `refs/tags/v2.0.8-beta.67` | `fc89efd` | `sha-fc89efd`, `2.0.8-beta.67` |
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: ci
|
name: ci
|
||||||
@@ -200,6 +200,7 @@ jobs:
|
|||||||
uses: crazy-max/ghaction-docker-meta@v1
|
uses: crazy-max/ghaction-docker-meta@v1
|
||||||
with:
|
with:
|
||||||
images: name/app
|
images: name/app
|
||||||
|
tag-sha: true
|
||||||
tag-semver: |
|
tag-semver: |
|
||||||
{{version}}
|
{{version}}
|
||||||
{{major}}.{{minor}}
|
{{major}}.{{minor}}
|
||||||
@@ -240,11 +241,13 @@ Following inputs can be used as `step.with` keys
|
|||||||
| `tag-sha` | Bool | Add git short SHA as Docker tag (default `false`) |
|
| `tag-sha` | Bool | Add git short SHA as Docker tag (default `false`) |
|
||||||
| `tag-edge` | Bool | Enable edge branch tagging (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-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` | 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-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-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-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`) |
|
||||||
|
|
||||||
@@ -269,7 +272,7 @@ 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,
|
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
|
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 `tag-semver` is a valid [semver](https://semver.org/) or if Git tag matches a regular expression
|
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).
|
with the [`tag-match` input](#tag-match-examples). Can be disabled if `tag-latest` is `false`.
|
||||||
|
|
||||||
### Handle semver tag
|
### Handle semver tag
|
||||||
|
|
||||||
|
@@ -44,7 +44,7 @@ const tagsLabelsTest = async (envFile: string, inputs: Inputs, exVersion: Versio
|
|||||||
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
||||||
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
||||||
|
|
||||||
const version = meta.version();
|
const version = meta.version;
|
||||||
console.log('version', version);
|
console.log('version', version);
|
||||||
expect(version).toEqual(exVersion);
|
expect(version).toEqual(exVersion);
|
||||||
|
|
||||||
@@ -437,7 +437,7 @@ describe('push tag', () => {
|
|||||||
{
|
{
|
||||||
images: ['user/app'],
|
images: ['user/app'],
|
||||||
tagMatch: `\\d{8}`,
|
tagMatch: `\\d{8}`,
|
||||||
tagMatchLatest: false,
|
tagLatest: false,
|
||||||
} as Inputs,
|
} as Inputs,
|
||||||
{
|
{
|
||||||
main: '20200110',
|
main: '20200110',
|
||||||
@@ -464,7 +464,7 @@ describe('push tag', () => {
|
|||||||
images: ['user/app'],
|
images: ['user/app'],
|
||||||
tagMatch: `(.*)-RC`,
|
tagMatch: `(.*)-RC`,
|
||||||
tagMatchGroup: 1,
|
tagMatchGroup: 1,
|
||||||
tagMatchLatest: false,
|
tagLatest: false,
|
||||||
} as Inputs,
|
} as Inputs,
|
||||||
{
|
{
|
||||||
main: '20200110',
|
main: '20200110',
|
||||||
@@ -737,6 +737,32 @@ describe('push tag', () => {
|
|||||||
"org.opencontainers.image.licenses=MIT"
|
"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);
|
])('given %p event ', tagsLabelsTest);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -906,7 +932,7 @@ describe('latest', () => {
|
|||||||
'event_tag_v1.1.1.env',
|
'event_tag_v1.1.1.env',
|
||||||
{
|
{
|
||||||
images: ['org/app', 'ghcr.io/user/app'],
|
images: ['org/app', 'ghcr.io/user/app'],
|
||||||
tagMatchLatest: false,
|
tagLatest: false,
|
||||||
} as Inputs,
|
} as Inputs,
|
||||||
{
|
{
|
||||||
main: 'v1.1.1',
|
main: 'v1.1.1',
|
||||||
@@ -932,7 +958,7 @@ describe('latest', () => {
|
|||||||
'event_tag_v1.1.1.env',
|
'event_tag_v1.1.1.env',
|
||||||
{
|
{
|
||||||
images: ['org/app', 'ghcr.io/MyUSER/MyApp'],
|
images: ['org/app', 'ghcr.io/MyUSER/MyApp'],
|
||||||
tagMatchLatest: false,
|
tagLatest: false,
|
||||||
} as Inputs,
|
} as Inputs,
|
||||||
{
|
{
|
||||||
main: 'v1.1.1',
|
main: 'v1.1.1',
|
||||||
@@ -1203,3 +1229,193 @@ describe('release', () => {
|
|||||||
],
|
],
|
||||||
])('given %p event ', tagsLabelsTest);
|
])('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)'
|
description: 'Group to get if tag-match matches (default 0)'
|
||||||
default: '0'
|
default: '0'
|
||||||
required: false
|
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:
|
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'
|
default: 'true'
|
||||||
required: false
|
required: false
|
||||||
tag-schedule:
|
tag-schedule:
|
||||||
description: 'Template to apply to schedule tag'
|
description: 'Template to apply to schedule tag'
|
||||||
default: 'nightly'
|
default: 'nightly'
|
||||||
required: false
|
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:
|
sep-tags:
|
||||||
description: 'Separator to use for tags output (default \n)'
|
description: 'Separator to use for tags output (default \n)'
|
||||||
required: false
|
required: false
|
||||||
|
46
dist/index.js
generated
vendored
46
dist/index.js
generated
vendored
@@ -28,8 +28,10 @@ function getInputs() {
|
|||||||
tagSemver: getInputList('tag-semver'),
|
tagSemver: getInputList('tag-semver'),
|
||||||
tagMatch: core.getInput('tag-match'),
|
tagMatch: core.getInput('tag-match'),
|
||||||
tagMatchGroup: Number(core.getInput('tag-match-group')) || 0,
|
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',
|
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`,
|
sepTags: core.getInput('sep-tags') || `\n`,
|
||||||
sepLabels: core.getInput('sep-labels') || `\n`,
|
sepLabels: core.getInput('sep-labels') || `\n`,
|
||||||
githubToken: core.getInput('github-token')
|
githubToken: core.getInput('github-token')
|
||||||
@@ -131,7 +133,7 @@ function run() {
|
|||||||
core.info(`runId: ${context.runId}`);
|
core.info(`runId: ${context.runId}`);
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
const meta = new meta_1.Meta(inputs, context, repo);
|
const meta = new meta_1.Meta(inputs, context, repo);
|
||||||
const version = meta.version();
|
const version = meta.version;
|
||||||
core.startGroup(`Docker image version`);
|
core.startGroup(`Docker image version`);
|
||||||
core.info(version.main || '');
|
core.info(version.main || '');
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
@@ -149,7 +151,7 @@ function run() {
|
|||||||
core.info(label);
|
core.info(label);
|
||||||
}
|
}
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
core.setOutput('labels', labels.join(inputs.sepTags));
|
core.setOutput('labels', labels.join(inputs.sepLabels));
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
@@ -171,6 +173,7 @@ exports.Meta = void 0;
|
|||||||
const handlebars = __webpack_require__(7492);
|
const handlebars = __webpack_require__(7492);
|
||||||
const moment = __webpack_require__(9623);
|
const moment = __webpack_require__(9623);
|
||||||
const semver = __webpack_require__(1383);
|
const semver = __webpack_require__(1383);
|
||||||
|
const core = __webpack_require__(2186);
|
||||||
class Meta {
|
class Meta {
|
||||||
constructor(inputs, context, repo) {
|
constructor(inputs, context, repo) {
|
||||||
this.inputs = inputs;
|
this.inputs = inputs;
|
||||||
@@ -180,10 +183,11 @@ class Meta {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
|
this.version = this.getVersion();
|
||||||
}
|
}
|
||||||
version() {
|
getVersion() {
|
||||||
const currentDate = this.date;
|
const currentDate = this.date;
|
||||||
const version = {
|
let version = {
|
||||||
main: undefined,
|
main: undefined,
|
||||||
partial: [],
|
partial: [],
|
||||||
latest: false
|
latest: false
|
||||||
@@ -197,6 +201,9 @@ class Meta {
|
|||||||
}
|
}
|
||||||
else if (/^refs\/tags\//.test(this.context.ref)) {
|
else if (/^refs\/tags\//.test(this.context.ref)) {
|
||||||
version.main = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
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)) {
|
if (this.inputs.tagSemver.length > 0 && semver.valid(version.main)) {
|
||||||
const sver = semver.parse(version.main, {
|
const sver = semver.parse(version.main, {
|
||||||
includePrerelease: true
|
includePrerelease: true
|
||||||
@@ -205,7 +212,7 @@ class Meta {
|
|||||||
version.main = handlebars.compile('{{version}}')(sver);
|
version.main = handlebars.compile('{{version}}')(sver);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
version.latest = true;
|
version.latest = this.inputs.tagLatest;
|
||||||
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver);
|
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver);
|
||||||
for (const semverTpl of this.inputs.tagSemver) {
|
for (const semverTpl of this.inputs.tagSemver) {
|
||||||
const partial = handlebars.compile(semverTpl)(sver);
|
const partial = handlebars.compile(semverTpl)(sver);
|
||||||
@@ -227,11 +234,11 @@ class Meta {
|
|||||||
}
|
}
|
||||||
if (tagMatch) {
|
if (tagMatch) {
|
||||||
version.main = tagMatch[this.inputs.tagMatchGroup];
|
version.main = tagMatch[this.inputs.tagMatchGroup];
|
||||||
version.latest = this.inputs.tagMatchLatest;
|
version.latest = this.inputs.tagLatest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
version.latest = this.inputs.tagMatchLatest;
|
version.latest = this.inputs.tagLatest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (/^refs\/heads\//.test(this.context.ref)) {
|
else if (/^refs\/heads\//.test(this.context.ref)) {
|
||||||
@@ -243,22 +250,33 @@ class Meta {
|
|||||||
else if (/^refs\/pull\//.test(this.context.ref)) {
|
else if (/^refs\/pull\//.test(this.context.ref)) {
|
||||||
version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
|
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);
|
version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index);
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
tags() {
|
tags() {
|
||||||
const version = this.version();
|
if (!this.version.main) {
|
||||||
if (!version.main) {
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
let tags = [];
|
let tags = [];
|
||||||
for (const image of this.inputs.images) {
|
for (const image of this.inputs.images) {
|
||||||
const imageLc = image.toLowerCase();
|
const imageLc = image.toLowerCase();
|
||||||
tags.push(`${imageLc}:${version.main}`);
|
tags.push(`${imageLc}:${this.version.main}`);
|
||||||
for (const partial of version.partial) {
|
for (const partial of this.version.partial) {
|
||||||
tags.push(`${imageLc}:${partial}`);
|
tags.push(`${imageLc}:${partial}`);
|
||||||
}
|
}
|
||||||
if (version.latest) {
|
if (this.version.latest) {
|
||||||
tags.push(`${imageLc}:latest`);
|
tags.push(`${imageLc}:latest`);
|
||||||
}
|
}
|
||||||
if (this.context.sha && this.inputs.tagSha) {
|
if (this.context.sha && this.inputs.tagSha) {
|
||||||
@@ -274,7 +292,7 @@ class Meta {
|
|||||||
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
||||||
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
||||||
`org.opencontainers.image.source=${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.created=${this.date.toISOString()}`,
|
||||||
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
||||||
`org.opencontainers.image.licenses=${((_a = this.repo.license) === null || _a === void 0 ? void 0 : _a.spdx_id) || ''}`
|
`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[];
|
tagSemver: string[];
|
||||||
tagMatch: string;
|
tagMatch: string;
|
||||||
tagMatchGroup: number;
|
tagMatchGroup: number;
|
||||||
tagMatchLatest: boolean;
|
tagLatest: boolean;
|
||||||
tagSchedule: string;
|
tagSchedule: string;
|
||||||
|
tagCustom: string[];
|
||||||
|
tagCustomOnly: boolean;
|
||||||
sepTags: string;
|
sepTags: string;
|
||||||
sepLabels: string;
|
sepLabels: string;
|
||||||
githubToken: string;
|
githubToken: string;
|
||||||
@@ -24,8 +26,10 @@ export function getInputs(): Inputs {
|
|||||||
tagSemver: getInputList('tag-semver'),
|
tagSemver: getInputList('tag-semver'),
|
||||||
tagMatch: core.getInput('tag-match'),
|
tagMatch: core.getInput('tag-match'),
|
||||||
tagMatchGroup: Number(core.getInput('tag-match-group')) || 0,
|
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',
|
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`,
|
sepTags: core.getInput('sep-tags') || `\n`,
|
||||||
sepLabels: core.getInput('sep-labels') || `\n`,
|
sepLabels: core.getInput('sep-labels') || `\n`,
|
||||||
githubToken: core.getInput('github-token')
|
githubToken: core.getInput('github-token')
|
||||||
|
@@ -27,7 +27,7 @@ async function run() {
|
|||||||
|
|
||||||
const meta: Meta = new Meta(inputs, context, repo);
|
const meta: Meta = new Meta(inputs, context, repo);
|
||||||
|
|
||||||
const version: Version = meta.version();
|
const version: Version = meta.version;
|
||||||
core.startGroup(`Docker image version`);
|
core.startGroup(`Docker image version`);
|
||||||
core.info(version.main || '');
|
core.info(version.main || '');
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
@@ -47,7 +47,7 @@ async function run() {
|
|||||||
core.info(label);
|
core.info(label);
|
||||||
}
|
}
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
core.setOutput('labels', labels.join(inputs.sepTags));
|
core.setOutput('labels', labels.join(inputs.sepLabels));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
|
40
src/meta.ts
40
src/meta.ts
@@ -2,6 +2,7 @@ import * as handlebars from 'handlebars';
|
|||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import {Inputs} from './context';
|
import {Inputs} from './context';
|
||||||
|
import * as core from '@actions/core';
|
||||||
import {Context} from '@actions/github/lib/context';
|
import {Context} from '@actions/github/lib/context';
|
||||||
import {ReposGetResponseData} from '@octokit/types';
|
import {ReposGetResponseData} from '@octokit/types';
|
||||||
|
|
||||||
@@ -12,6 +13,8 @@ export interface Version {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Meta {
|
export class Meta {
|
||||||
|
public readonly version: Version;
|
||||||
|
|
||||||
private readonly inputs: Inputs;
|
private readonly inputs: Inputs;
|
||||||
private readonly context: Context;
|
private readonly context: Context;
|
||||||
private readonly repo: ReposGetResponseData;
|
private readonly repo: ReposGetResponseData;
|
||||||
@@ -25,11 +28,12 @@ export class Meta {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
|
this.version = this.getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
public version(): Version {
|
private getVersion(): Version {
|
||||||
const currentDate = this.date;
|
const currentDate = this.date;
|
||||||
const version: Version = {
|
let version: Version = {
|
||||||
main: undefined,
|
main: undefined,
|
||||||
partial: [],
|
partial: [],
|
||||||
latest: false
|
latest: false
|
||||||
@@ -43,6 +47,9 @@ export class Meta {
|
|||||||
});
|
});
|
||||||
} else if (/^refs\/tags\//.test(this.context.ref)) {
|
} else if (/^refs\/tags\//.test(this.context.ref)) {
|
||||||
version.main = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
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)) {
|
if (this.inputs.tagSemver.length > 0 && semver.valid(version.main)) {
|
||||||
const sver = semver.parse(version.main, {
|
const sver = semver.parse(version.main, {
|
||||||
includePrerelease: true
|
includePrerelease: true
|
||||||
@@ -50,7 +57,7 @@ export class Meta {
|
|||||||
if (semver.prerelease(version.main)) {
|
if (semver.prerelease(version.main)) {
|
||||||
version.main = handlebars.compile('{{version}}')(sver);
|
version.main = handlebars.compile('{{version}}')(sver);
|
||||||
} else {
|
} else {
|
||||||
version.latest = true;
|
version.latest = this.inputs.tagLatest;
|
||||||
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver);
|
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver);
|
||||||
for (const semverTpl of this.inputs.tagSemver) {
|
for (const semverTpl of this.inputs.tagSemver) {
|
||||||
const partial = handlebars.compile(semverTpl)(sver);
|
const partial = handlebars.compile(semverTpl)(sver);
|
||||||
@@ -70,10 +77,10 @@ export class Meta {
|
|||||||
}
|
}
|
||||||
if (tagMatch) {
|
if (tagMatch) {
|
||||||
version.main = tagMatch[this.inputs.tagMatchGroup];
|
version.main = tagMatch[this.inputs.tagMatchGroup];
|
||||||
version.latest = this.inputs.tagMatchLatest;
|
version.latest = this.inputs.tagLatest;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
version.latest = this.inputs.tagMatchLatest;
|
version.latest = this.inputs.tagLatest;
|
||||||
}
|
}
|
||||||
} else if (/^refs\/heads\//.test(this.context.ref)) {
|
} else if (/^refs\/heads\//.test(this.context.ref)) {
|
||||||
version.main = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
version.main = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
||||||
@@ -84,24 +91,35 @@ export class Meta {
|
|||||||
version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
|
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);
|
version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index);
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public tags(): Array<string> {
|
public tags(): Array<string> {
|
||||||
const version: Version = this.version();
|
if (!this.version.main) {
|
||||||
if (!version.main) {
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
let tags: Array<string> = [];
|
let tags: Array<string> = [];
|
||||||
for (const image of this.inputs.images) {
|
for (const image of this.inputs.images) {
|
||||||
const imageLc = image.toLowerCase();
|
const imageLc = image.toLowerCase();
|
||||||
tags.push(`${imageLc}:${version.main}`);
|
tags.push(`${imageLc}:${this.version.main}`);
|
||||||
for (const partial of version.partial) {
|
for (const partial of this.version.partial) {
|
||||||
tags.push(`${imageLc}:${partial}`);
|
tags.push(`${imageLc}:${partial}`);
|
||||||
}
|
}
|
||||||
if (version.latest) {
|
if (this.version.latest) {
|
||||||
tags.push(`${imageLc}:latest`);
|
tags.push(`${imageLc}:latest`);
|
||||||
}
|
}
|
||||||
if (this.context.sha && this.inputs.tagSha) {
|
if (this.context.sha && this.inputs.tagSha) {
|
||||||
@@ -117,7 +135,7 @@ export class Meta {
|
|||||||
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
||||||
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
||||||
`org.opencontainers.image.source=${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.created=${this.date.toISOString()}`,
|
||||||
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
||||||
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
|
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
|
||||||
|
Reference in New Issue
Block a user