mirror of
https://github.com/docker/metadata-action.git
synced 2024-11-22 20:15:41 +01:00
backward compatibility with old images format
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
a5680a6642
commit
2f4dd1462a
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -241,7 +241,8 @@ jobs:
|
|||||||
id: docker_meta
|
id: docker_meta
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
images: ${{ env.DOCKER_IMAGE }}
|
images: |
|
||||||
|
${{ env.DOCKER_IMAGE }}
|
||||||
tags: |
|
tags: |
|
||||||
type=schedule
|
type=schedule
|
||||||
type=ref,event=branch
|
type=ref,event=branch
|
||||||
|
17
README.md
17
README.md
@ -126,7 +126,8 @@ jobs:
|
|||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v3
|
uses: docker/metadata-action@v3
|
||||||
with:
|
with:
|
||||||
images: name/app
|
images: |
|
||||||
|
name/app
|
||||||
tags: |
|
tags: |
|
||||||
type=ref,event=branch
|
type=ref,event=branch
|
||||||
type=ref,event=pr
|
type=ref,event=pr
|
||||||
@ -203,7 +204,8 @@ jobs:
|
|||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v3
|
uses: docker/metadata-action@v3
|
||||||
with:
|
with:
|
||||||
images: name/app
|
images: |
|
||||||
|
name/app
|
||||||
tags: |
|
tags: |
|
||||||
type=ref,event=branch
|
type=ref,event=branch
|
||||||
type=ref,event=pr
|
type=ref,event=pr
|
||||||
@ -265,14 +267,9 @@ Following inputs can be used as `step.with` keys
|
|||||||
> org.opencontainers.image.vendor=MyCompany
|
> org.opencontainers.image.vendor=MyCompany
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
> `CSV` type is a comma-delimited string
|
|
||||||
> ```yaml
|
|
||||||
> images: name/app,ghcr.io/name/app
|
|
||||||
> ```
|
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|---------------------|----------|------------------------------------|
|
|---------------------|--------|----------------------------------------------------------|
|
||||||
| `images` | List/CSV | List of Docker images to use as base name for tags |
|
| `images` | List | List of Docker images to use as base name for tags |
|
||||||
| `tags` | List | List of [tags](#tags-input) as key-value pair attributes |
|
| `tags` | List | List of [tags](#tags-input) as key-value pair attributes |
|
||||||
| `flavor` | List | [Flavor](#flavor-input) to apply |
|
| `flavor` | List | [Flavor](#flavor-input) to apply |
|
||||||
| `labels` | List | List of custom labels |
|
| `labels` | List | List of custom labels |
|
||||||
@ -285,7 +282,7 @@ Following inputs can be used as `step.with` keys
|
|||||||
Following outputs are available
|
Following outputs are available
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|---------------|---------|---------------------------------------|
|
|---------------|---------|-------------------------------------------------------------------------------|
|
||||||
| `version` | String | Docker image version |
|
| `version` | String | Docker image version |
|
||||||
| `tags` | String | Docker tags |
|
| `tags` | String | Docker tags |
|
||||||
| `labels` | String | Docker labels |
|
| `labels` | String | Docker labels |
|
||||||
|
@ -16,6 +16,22 @@ describe('transform', () => {
|
|||||||
] as Image[],
|
] as Image[],
|
||||||
false
|
false
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
`name/foo,name/bar`
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
name: `name/foo`,
|
||||||
|
enable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `name/bar`,
|
||||||
|
enable: true,
|
||||||
|
}
|
||||||
|
] as Image[],
|
||||||
|
false
|
||||||
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
`name/foo`,
|
`name/foo`,
|
||||||
@ -66,6 +82,9 @@ describe('transform', () => {
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
[`name=,enable=true`], undefined, true
|
[`name=,enable=true`], undefined, true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[`name/foo,name=name/bar,enable=true`], undefined, true
|
||||||
]
|
]
|
||||||
])('given %p', async (l: string[], expected: Image[], invalid: boolean) => {
|
])('given %p', async (l: string[], expected: Image[], invalid: boolean) => {
|
||||||
try {
|
try {
|
||||||
|
2
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -27,7 +27,7 @@ export function tmpDir(): string {
|
|||||||
|
|
||||||
export function getInputs(): Inputs {
|
export function getInputs(): Inputs {
|
||||||
return {
|
return {
|
||||||
images: getInputList('images'),
|
images: getInputList('images', true),
|
||||||
tags: getInputList('tags', true),
|
tags: getInputList('tags', true),
|
||||||
flavor: getInputList('flavor', true),
|
flavor: getInputList('flavor', true),
|
||||||
labels: getInputList('labels', true),
|
labels: getInputList('labels', true),
|
||||||
|
38
src/image.ts
38
src/image.ts
@ -1,4 +1,5 @@
|
|||||||
import {parse} from 'csv-parse/sync';
|
import {parse} from 'csv-parse/sync';
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
export interface Image {
|
export interface Image {
|
||||||
name: string;
|
name: string;
|
||||||
@ -6,7 +7,33 @@ export interface Image {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Transform(inputs: string[]): Image[] {
|
export function Transform(inputs: string[]): Image[] {
|
||||||
const images: Image[] = [];
|
let images: Image[] = [];
|
||||||
|
|
||||||
|
// backward compatibility with old format
|
||||||
|
if (inputs.length == 1) {
|
||||||
|
let newformat = false;
|
||||||
|
const fields = parse(inputs[0], {
|
||||||
|
relaxColumnCount: true,
|
||||||
|
skipEmptyLines: true
|
||||||
|
})[0];
|
||||||
|
for (const field of fields) {
|
||||||
|
const parts = field
|
||||||
|
.toString()
|
||||||
|
.split('=')
|
||||||
|
.map(item => item.trim());
|
||||||
|
if (parts.length == 1) {
|
||||||
|
images.push({name: parts[0].toLowerCase(), enable: true});
|
||||||
|
} else {
|
||||||
|
newformat = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!newformat) {
|
||||||
|
return output(images);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
images = [];
|
||||||
for (const input of inputs) {
|
for (const input of inputs) {
|
||||||
const image: Image = {name: '', enable: true};
|
const image: Image = {name: '', enable: true};
|
||||||
const fields = parse(input, {
|
const fields = parse(input, {
|
||||||
@ -46,5 +73,14 @@ export function Transform(inputs: string[]): Image[] {
|
|||||||
}
|
}
|
||||||
images.push(image);
|
images.push(image);
|
||||||
}
|
}
|
||||||
|
return output(images);
|
||||||
|
}
|
||||||
|
|
||||||
|
function output(images: Image[]): Image[] {
|
||||||
|
core.startGroup(`Processing images input`);
|
||||||
|
for (const image of images) {
|
||||||
|
core.info(`name=${image.name},enable=${image.enable}`);
|
||||||
|
}
|
||||||
|
core.endGroup();
|
||||||
return images;
|
return images;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user