mirror of
https://github.com/docker/metadata-action.git
synced 2024-12-22 21:35:38 +00:00
Allow to disable edge branch tagging (#2)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
a0b5755726
commit
cb039680df
|
@ -112,7 +112,8 @@ Following inputs can be used as `step.with` keys
|
||||||
|---------------------|----------|------------------------------------|
|
|---------------------|----------|------------------------------------|
|
||||||
| `images` | List/CSV | List of Docker images to use as base name for tags |
|
| `images` | List/CSV | List of Docker images to use as base name for tags |
|
||||||
| `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` | String | Branch that will be tagged as edge (default `repo.default_branch`) |
|
| `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-schedule` | String | [Handlebars template](https://handlebarsjs.com/guide/) to apply to schedule tag (default `nightly`) |
|
| `tag-schedule` | String | [Handlebars template](https://handlebarsjs.com/guide/) to apply to schedule tag (default `nightly`) |
|
||||||
| `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`) |
|
||||||
|
|
|
@ -119,6 +119,7 @@ describe('tags and labels', () => {
|
||||||
'event_push_defbranch.env',
|
'event_push_defbranch.env',
|
||||||
{
|
{
|
||||||
images: ['user/app'],
|
images: ['user/app'],
|
||||||
|
tagEdge: true,
|
||||||
} as Inputs,
|
} as Inputs,
|
||||||
'edge',
|
'edge',
|
||||||
[
|
[
|
||||||
|
@ -135,6 +136,26 @@ describe('tags and labels', () => {
|
||||||
"org.opencontainers.image.licenses=MIT"
|
"org.opencontainers.image.licenses=MIT"
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'event_push_defbranch.env',
|
||||||
|
{
|
||||||
|
images: ['user/app'],
|
||||||
|
} as Inputs,
|
||||||
|
'master',
|
||||||
|
[
|
||||||
|
'user/app:master'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"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.git",
|
||||||
|
"org.opencontainers.image.version=master",
|
||||||
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||||
|
"org.opencontainers.image.licenses=MIT"
|
||||||
|
]
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'event_release.env',
|
'event_release.env',
|
||||||
{
|
{
|
||||||
|
@ -263,6 +284,7 @@ describe('tags and labels', () => {
|
||||||
'event_workflow_dispatch.env',
|
'event_workflow_dispatch.env',
|
||||||
{
|
{
|
||||||
images: ['user/app'],
|
images: ['user/app'],
|
||||||
|
tagEdge: true,
|
||||||
} as Inputs,
|
} as Inputs,
|
||||||
'edge',
|
'edge',
|
||||||
[
|
[
|
||||||
|
@ -325,6 +347,7 @@ describe('tags and labels', () => {
|
||||||
'event_push_defbranch.env',
|
'event_push_defbranch.env',
|
||||||
{
|
{
|
||||||
images: ['org/app', 'ghcr.io/user/app'],
|
images: ['org/app', 'ghcr.io/user/app'],
|
||||||
|
tagEdge: true,
|
||||||
} as Inputs,
|
} as Inputs,
|
||||||
'edge',
|
'edge',
|
||||||
[
|
[
|
||||||
|
@ -439,6 +462,7 @@ describe('tags and labels', () => {
|
||||||
{
|
{
|
||||||
images: ['org/app', 'ghcr.io/user/app'],
|
images: ['org/app', 'ghcr.io/user/app'],
|
||||||
tagSha: true,
|
tagSha: true,
|
||||||
|
tagEdge: true,
|
||||||
} as Inputs,
|
} as Inputs,
|
||||||
'edge',
|
'edge',
|
||||||
[
|
[
|
||||||
|
@ -513,7 +537,8 @@ describe('tags and labels', () => {
|
||||||
{
|
{
|
||||||
images: ['org/app', 'ghcr.io/user/app'],
|
images: ['org/app', 'ghcr.io/user/app'],
|
||||||
tagSha: true,
|
tagSha: true,
|
||||||
tagEdge: 'dev'
|
tagEdge: true,
|
||||||
|
tagEdgeBranch: 'dev'
|
||||||
} as Inputs,
|
} as Inputs,
|
||||||
'edge',
|
'edge',
|
||||||
[
|
[
|
||||||
|
@ -538,7 +563,8 @@ describe('tags and labels', () => {
|
||||||
{
|
{
|
||||||
images: ['org/app', 'ghcr.io/user/app'],
|
images: ['org/app', 'ghcr.io/user/app'],
|
||||||
tagSha: true,
|
tagSha: true,
|
||||||
tagEdge: 'dev'
|
tagEdge: true,
|
||||||
|
tagEdgeBranch: 'dev'
|
||||||
} as Inputs,
|
} as Inputs,
|
||||||
'master',
|
'master',
|
||||||
[
|
[
|
||||||
|
|
|
@ -15,6 +15,10 @@ inputs:
|
||||||
default: 'false'
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
tag-edge:
|
tag-edge:
|
||||||
|
description: 'Enable edge branch tagging'
|
||||||
|
default: 'false'
|
||||||
|
required: false
|
||||||
|
tag-edge-branch:
|
||||||
description: 'Branch that will be tagged as edge (default repo.default_branch)'
|
description: 'Branch that will be tagged as edge (default repo.default_branch)'
|
||||||
required: false
|
required: false
|
||||||
tag-schedule:
|
tag-schedule:
|
||||||
|
|
13
dist/index.js
generated
vendored
13
dist/index.js
generated
vendored
|
@ -22,8 +22,9 @@ const core = __webpack_require__(2186);
|
||||||
function getInputs() {
|
function getInputs() {
|
||||||
return {
|
return {
|
||||||
images: getInputList('images'),
|
images: getInputList('images'),
|
||||||
tagSha: /true/i.test(core.getInput('tag-sha')),
|
tagSha: /true/i.test(core.getInput('tag-sha') || 'false'),
|
||||||
tagEdge: core.getInput('tag-edge'),
|
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
|
||||||
|
tagEdgeBranch: core.getInput('tag-edge-branch'),
|
||||||
tagSchedule: core.getInput('tag-schedule') || 'nightly',
|
tagSchedule: core.getInput('tag-schedule') || 'nightly',
|
||||||
sepTags: core.getInput('sep-tags') || `\n`,
|
sepTags: core.getInput('sep-tags') || `\n`,
|
||||||
sepLabels: core.getInput('sep-labels') || `\n`,
|
sepLabels: core.getInput('sep-labels') || `\n`,
|
||||||
|
@ -170,8 +171,8 @@ const core = __webpack_require__(2186);
|
||||||
class Meta {
|
class Meta {
|
||||||
constructor(inputs, context, repo) {
|
constructor(inputs, context, repo) {
|
||||||
this.inputs = inputs;
|
this.inputs = inputs;
|
||||||
if (!this.inputs.tagEdge) {
|
if (!this.inputs.tagEdgeBranch) {
|
||||||
this.inputs.tagEdge = repo.default_branch;
|
this.inputs.tagEdgeBranch = repo.default_branch;
|
||||||
}
|
}
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
|
@ -188,7 +189,7 @@ class Meta {
|
||||||
}
|
}
|
||||||
else if (/^refs\/heads\//.test(this.context.ref)) {
|
else if (/^refs\/heads\//.test(this.context.ref)) {
|
||||||
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
||||||
return this.inputs.tagEdge === branch ? 'edge' : branch;
|
return this.inputs.tagEdge && this.inputs.tagEdgeBranch === branch ? 'edge' : branch;
|
||||||
}
|
}
|
||||||
else if (/^refs\/pull\//.test(this.context.ref)) {
|
else if (/^refs\/pull\//.test(this.context.ref)) {
|
||||||
const pr = this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '');
|
const pr = this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '');
|
||||||
|
@ -246,7 +247,7 @@ class Meta {
|
||||||
}
|
}
|
||||||
eventBranch(image) {
|
eventBranch(image) {
|
||||||
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
||||||
if (this.inputs.tagEdge === branch) {
|
if (this.inputs.tagEdge && this.inputs.tagEdgeBranch === branch) {
|
||||||
return [`${image}:edge`];
|
return [`${image}:edge`];
|
||||||
}
|
}
|
||||||
return [`${image}:${branch}`];
|
return [`${image}:${branch}`];
|
||||||
|
|
|
@ -3,7 +3,8 @@ import * as core from '@actions/core';
|
||||||
export interface Inputs {
|
export interface Inputs {
|
||||||
images: string[];
|
images: string[];
|
||||||
tagSha: boolean;
|
tagSha: boolean;
|
||||||
tagEdge: string;
|
tagEdge: boolean;
|
||||||
|
tagEdgeBranch: string;
|
||||||
tagSchedule: string;
|
tagSchedule: string;
|
||||||
sepTags: string;
|
sepTags: string;
|
||||||
sepLabels: string;
|
sepLabels: string;
|
||||||
|
@ -13,8 +14,9 @@ export interface Inputs {
|
||||||
export function getInputs(): Inputs {
|
export function getInputs(): Inputs {
|
||||||
return {
|
return {
|
||||||
images: getInputList('images'),
|
images: getInputList('images'),
|
||||||
tagSha: /true/i.test(core.getInput('tag-sha')),
|
tagSha: /true/i.test(core.getInput('tag-sha') || 'false'),
|
||||||
tagEdge: core.getInput('tag-edge'),
|
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
|
||||||
|
tagEdgeBranch: core.getInput('tag-edge-branch'),
|
||||||
tagSchedule: core.getInput('tag-schedule') || 'nightly',
|
tagSchedule: core.getInput('tag-schedule') || 'nightly',
|
||||||
sepTags: core.getInput('sep-tags') || `\n`,
|
sepTags: core.getInput('sep-tags') || `\n`,
|
||||||
sepLabels: core.getInput('sep-labels') || `\n`,
|
sepLabels: core.getInput('sep-labels') || `\n`,
|
||||||
|
|
|
@ -14,8 +14,8 @@ export class Meta {
|
||||||
|
|
||||||
constructor(inputs: Inputs, context: Context, repo: ReposGetResponseData) {
|
constructor(inputs: Inputs, context: Context, repo: ReposGetResponseData) {
|
||||||
this.inputs = inputs;
|
this.inputs = inputs;
|
||||||
if (!this.inputs.tagEdge) {
|
if (!this.inputs.tagEdgeBranch) {
|
||||||
this.inputs.tagEdge = repo.default_branch;
|
this.inputs.tagEdgeBranch = repo.default_branch;
|
||||||
}
|
}
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
|
@ -31,7 +31,7 @@ export class Meta {
|
||||||
return sver ? sver : tag;
|
return sver ? sver : tag;
|
||||||
} else if (/^refs\/heads\//.test(this.context.ref)) {
|
} else if (/^refs\/heads\//.test(this.context.ref)) {
|
||||||
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
||||||
return this.inputs.tagEdge === branch ? 'edge' : branch;
|
return this.inputs.tagEdge && this.inputs.tagEdgeBranch === branch ? 'edge' : branch;
|
||||||
} else if (/^refs\/pull\//.test(this.context.ref)) {
|
} else if (/^refs\/pull\//.test(this.context.ref)) {
|
||||||
const pr = this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '');
|
const pr = this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '');
|
||||||
return `pr-${pr}`;
|
return `pr-${pr}`;
|
||||||
|
@ -88,7 +88,7 @@ export class Meta {
|
||||||
|
|
||||||
private eventBranch(image: string): Array<string> {
|
private eventBranch(image: string): Array<string> {
|
||||||
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
||||||
if (this.inputs.tagEdge === branch) {
|
if (this.inputs.tagEdge && this.inputs.tagEdgeBranch === branch) {
|
||||||
return [`${image}:edge`];
|
return [`${image}:edge`];
|
||||||
}
|
}
|
||||||
return [`${image}:${branch}`];
|
return [`${image}:${branch}`];
|
||||||
|
|
Loading…
Reference in a new issue