backward compatibility with old images format

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-04-28 09:08:21 +02:00
parent a5680a6642
commit 2f4dd1462a
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
7 changed files with 80 additions and 27 deletions

View file

@ -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

View file

@ -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,31 +267,26 @@ 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 | Name | Type | Description |
> ```yaml |---------------------|--------|----------------------------------------------------------|
> images: name/app,ghcr.io/name/app | `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 |
| `flavor` | List | [Flavor](#flavor-input) to apply |
| Name | Type | Description | | `labels` | List | List of custom labels |
|---------------------|----------|------------------------------------| | `sep-tags` | String | Separator to use for tags output (default `\n`) |
| `images` | List/CSV | List of Docker images to use as base name for tags | | `sep-labels` | String | Separator to use for labels output (default `\n`) |
| `tags` | List | List of [tags](#tags-input) as key-value pair attributes | | `bake-target` | String | Bake target name (default `docker-metadata-action`) |
| `flavor` | List | [Flavor](#flavor-input) to apply |
| `labels` | List | List of custom labels |
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
| `bake-target` | String | Bake target name (default `docker-metadata-action`) |
### outputs ### outputs
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 |
| `json` | String | JSON output of tags and labels | | `json` | String | JSON output of tags and labels |
| `bake-file` | File | [Bake definition file](https://github.com/docker/buildx#file-definition) path | | `bake-file` | File | [Bake definition file](https://github.com/docker/buildx#file-definition) path |
## `images` input ## `images` input

View file

@ -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

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -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),

View file

@ -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;
} }