Skip to content

Commit 9476c25

Browse files
authored
Merge pull request #1153 from crazy-max/export-retention
use default retention days for build export artifact
2 parents 31159d4 + 97be5a4 commit 9476c25

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

.github/workflows/ci.yml

+29
Original file line numberDiff line numberDiff line change
@@ -1367,3 +1367,32 @@ jobs:
13671367
file: ./test/Dockerfile
13681368
env:
13691369
DOCKER_BUILD_NO_SUMMARY: true
1370+
1371+
export-retention-days:
1372+
runs-on: ubuntu-latest
1373+
strategy:
1374+
fail-fast: false
1375+
matrix:
1376+
days:
1377+
- 2
1378+
- 0
1379+
steps:
1380+
-
1381+
name: Checkout
1382+
uses: actions/checkout@v4
1383+
with:
1384+
path: action
1385+
-
1386+
name: Set up Docker Buildx
1387+
uses: docker/setup-buildx-action@v3
1388+
with:
1389+
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
1390+
driver-opts: |
1391+
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
1392+
-
1393+
name: Build
1394+
uses: ./action
1395+
with:
1396+
file: ./test/Dockerfile
1397+
env:
1398+
DOCKER_BUILD_EXPORT_RETENTION_DAYS: ${{ matrix.days }}

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,10 @@ The following outputs are available:
259259

260260
### environment variables
261261

262-
| Name | Type | Description |
263-
|---------------------------|------|-------------------------------------------------------------------------------------------------------------------|
264-
| `DOCKER_BUILD_NO_SUMMARY` | Bool | If `true`, [build summary](https://docs.docker.com/build/ci/github-actions/build-summary/) generation is disabled |
262+
| Name | Type | Description |
263+
|--------------------------------------|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
264+
| `DOCKER_BUILD_NO_SUMMARY` | Bool | If `true`, [build summary](https://docs.docker.com/build/ci/github-actions/build-summary/) generation is disabled |
265+
| `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` |
265266

266267
## Troubleshooting
267268

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ actionsToolkit.run(
151151
return;
152152
}
153153
try {
154+
const exportRetentionDays = buildExportRetentionDays();
154155
const buildxHistory = new BuildxHistory();
155156
const exportRes = await buildxHistory.export({
156157
refs: [stateHelper.buildRef]
@@ -159,7 +160,7 @@ actionsToolkit.run(
159160
const uploadRes = await GitHub.uploadArtifact({
160161
filename: exportRes.dockerbuildFilename,
161162
mimeType: 'application/gzip',
162-
retentionDays: 90
163+
retentionDays: exportRetentionDays
163164
});
164165
await GitHub.writeBuildSummary({
165166
exportRes: exportRes,
@@ -197,3 +198,13 @@ async function buildRef(toolkit: Toolkit, since: Date, builder?: string): Promis
197198
});
198199
return Object.keys(refs).length > 0 ? Object.keys(refs)[0] : '';
199200
}
201+
202+
function buildExportRetentionDays(): number | undefined {
203+
if (process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS) {
204+
const res = parseInt(process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS);
205+
if (isNaN(res)) {
206+
throw Error(`Invalid build export retention days: ${process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS}`);
207+
}
208+
return res;
209+
}
210+
}

0 commit comments

Comments
 (0)