mirror of
https://github.com/docker/metadata-action.git
synced 2024-11-22 12:05: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
|
||||
uses: ./
|
||||
with:
|
||||
images: ${{ env.DOCKER_IMAGE }}
|
||||
images: |
|
||||
${{ env.DOCKER_IMAGE }}
|
||||
tags: |
|
||||
type=schedule
|
||||
type=ref,event=branch
|
||||
|
17
README.md
17
README.md
@ -126,7 +126,8 @@ jobs:
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: name/app
|
||||
images: |
|
||||
name/app
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
@ -203,7 +204,8 @@ jobs:
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: name/app
|
||||
images: |
|
||||
name/app
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
@ -265,14 +267,9 @@ Following inputs can be used as `step.with` keys
|
||||
> org.opencontainers.image.vendor=MyCompany
|
||||
> ```
|
||||
|
||||
> `CSV` type is a comma-delimited string
|
||||
> ```yaml
|
||||
> images: name/app,ghcr.io/name/app
|
||||
> ```
|
||||
|
||||
| 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 |
|
||||
| `flavor` | List | [Flavor](#flavor-input) to apply |
|
||||
| `labels` | List | List of custom labels |
|
||||
@ -285,7 +282,7 @@ Following inputs can be used as `step.with` keys
|
||||
Following outputs are available
|
||||
|
||||
| Name | Type | Description |
|
||||
|---------------|---------|---------------------------------------|
|
||||
|---------------|---------|-------------------------------------------------------------------------------|
|
||||
| `version` | String | Docker image version |
|
||||
| `tags` | String | Docker tags |
|
||||
| `labels` | String | Docker labels |
|
||||
|
@ -16,6 +16,22 @@ describe('transform', () => {
|
||||
] as Image[],
|
||||
false
|
||||
],
|
||||
[
|
||||
[
|
||||
`name/foo,name/bar`
|
||||
],
|
||||
[
|
||||
{
|
||||
name: `name/foo`,
|
||||
enable: true,
|
||||
},
|
||||
{
|
||||
name: `name/bar`,
|
||||
enable: true,
|
||||
}
|
||||
] as Image[],
|
||||
false
|
||||
],
|
||||
[
|
||||
[
|
||||
`name/foo`,
|
||||
@ -66,6 +82,9 @@ describe('transform', () => {
|
||||
],
|
||||
[
|
||||
[`name=,enable=true`], undefined, true
|
||||
],
|
||||
[
|
||||
[`name/foo,name=name/bar,enable=true`], undefined, true
|
||||
]
|
||||
])('given %p', async (l: string[], expected: Image[], invalid: boolean) => {
|
||||
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 {
|
||||
return {
|
||||
images: getInputList('images'),
|
||||
images: getInputList('images', true),
|
||||
tags: getInputList('tags', true),
|
||||
flavor: getInputList('flavor', true),
|
||||
labels: getInputList('labels', true),
|
||||
|
38
src/image.ts
38
src/image.ts
@ -1,4 +1,5 @@
|
||||
import {parse} from 'csv-parse/sync';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
export interface Image {
|
||||
name: string;
|
||||
@ -6,7 +7,33 @@ export interface 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) {
|
||||
const image: Image = {name: '', enable: true};
|
||||
const fields = parse(input, {
|
||||
@ -46,5 +73,14 @@ export function Transform(inputs: string[]): 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user