Skip to content

Commit

Permalink
Improve debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Apr 3, 2021
1 parent 1a8a264 commit 6b03dad
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -94,7 +94,7 @@ jobs:
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=match,"pattern=${{ matrix.tag-match }}",group=${{ matrix.tag-match-group }}
type=match,pattern=${{ matrix.tag-match }},group=${{ matrix.tag-match-group }}
type=sha
tag-semver:
Expand Down
2 changes: 1 addition & 1 deletion __tests__/tag.test.ts
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{1,3}.\\d{1,3}.\\d{1,3}",group=0`
],
[
{
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
@@ -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
@@ -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

0 comments on commit 6b03dad

Please sign in to comment.