Skip to content

Commit

Permalink
generate GitHub annotations for build checks
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 Jul 31, 2024
1 parent 28c6eb5 commit 5effddc
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,30 @@ jobs:
targets: app
env:
DOCKER_BUILD_RECORD_RETENTION_DAYS: ${{ matrix.days }}

checks:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
buildx-version:
- latest
- v0.14.1
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ matrix.buildx-version }}
driver-opts: |
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
-
name: Build
uses: ./
with:
workdir: ./test
files: |
./test/lint.hcl
16 changes: 15 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ actionsToolkit.run(
const args: string[] = await context.getArgs(inputs, definition, toolkit);
const buildCmd = await toolkit.buildx.getCommand(args);
const buildEnv = Object.assign({}, process.env, {
BUILDX_BAKE_GIT_AUTH_TOKEN: gitAuthToken
BUILDX_BAKE_GIT_AUTH_TOKEN: gitAuthToken,
BUILDX_METADATA_WARNINGS: 'true'
}) as {
[key: string]: string;
};
Expand Down Expand Up @@ -164,6 +165,19 @@ actionsToolkit.run(
}
});

const warnings = toolkit.buildxBake.resolveWarnings(metadata);
if (refs.length > 0 && warnings && warnings.length > 0) {
const annotations = await Buildx.convertWarningsToGitHubAnnotations(warnings, refs);
core.debug(`annotations: ${JSON.stringify(annotations, null, 2)}`);
if (annotations && annotations.length > 0) {
await core.group(`Generating GitHub annotations (${annotations.length} build checks found)`, async () => {
for (const annotation of annotations) {
core.warning(annotation.message, annotation);
}
});
}
}

await core.group(`Check build summary support`, async () => {
if (!buildSummaryEnabled()) {
core.info('Build summary disabled');
Expand Down
10 changes: 10 additions & 0 deletions test/lint-other.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
frOM busybox as base
cOpy lint-other.Dockerfile .

froM busybox aS notused
COPY lint-other.Dockerfile .

from scratch
COPy --from=base \
/lint-other.Dockerfile \
/
12 changes: 12 additions & 0 deletions test/lint.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
frOM busybox as base
cOpy lint.Dockerfile .

from scratch
MAINTAINER moby@example.com
COPy --from=base \
/lint.Dockerfile \
/

CMD [ "echo", "Hello, Norway!" ]
CMD [ "echo", "Hello, Sweden!" ]
ENTRYPOINT my-program start
12 changes: 12 additions & 0 deletions test/lint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
group "default" {
targets = ["lint", "lint-other", "lint-inline"]
}
target "lint" {
dockerfile = "lint.Dockerfile"
}
target "lint-other" {
dockerfile = "lint-other.Dockerfile"
}
target "lint-inline" {
dockerfile-inline = "FRoM alpine\nENTRYPOINT [\"echo\", \"hello\"]"
}

0 comments on commit 5effddc

Please sign in to comment.