Skip to content

Improve logging #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ jobs:
fail-fast: false
matrix:
include:
- tag-match: '\d{1,3}.\d{1,3}.\d{1,3}'
- tag-match: '\d.\d.\d'
tag-match-group: '0'
- tag-match: '\d{1,3}.\d{1,3}'
- tag-match: '\d.\d'
tag-match-group: '0'
- tag-match: 'v(.*)'
tag-match-group: '1'
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,7 @@ tags: |
```yaml
tags: |
# minimal
type=match,pattern=\d{8}
# double quotes if comma in pattern
type=match,"pattern=\d{1,3}.\d{1,3}.\d{1,3}"
type=match,pattern=\d.\d.\d
# define match group
type=match,pattern=v(.*),group=1
# use custom value instead of git tag
Expand All @@ -435,7 +433,7 @@ a custom value through `value` attribute.

| Git tag | Pattern | Group | Output |
|-------------------------|-------------------------------|---------|------------------------|
| `v1.2.3` | `\d{1,3}.\d{1,3}.\d{1,3}` | `0` | `1.2.3` |
| `v1.2.3` | `\d.\d.\d` | `0` | `1.2.3` |
| `v2.0.8-beta.67` | `v(.*)` | `1` | `2.0.8-beta.67` |
| `v2.0.8-beta.67` | `v(\d.\d)` | `1` | `2.0` |
| `20200110-RC2` | `\d+` | `0` | `20200110` |
Expand Down
18 changes: 9 additions & 9 deletions __tests__/meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ describe('tag', () => {
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,"pattern=\\d{1,3}.\\d{1,3}.\\d{1,3}"`
`type=match,"pattern=\\d.\\d.\\d"`
]
} as Inputs,
{
Expand Down Expand Up @@ -744,7 +744,7 @@ describe('tag', () => {
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,"pattern=^v(\\d{1,3}.\\d{1,3}.\\d{1,3})$",group=1`
`type=match,"pattern=^v(\\d.\\d.\\d)$",group=1`
]
} as Inputs,
{
Expand Down Expand Up @@ -775,7 +775,7 @@ describe('tag', () => {
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,"pattern=\\d{1,3}.\\d{1,3}.\\d{1,3}-(alpha|beta).\\d{1,3}"`
`type=match,"pattern=\\d.\\d.\\d-(alpha|beta).\\d+"`
]
} as Inputs,
{
Expand Down Expand Up @@ -806,7 +806,7 @@ describe('tag', () => {
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,"pattern=\\d{1,3}.\\d{1,3}"`
`type=match,"pattern=\\d.\\d"`
]
} as Inputs,
{
Expand Down Expand Up @@ -837,7 +837,7 @@ describe('tag', () => {
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,"pattern=/^v(\\d{1,3}.\\d{1,3}.\\d{1,3})$/ig",group=1`,
`type=match,"pattern=/^v(\\d.\\d.\\d)$/ig",group=1`,
]
} as Inputs,
{
Expand Down Expand Up @@ -866,7 +866,7 @@ describe('tag', () => {
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,"pattern=\\d{1,3}.\\d{1,3}"`
`type=match,"pattern=\\d.\\d"`
]
} as Inputs,
{
Expand Down Expand Up @@ -1030,7 +1030,7 @@ describe('tag', () => {
tags: [
`type=raw,priority=2000,foo`,
`type=semver,pattern={{version}}`,
`type=match,"pattern=\\d{1,3}.\\d{1,3}"`
`type=match,"pattern=\\d.\\d"`
]
} as Inputs,
{
Expand Down Expand Up @@ -1189,7 +1189,7 @@ describe('latest', () => {
{
images: ['user/app'],
tags: [
`type=match,"pattern=\\d{1,3}.\\d{1,3}.\\d{1,3}"`
`type=match,"pattern=\\d.\\d.\\d"`
]
} as Inputs,
{
Expand Down Expand Up @@ -1246,7 +1246,7 @@ describe('latest', () => {
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,"pattern=\\d{1,3}.\\d{1,3}.\\d{1,3}"`
`type=match,"pattern=\\d.\\d.\\d"`
]
} as Inputs,
{
Expand Down
8 changes: 4 additions & 4 deletions __tests__/tag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('transform', () => {
`type=raw,foo`,
`type=edge`,
`type=semver,pattern={{version}}`,
`type=match,"pattern=\\d{1,3}.\\d{1,3}.\\d{1,3}"`
`type=match,"pattern=\\d.\\d.\\d",group=0`
],
[
{
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('transform', () => {
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "\\d{1,3}.\\d{1,3}.\\d{1,3}",
"pattern": "\\d.\\d.\\d",
"group": "0",
"value": ""
}
Expand Down Expand Up @@ -204,15 +204,15 @@ describe('parse', () => {
false
],
[
`type=match,enable=true,"pattern=^v(\\d{1,3}.\\d{1,3}.\\d{1,3})$",group=1`,
`type=match,enable=true,"pattern=^v(\\d.\\d.\\d)$",group=1`,
{
type: Type.Match,
attrs: {
"priority": DefaultPriorities[Type.Match],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "^v(\\d{1,3}.\\d{1,3}.\\d{1,3})$",
"pattern": "^v(\\d.\\d.\\d)$",
"group": "1",
"value": ""
}
Expand Down
74 changes: 68 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/flavor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as core from '@actions/core';

export interface Flavor {
latest: string;
prefix: string;
Expand Down Expand Up @@ -38,5 +40,11 @@ export function Transform(inputs: string[]): Flavor {
}
}

core.startGroup(`Processing flavor input`);
core.info(`latest=${flavor.latest}`);
core.info(`prefix=${flavor.prefix}`);
core.info(`suffix=${flavor.suffix}`);
core.endGroup();

return flavor;
}
35 changes: 27 additions & 8 deletions src/tag.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import csvparse from 'csv-parse/lib/sync';
import * as core from '@actions/core';

export enum Type {
Schedule = 'schedule',
Expand All @@ -16,9 +17,21 @@ export enum RefEvent {
PR = 'pr'
}

export interface Tag {
type: Type;
attrs: Record<string, string>;
export class Tag {
public type?: Type;
public attrs: Record<string, string>;

constructor() {
this.attrs = {};
}

public toString(): string {
const out: string[] = [`type=${this.type}`];
for (let attr in this.attrs) {
out.push(`${attr}=${this.attrs[attr]}`);
}
return out.join(',');
}
}

export const DefaultPriorities: Record<Type, string> = {
Expand All @@ -42,10 +55,11 @@ export function Transform(inputs: string[]): Tag[] {
`type=ref,event=${RefEvent.PR}`
];
}

for (const input of inputs) {
tags.push(Parse(input));
}
return tags.sort((tag1, tag2) => {
const sorted = tags.sort((tag1, tag2) => {
if (Number(tag1.attrs['priority']) < Number(tag2.attrs['priority'])) {
return 1;
}
Expand All @@ -54,6 +68,14 @@ export function Transform(inputs: string[]): Tag[] {
}
return 0;
});

core.startGroup(`Processing tags input`);
for (const tag of sorted) {
core.info(tag.toString());
}
core.endGroup();

return sorted;
}

export function Parse(s: string): Tag {
Expand All @@ -62,10 +84,7 @@ export function Parse(s: string): Tag {
skipLinesWithEmptyValues: true
})[0];

const tag = {
attrs: {}
} as Tag;

const tag = new Tag();
for (const field of fields) {
const parts = field.toString().split('=', 2);
if (parts.length == 1) {
Expand Down