3
0
Fork 0
mirror of https://gitea.com/docker/build-push-action.git synced 2024-11-25 19:09:40 +01:00

Merge pull request #1153 from crazy-max/export-retention

use default retention days for build export artifact
This commit is contained in:
CrazyMax 2024-06-26 14:00:48 +02:00 committed by GitHub
commit 9476c25b2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 47 additions and 6 deletions

View file

@ -1367,3 +1367,32 @@ jobs:
file: ./test/Dockerfile file: ./test/Dockerfile
env: env:
DOCKER_BUILD_NO_SUMMARY: true 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 }}

View file

@ -259,9 +259,10 @@ The following outputs are available:
### environment variables ### environment variables
| Name | Type | Description | | 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_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 ## Troubleshooting

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -151,6 +151,7 @@ actionsToolkit.run(
return; return;
} }
try { try {
const exportRetentionDays = buildExportRetentionDays();
const buildxHistory = new BuildxHistory(); const buildxHistory = new BuildxHistory();
const exportRes = await buildxHistory.export({ const exportRes = await buildxHistory.export({
refs: [stateHelper.buildRef] refs: [stateHelper.buildRef]
@ -159,7 +160,7 @@ actionsToolkit.run(
const uploadRes = await GitHub.uploadArtifact({ const uploadRes = await GitHub.uploadArtifact({
filename: exportRes.dockerbuildFilename, filename: exportRes.dockerbuildFilename,
mimeType: 'application/gzip', mimeType: 'application/gzip',
retentionDays: 90 retentionDays: exportRetentionDays
}); });
await GitHub.writeBuildSummary({ await GitHub.writeBuildSummary({
exportRes: exportRes, exportRes: exportRes,
@ -197,3 +198,13 @@ async function buildRef(toolkit: Toolkit, since: Date, builder?: string): Promis
}); });
return Object.keys(refs).length > 0 ? Object.keys(refs)[0] : ''; 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;
}
}