Skip to content

Commit 955c005

Browse files
authored
Merge pull request #238 from crazy-max/build-checks
generate GitHub annotations for build checks
2 parents 28c6eb5 + 4c69466 commit 955c005

File tree

8 files changed

+111
-3
lines changed

8 files changed

+111
-3
lines changed

.github/workflows/ci.yml

+50
Original file line numberDiff line numberDiff line change
@@ -641,3 +641,53 @@ jobs:
641641
targets: app
642642
env:
643643
DOCKER_BUILD_RECORD_RETENTION_DAYS: ${{ matrix.days }}
644+
645+
checks:
646+
runs-on: ubuntu-latest
647+
strategy:
648+
fail-fast: false
649+
matrix:
650+
buildx-version:
651+
- latest
652+
- v0.14.1
653+
steps:
654+
-
655+
name: Checkout
656+
uses: actions/checkout@v4
657+
-
658+
name: Set up Docker Buildx
659+
uses: docker/setup-buildx-action@v3
660+
with:
661+
version: ${{ matrix.buildx-version }}
662+
driver-opts: |
663+
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
664+
-
665+
name: Build
666+
uses: ./
667+
with:
668+
workdir: ./test
669+
files: |
670+
./lint.hcl
671+
672+
annotations-disabled:
673+
runs-on: ubuntu-latest
674+
steps:
675+
-
676+
name: Checkout
677+
uses: actions/checkout@v4
678+
-
679+
name: Set up Docker Buildx
680+
uses: docker/setup-buildx-action@v3
681+
with:
682+
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
683+
driver-opts: |
684+
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
685+
-
686+
name: Build
687+
uses: ./
688+
with:
689+
workdir: ./test
690+
files: |
691+
./lint.hcl
692+
env:
693+
DOCKER_BUILD_CHECKS_ANNOTATIONS: false

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ The following outputs are available
208208

209209
| Name | Type | Default | Description |
210210
|--------------------------------------|--------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
211+
| `DOCKER_BUILD_CHECKS_ANNOTATIONS` | Bool | `true` | If `false`, GitHub annotations are not generated for [build checks](https://docs.docker.com/build/checks/) |
211212
| `DOCKER_BUILD_SUMMARY` | Bool | `true` | If `false`, [build summary](https://docs.docker.com/build/ci/github-actions/build-summary/) generation is disabled |
212213
| `DOCKER_BUILD_RECORD_UPLOAD` | Bool | `true` | If `false`, build record upload as [GitHub artifact](https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts) is disabled |
213214
| `DOCKER_BUILD_RECORD_RETENTION_DAYS` | Number | | Duration after which build record artifact will expire in days. Defaults to repository/org [retention settings](https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration#artifact-and-log-retention-policy) if unset or `0` |

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ actionsToolkit.run(
119119
const args: string[] = await context.getArgs(inputs, definition, toolkit);
120120
const buildCmd = await toolkit.buildx.getCommand(args);
121121
const buildEnv = Object.assign({}, process.env, {
122-
BUILDX_BAKE_GIT_AUTH_TOKEN: gitAuthToken
122+
BUILDX_BAKE_GIT_AUTH_TOKEN: gitAuthToken,
123+
BUILDX_METADATA_WARNINGS: 'true'
123124
}) as {
124125
[key: string]: string;
125126
};
@@ -164,6 +165,21 @@ actionsToolkit.run(
164165
}
165166
});
166167

168+
if (buildChecksAnnotationsEnabled()) {
169+
const warnings = toolkit.buildxBake.resolveWarnings(metadata);
170+
if (refs.length > 0 && warnings && warnings.length > 0) {
171+
const annotations = await Buildx.convertWarningsToGitHubAnnotations(warnings, refs);
172+
core.debug(`annotations: ${JSON.stringify(annotations, null, 2)}`);
173+
if (annotations && annotations.length > 0) {
174+
await core.group(`Generating GitHub annotations (${annotations.length} build checks found)`, async () => {
175+
for (const annotation of annotations) {
176+
core.warning(annotation.message, annotation);
177+
}
178+
});
179+
}
180+
}
181+
}
182+
167183
await core.group(`Check build summary support`, async () => {
168184
if (!buildSummaryEnabled()) {
169185
core.info('Build summary disabled');
@@ -255,6 +271,13 @@ async function buildRefs(toolkit: Toolkit, since: Date, builder?: string): Promi
255271
return refs;
256272
}
257273

274+
function buildChecksAnnotationsEnabled(): boolean {
275+
if (process.env.DOCKER_BUILD_CHECKS_ANNOTATIONS) {
276+
return Util.parseBool(process.env.DOCKER_BUILD_CHECKS_ANNOTATIONS);
277+
}
278+
return true;
279+
}
280+
258281
function buildSummaryEnabled(): boolean {
259282
if (process.env.DOCKER_BUILD_NO_SUMMARY) {
260283
core.warning('DOCKER_BUILD_NO_SUMMARY is deprecated. Set DOCKER_BUILD_SUMMARY to false instead.');

test/lint-other.Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
frOM busybox as base
2+
cOpy lint-other.Dockerfile .
3+
4+
froM busybox aS notused
5+
COPY lint-other.Dockerfile .
6+
7+
from scratch
8+
COPy --from=base \
9+
/lint-other.Dockerfile \
10+
/

test/lint.Dockerfile

+12
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

test/lint.hcl

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
group "default" {
2+
targets = ["lint", "lint-other", "lint-inline"]
3+
}
4+
target "lint" {
5+
dockerfile = "lint.Dockerfile"
6+
}
7+
target "lint-other" {
8+
dockerfile = "lint-other.Dockerfile"
9+
}
10+
target "lint-inline" {
11+
dockerfile-inline = "FRoM alpine\nENTRYPOINT [\"echo\", \"hello\"]"
12+
}

0 commit comments

Comments
 (0)