Skip to content

Commit

Permalink
use default retention days for build export artifact
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Jun 24, 2024
1 parent 31159d4 commit 9cac6c8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1367,3 +1367,32 @@ jobs:
file: ./test/Dockerfile
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
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_EXPORT_RETENTION_DAYS: ${{ matrix.days }}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,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` |

## Troubleshooting

Expand Down
13 changes: 12 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ actionsToolkit.run(
return;
}
try {
const exportRetentionDays = buildExportRetentionDays();
const buildxHistory = new BuildxHistory();
const exportRes = await buildxHistory.export({
refs: [stateHelper.buildRef]
Expand All @@ -159,7 +160,7 @@ actionsToolkit.run(
const uploadRes = await GitHub.uploadArtifact({
filename: exportRes.dockerbuildFilename,
mimeType: 'application/gzip',
retentionDays: 90
retentionDays: exportRetentionDays
});
await GitHub.writeBuildSummary({
exportRes: exportRes,
Expand Down Expand Up @@ -197,3 +198,13 @@ async function buildRef(toolkit: Toolkit, since: Date, builder?: string): Promis
});
return Object.keys(refs).length > 0 ? Object.keys(refs)[0] : '';
}

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;
}
}

0 comments on commit 9cac6c8

Please sign in to comment.