Skip to content

Commit 2f4dd14

Browse files
committed
backward compatibility with old images format
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
1 parent a5680a6 commit 2f4dd14

7 files changed

Lines changed: 80 additions & 27 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ jobs:
241241
id: docker_meta
242242
uses: ./
243243
with:
244-
images: ${{ env.DOCKER_IMAGE }}
244+
images: |
245+
${{ env.DOCKER_IMAGE }}
245246
tags: |
246247
type=schedule
247248
type=ref,event=branch

README.md

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ jobs:
126126
id: meta
127127
uses: docker/metadata-action@v3
128128
with:
129-
images: name/app
129+
images: |
130+
name/app
130131
tags: |
131132
type=ref,event=branch
132133
type=ref,event=pr
@@ -203,7 +204,8 @@ jobs:
203204
id: meta
204205
uses: docker/metadata-action@v3
205206
with:
206-
images: name/app
207+
images: |
208+
name/app
207209
tags: |
208210
type=ref,event=branch
209211
type=ref,event=pr
@@ -265,31 +267,26 @@ Following inputs can be used as `step.with` keys
265267
> org.opencontainers.image.vendor=MyCompany
266268
> ```
267269

268-
> `CSV` type is a comma-delimited string
269-
> ```yaml
270-
> images: name/app,ghcr.io/name/app
271-
> ```
272-
273-
| Name | Type | Description |
274-
|---------------------|----------|------------------------------------|
275-
| `images` | List/CSV | List of Docker images to use as base name for tags |
276-
| `tags` | List | List of [tags](#tags-input) as key-value pair attributes |
277-
| `flavor` | List | [Flavor](#flavor-input) to apply |
278-
| `labels` | List | List of custom labels |
279-
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
280-
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
281-
| `bake-target` | String | Bake target name (default `docker-metadata-action`) |
270+
| Name | Type | Description |
271+
|---------------------|--------|----------------------------------------------------------|
272+
| `images` | List | List of Docker images to use as base name for tags |
273+
| `tags` | List | List of [tags](#tags-input) as key-value pair attributes |
274+
| `flavor` | List | [Flavor](#flavor-input) to apply |
275+
| `labels` | List | List of custom labels |
276+
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
277+
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
278+
| `bake-target` | String | Bake target name (default `docker-metadata-action`) |
282279

283280
### outputs
284281

285282
Following outputs are available
286283

287-
| Name | Type | Description |
288-
|---------------|---------|---------------------------------------|
289-
| `version` | String | Docker image version |
290-
| `tags` | String | Docker tags |
291-
| `labels` | String | Docker labels |
292-
| `json` | String | JSON output of tags and labels |
284+
| Name | Type | Description |
285+
|---------------|---------|-------------------------------------------------------------------------------|
286+
| `version` | String | Docker image version |
287+
| `tags` | String | Docker tags |
288+
| `labels` | String | Docker labels |
289+
| `json` | String | JSON output of tags and labels |
293290
| `bake-file` | File | [Bake definition file](https://github.com/docker/buildx#file-definition) path |
294291

295292
## `images` input

__tests__/image.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ describe('transform', () => {
1616
] as Image[],
1717
false
1818
],
19+
[
20+
[
21+
`name/foo,name/bar`
22+
],
23+
[
24+
{
25+
name: `name/foo`,
26+
enable: true,
27+
},
28+
{
29+
name: `name/bar`,
30+
enable: true,
31+
}
32+
] as Image[],
33+
false
34+
],
1935
[
2036
[
2137
`name/foo`,
@@ -66,6 +82,9 @@ describe('transform', () => {
6682
],
6783
[
6884
[`name=,enable=true`], undefined, true
85+
],
86+
[
87+
[`name/foo,name=name/bar,enable=true`], undefined, true
6988
]
7089
])('given %p', async (l: string[], expected: Image[], invalid: boolean) => {
7190
try {

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function tmpDir(): string {
2727

2828
export function getInputs(): Inputs {
2929
return {
30-
images: getInputList('images'),
30+
images: getInputList('images', true),
3131
tags: getInputList('tags', true),
3232
flavor: getInputList('flavor', true),
3333
labels: getInputList('labels', true),

src/image.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
11
import {parse} from 'csv-parse/sync';
2+
import * as core from '@actions/core';
23

34
export interface Image {
45
name: string;
56
enable: boolean;
67
}
78

89
export function Transform(inputs: string[]): Image[] {
9-
const images: Image[] = [];
10+
let images: Image[] = [];
11+
12+
// backward compatibility with old format
13+
if (inputs.length == 1) {
14+
let newformat = false;
15+
const fields = parse(inputs[0], {
16+
relaxColumnCount: true,
17+
skipEmptyLines: true
18+
})[0];
19+
for (const field of fields) {
20+
const parts = field
21+
.toString()
22+
.split('=')
23+
.map(item => item.trim());
24+
if (parts.length == 1) {
25+
images.push({name: parts[0].toLowerCase(), enable: true});
26+
} else {
27+
newformat = true;
28+
break;
29+
}
30+
}
31+
if (!newformat) {
32+
return output(images);
33+
}
34+
}
35+
36+
images = [];
1037
for (const input of inputs) {
1138
const image: Image = {name: '', enable: true};
1239
const fields = parse(input, {
@@ -46,5 +73,14 @@ export function Transform(inputs: string[]): Image[] {
4673
}
4774
images.push(image);
4875
}
76+
return output(images);
77+
}
78+
79+
function output(images: Image[]): Image[] {
80+
core.startGroup(`Processing images input`);
81+
for (const image of images) {
82+
core.info(`name=${image.name},enable=${image.enable}`);
83+
}
84+
core.endGroup();
4985
return images;
5086
}

0 commit comments

Comments
 (0)