diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33d3e26..6c3d857 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -536,7 +536,6 @@ jobs: version: ${{ inputs.buildx-version || env.BUILDX_VERSION }} driver-opts: | image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }} - network=host - name: Build uses: ./ @@ -546,3 +545,32 @@ jobs: targets: app env: DOCKER_BUILD_NO_SUMMARY: true + + export-retention-days: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + days: + - 2 + - 0 + 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: + files: | + ./test/config.hcl + targets: app + env: + DOCKER_BUILD_EXPORT_RETENTION_DAYS: ${{ matrix.days }} diff --git a/README.md b/README.md index 2653e7c..959ae59 100644 --- a/README.md +++ b/README.md @@ -258,9 +258,10 @@ The following outputs are available ### environment variables -| Name | Type | Description | -|---------------------------|------|-------------------------------------------------------------------------------------------------------------------| -| `DOCKER_BUILD_NO_SUMMARY` | Bool | If `true`, [build summary](https://docs.docker.com/build/ci/github-actions/build-summary/) generation is disabled | +| Name | Type | Description | +|--------------------------------------|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `DOCKER_BUILD_NO_SUMMARY` | Bool | If `true`, [build summary](https://docs.docker.com/build/ci/github-actions/build-summary/) generation 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` | ## Contributing diff --git a/src/main.ts b/src/main.ts index ce675b8..4ffc9d3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -176,6 +176,7 @@ actionsToolkit.run( return; } try { + const exportRetentionDays = buildExportRetentionDays(); const buildxHistory = new BuildxHistory(); const exportRes = await buildxHistory.export({ refs: stateHelper.buildRefs @@ -184,7 +185,7 @@ actionsToolkit.run( const uploadRes = await GitHub.uploadArtifact({ filename: exportRes.dockerbuildFilename, mimeType: 'application/gzip', - retentionDays: 90 + retentionDays: exportRetentionDays }); await GitHub.writeBuildSummary({ exportRes: exportRes, @@ -229,3 +230,13 @@ async function buildRefs(toolkit: Toolkit, since: Date, builder?: string): Promi } return refs; } + +function buildExportRetentionDays(): number | undefined { + if (process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS) { + const res = parseInt(process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS); + if (isNaN(res)) { + throw Error(`Invalid build export retention days: ${process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS}`); + } + return res; + } +}