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 f0de040
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 14 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -39,6 +39,7 @@ ___
* [Notes](#notes)
* [Latest tag](#latest-tag)
* [Overwrite labels](#overwrite-labels)
* [Debug](#debug)
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
* [Contributing](#contributing)
* [License](#license)
Expand Down Expand Up @@ -573,6 +574,10 @@ labels generated are not suitable, you can overwrite them like this:
org.opencontainers.image.vendor=MyCompany
```
### Debug
For more details, please enable debug logs by [adding secret `ACTIONS_STEP_DEBUG=true`](https://docs.github.com/en/actions/managing-workflow-runs/enabling-debug-logging#enabling-step-debug-logging).
## Keep up-to-date with GitHub Dependabot
Since [Dependabot](https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-github-dependabot)
Expand Down
76 changes: 70 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 {
}
}

if (core.isDebug()) {
core.startGroup(`Parsing flavor input`);
core.debug([`latest=${flavor.latest}`, `prefix=${flavor.prefix}`, `suffix=${flavor.suffix}`].join(','));
core.endGroup();
}

return flavor;
}
37 changes: 29 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,16 @@ export function Transform(inputs: string[]): Tag[] {
}
return 0;
});

if (core.isDebug()) {
core.startGroup(`Parsing tags input`);
for (const tag of sorted) {
core.debug(tag.toString());
}
core.endGroup();
}

return sorted;
}

export function Parse(s: string): Tag {
Expand All @@ -62,10 +86,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 f0de040

Please sign in to comment.