From de2365af33b297214817371552545c663ca68972 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:07:54 +0200 Subject: [PATCH] opt to disable build record upload Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- .github/workflows/ci.yml | 23 +++++++++++++++++++++++ README.md | 1 + src/main.ts | 32 +++++++++++++++++++++++++------- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 804ad0f36..dc0a46a89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1412,6 +1412,29 @@ jobs: with: file: ./test/Dockerfile + record-upload-disable: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + with: + path: action + - + 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: ./action + with: + file: ./test/Dockerfile + env: + DOCKER_BUILD_RECORD_UPLOAD: false + export-retention-days: runs-on: ubuntu-latest strategy: diff --git a/README.md b/README.md index 8514a792e..77c0ef342 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,7 @@ The following outputs are available: | Name | Type | Default | Description | |--------------------------------------|--------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `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_EXPORT_RETENTION_DAYS` | Number | | Duration after which build export 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` | ## Troubleshooting diff --git a/src/main.ts b/src/main.ts index 769a97412..5e91d69aa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,6 +15,7 @@ import {Util} from '@docker/actions-toolkit/lib/util'; import {BuilderInfo} from '@docker/actions-toolkit/lib/types/buildx/builder'; import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker/docker'; +import {UploadArtifactResponse} from '@docker/actions-toolkit/lib/types/github'; import * as context from './context'; @@ -163,17 +164,27 @@ actionsToolkit.run( if (stateHelper.isSummarySupported) { await core.group(`Generating build summary`, async () => { try { - const exportRetentionDays = buildExportRetentionDays(); + const recordUploadEnabled = buildRecordUploadEnabled(); + let exportRetentionDays: number | undefined; + if (recordUploadEnabled) { + exportRetentionDays = buildExportRetentionDays(); + } + const buildxHistory = new BuildxHistory(); const exportRes = await buildxHistory.export({ refs: stateHelper.buildRef ? [stateHelper.buildRef] : [] }); - core.info(`Build record exported to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`); - const uploadRes = await GitHub.uploadArtifact({ - filename: exportRes.dockerbuildFilename, - mimeType: 'application/gzip', - retentionDays: exportRetentionDays - }); + core.info(`Build record written to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`); + + let uploadRes: UploadArtifactResponse | undefined; + if (recordUploadEnabled) { + uploadRes = await GitHub.uploadArtifact({ + filename: exportRes.dockerbuildFilename, + mimeType: 'application/gzip', + retentionDays: exportRetentionDays + }); + } + await GitHub.writeBuildSummary({ exportRes: exportRes, uploadRes: uploadRes, @@ -221,6 +232,13 @@ function buildSummaryEnabled(): boolean { return true; } +function buildRecordUploadEnabled(): boolean { + if (process.env.DOCKER_BUILD_RECORD_UPLOAD) { + return Util.parseBool(process.env.DOCKER_BUILD_RECORD_UPLOAD); + } + return true; +} + function buildExportRetentionDays(): number | undefined { if (process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS) { const res = parseInt(process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS);