Skip to content

Commit

Permalink
github: annotate build warnings
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Jun 14, 2024
1 parent 931a895 commit aa26ffd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:

env:
NODE_VERSION: "20"
BUILDX_VERSION: "v0.15.0"
BUILDX_VERSION: "https://github.com/crazy-max/buildx.git#metadata-warnings"

jobs:
test:
Expand Down
8 changes: 8 additions & 0 deletions __tests__/fixtures/lint.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# syntax=docker/dockerfile-upstream:master
frOM busybox as base

Check warning on line 2 in __tests__/fixtures/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / test-itg (github.test.itg.ts, ubuntu-latest)

ConsistentInstructionCasing: Command 'frOM' should be consistently cased (line 2)

Instructions should be in consistent casing (all lower or all upper)
cOpy lint.Dockerfile .

Check warning on line 3 in __tests__/fixtures/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / test-itg (github.test.itg.ts, ubuntu-latest)

ConsistentInstructionCasing: Command 'cOpy' should be consistently cased (line 3)

Instructions should be in consistent casing (all lower or all upper)

from scratch
COPy --from=base \

Check warning on line 6 in __tests__/fixtures/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / test-itg (github.test.itg.ts, ubuntu-latest)

ConsistentInstructionCasing: Command 'COPy' should be consistently cased (line 6)

Instructions should be in consistent casing (all lower or all upper)
/lint.Dockerfile \
/
31 changes: 31 additions & 0 deletions __tests__/github.test.itg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,34 @@ maybe('writeBuildSummary', () => {
});
});
});

maybe('annotateBuildWarnings', () => {
it('annoate lint issues', async () => {
const buildx = new Buildx();
const build = new Build({buildx: buildx});

fs.mkdirSync(tmpDir, {recursive: true});
await expect(
(async () => {
// prettier-ignore
const buildCmd = await buildx.getCommand([
'--builder', process.env.CTN_BUILDER_NAME ?? 'default',
'build',
'-f', path.join(fixturesDir, 'lint.Dockerfile'),
fixturesDir,
'--metadata-file', build.getMetadataFilePath()
]);
await Exec.exec(buildCmd.command, buildCmd.args);
})()
).resolves.not.toThrow();

const metadata = build.resolveMetadata();
expect(metadata).toBeDefined();
const buildRef = build.resolveRef(metadata);
expect(buildRef).toBeDefined();
const buildStatus = build.resolveStatus(metadata);
expect(buildStatus).toBeDefined();

await GitHub.annotateBuildWarnings(path.join(fixturesDir, 'lint.Dockerfile'), buildStatus ?? {});
});
});
11 changes: 11 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {jwtDecode, JwtPayload} from 'jwt-decode';

import {Util} from './util';

import {SolveStatus} from './types/buildkit/client';
import {BuildSummaryOpts, GitHubActionsRuntimeToken, GitHubActionsRuntimeTokenAC, GitHubRepo, UploadArtifactOpts, UploadArtifactResponse} from './types/github';

export interface GitHubOpts {
Expand Down Expand Up @@ -281,4 +282,14 @@ export class GitHub {
core.info(`Writing summary`);
await sum.addSeparator().write();
}

public static async annotateBuildWarnings(source: string, st: SolveStatus): Promise<void> {
st.warnings?.forEach(warning => {
core.warning(warning.detail?.map(encoded => atob(encoded)).join(' ') || 'n/a', {
title: atob(warning.short) || 'Build warning',
file: source,
startLine: warning.range && warning.range.length > 0 ? warning.range[0]?.start.line : undefined
});
});
}
}

0 comments on commit aa26ffd

Please sign in to comment.