From bc6f04190c9c5f38fd3920a841b8481554be5880 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Wed, 31 Jul 2024 14:24:42 +0200 Subject: [PATCH] opt to disable github annotations generation for build checks Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- .github/workflows/ci.yml | 23 +++++++++++++++++++++++ README.md | 1 + src/main.ts | 29 +++++++++++++++++++---------- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80d2012..ead1af4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -668,3 +668,26 @@ jobs: workdir: ./test files: | ./lint.hcl + + annotations-disabled: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + version: ${{ inputs.buildx-version || env.BUILDX_VERSION }} + driver-opts: | + image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }} + - + name: Build + uses: ./ + with: + workdir: ./test + files: | + ./lint.hcl + env: + DOCKER_BUILD_CHECKS_ANNOTATIONS: false diff --git a/README.md b/README.md index 9d70880..7e89d91 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,7 @@ The following outputs are available | Name | Type | Default | Description | |--------------------------------------|--------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `DOCKER_BUILD_CHECKS_ANNOTATIONS` | Bool | `true` | If `false`, GitHub annotations are not generated for [build checks](https://docs.docker.com/build/checks/) | | `DOCKER_BUILD_SUMMARY` | Bool | `true` | If `false`, [build summary](https://docs.docker.com/build/ci/github-actions/build-summary/) generation is disabled | | `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 | | `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` | diff --git a/src/main.ts b/src/main.ts index 3240521..e93b947 100644 --- a/src/main.ts +++ b/src/main.ts @@ -165,16 +165,18 @@ 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); - } - }); + if (buildChecksAnnotationsEnabled()) { + 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); + } + }); + } } } @@ -269,6 +271,13 @@ async function buildRefs(toolkit: Toolkit, since: Date, builder?: string): Promi return refs; } +function buildChecksAnnotationsEnabled(): boolean { + if (process.env.DOCKER_BUILD_CHECKS_ANNOTATIONS) { + return Util.parseBool(process.env.DOCKER_BUILD_CHECKS_ANNOTATIONS); + } + return true; +} + function buildSummaryEnabled(): boolean { if (process.env.DOCKER_BUILD_NO_SUMMARY) { core.warning('DOCKER_BUILD_NO_SUMMARY is deprecated. Set DOCKER_BUILD_SUMMARY to false instead.');