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 e252202
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 14 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -43,6 +43,9 @@ jobs:
strategy:
fail-fast: false
matrix:
debug:
- ""
- "true"
tag-schedule:
- ""
- "cron-{{date 'YYYYMMDD'}}"
Expand All @@ -65,6 +68,8 @@ jobs:
type=ref,event=tag
type=ref,event=pr
type=sha
env:
RUNNER_DEBUG: ${{ matrix.debug }}

tag-match:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -102,6 +107,9 @@ jobs:
strategy:
fail-fast: false
matrix:
debug:
- ""
- "true"
flavor-latest:
- "auto"
- "true"
Expand All @@ -128,6 +136,8 @@ jobs:
type=sha
flavor: |
latest=${{ matrix.flavor-latest }}
env:
RUNNER_DEBUG: ${{ matrix.debug }}

flavor:
runs-on: ubuntu-latest
Expand Down
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
80 changes: 74 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 e252202

Please sign in to comment.