From 5effddc685482f50585ea749a2c44022f346c77e Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Wed, 31 Jul 2024 12:06:56 +0200 Subject: [PATCH] generate GitHub annotations for build checks Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- .github/workflows/ci.yml | 27 +++++++++++++++++++++++++++ src/main.ts | 16 +++++++++++++++- test/lint-other.Dockerfile | 10 ++++++++++ test/lint.Dockerfile | 12 ++++++++++++ test/lint.hcl | 12 ++++++++++++ 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 test/lint-other.Dockerfile create mode 100644 test/lint.Dockerfile create mode 100644 test/lint.hcl diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb5ea3c..4766ca0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/src/main.ts b/src/main.ts index 266928d..3240521 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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; }; @@ -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'); diff --git a/test/lint-other.Dockerfile b/test/lint-other.Dockerfile new file mode 100644 index 0000000..ca732ca --- /dev/null +++ b/test/lint-other.Dockerfile @@ -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 \ + / diff --git a/test/lint.Dockerfile b/test/lint.Dockerfile new file mode 100644 index 0000000..0d14d88 --- /dev/null +++ b/test/lint.Dockerfile @@ -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 diff --git a/test/lint.hcl b/test/lint.hcl new file mode 100644 index 0000000..d429ec1 --- /dev/null +++ b/test/lint.hcl @@ -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\"]" +}