Skip to content

Commit 806a2a4

Browse files
committed
generate GitHub annotations for build checks
Signed-off-by: CrazyMax <[email protected]>
1 parent a8d3541 commit 806a2a4

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,3 +1463,29 @@ jobs:
14631463
file: ./test/Dockerfile
14641464
env:
14651465
DOCKER_BUILD_RECORD_RETENTION_DAYS: ${{ matrix.days }}
1466+
1467+
checks:
1468+
runs-on: ubuntu-latest
1469+
strategy:
1470+
fail-fast: false
1471+
matrix:
1472+
buildx-version:
1473+
- latest
1474+
- v0.14.1
1475+
steps:
1476+
-
1477+
name: Checkout
1478+
uses: actions/checkout@v4
1479+
-
1480+
name: Set up Docker Buildx
1481+
uses: docker/setup-buildx-action@v3
1482+
with:
1483+
version: ${{ matrix.buildx-version }}
1484+
driver-opts: |
1485+
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
1486+
-
1487+
name: Build
1488+
uses: ./
1489+
with:
1490+
context: ./test
1491+
file: ./test/lint.Dockerfile

src/main.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ actionsToolkit.run(
9797

9898
let err: Error | undefined;
9999
await Exec.getExecOutput(buildCmd.command, buildCmd.args, {
100-
ignoreReturnCode: true
100+
ignoreReturnCode: true,
101+
env: Object.assign({}, process.env, {
102+
BUILDX_METADATA_WARNINGS: 'true'
103+
}) as {
104+
[key: string]: string;
105+
}
101106
}).then(res => {
102107
if (res.stderr.length > 0 && res.exitCode != 0) {
103108
err = Error(`buildx failed with: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
@@ -106,7 +111,7 @@ actionsToolkit.run(
106111

107112
const imageID = toolkit.buildxBuild.resolveImageID();
108113
const metadata = toolkit.buildxBuild.resolveMetadata();
109-
const digest = toolkit.buildxBuild.resolveDigest();
114+
const digest = toolkit.buildxBuild.resolveDigest(metadata);
110115
if (imageID) {
111116
await core.group(`ImageID`, async () => {
112117
core.info(imageID);
@@ -127,7 +132,7 @@ actionsToolkit.run(
127132
});
128133
}
129134

130-
let ref: string;
135+
let ref: string | undefined;
131136
await core.group(`Reference`, async () => {
132137
ref = await buildRef(toolkit, startedTime, inputs.builder);
133138
if (ref) {
@@ -138,6 +143,19 @@ actionsToolkit.run(
138143
}
139144
});
140145

146+
const warnings = toolkit.buildxBuild.resolveWarnings(metadata);
147+
if (ref && warnings && warnings.length > 0) {
148+
const annotations = await Buildx.convertWarningsToGitHubAnnotations(warnings, [ref]);
149+
core.debug(`annotations: ${JSON.stringify(annotations, null, 2)}`);
150+
if (annotations && annotations.length > 0) {
151+
await core.group(`Generating GitHub annotations (${annotations.length} build checks found)`, async () => {
152+
for (const annotation of annotations) {
153+
core.warning(annotation.message, annotation);
154+
}
155+
});
156+
}
157+
}
158+
141159
await core.group(`Check build summary support`, async () => {
142160
if (!buildSummaryEnabled()) {
143161
core.info('Build summary disabled');

test/lint.Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
frOM busybox as base
2+
cOpy lint.Dockerfile .
3+
4+
from scratch
5+
6+
COPy --from=base \
7+
/lint.Dockerfile \
8+
/
9+
10+
CMD [ "echo", "Hello, Norway!" ]
11+
CMD [ "echo", "Hello, Sweden!" ]
12+
ENTRYPOINT my-program start

0 commit comments

Comments
 (0)