Skip to content

Commit 1a16264

Browse files
authored
Merge pull request #1172 from crazy-max/build-export-disable
opt to disable build record upload
2 parents bca5082 + 9eea548 commit 1a16264

File tree

5 files changed

+72
-23
lines changed

5 files changed

+72
-23
lines changed

.github/workflows/ci.yml

+25-2
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,30 @@ jobs:
14121412
with:
14131413
file: ./test/Dockerfile
14141414

1415-
export-retention-days:
1415+
record-upload-disable:
1416+
runs-on: ubuntu-latest
1417+
steps:
1418+
-
1419+
name: Checkout
1420+
uses: actions/checkout@v4
1421+
with:
1422+
path: action
1423+
-
1424+
name: Set up Docker Buildx
1425+
uses: docker/setup-buildx-action@v3
1426+
with:
1427+
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
1428+
driver-opts: |
1429+
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
1430+
-
1431+
name: Build
1432+
uses: ./action
1433+
with:
1434+
file: ./test/Dockerfile
1435+
env:
1436+
DOCKER_BUILD_RECORD_UPLOAD: false
1437+
1438+
record-retention-days:
14161439
runs-on: ubuntu-latest
14171440
strategy:
14181441
fail-fast: false
@@ -1439,4 +1462,4 @@ jobs:
14391462
with:
14401463
file: ./test/Dockerfile
14411464
env:
1442-
DOCKER_BUILD_EXPORT_RETENTION_DAYS: ${{ matrix.days }}
1465+
DOCKER_BUILD_RECORD_RETENTION_DAYS: ${{ matrix.days }}

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ The following outputs are available:
259259
| Name | Type | Default | Description |
260260
|--------------------------------------|--------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
261261
| `DOCKER_BUILD_SUMMARY` | Bool | `true` | If `false`, [build summary](https://docs.docker.com/build/ci/github-actions/build-summary/) generation is disabled |
262-
| `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` |
262+
| `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 |
263+
| `DOCKER_BUILD_RECORD_RETENTION_DAYS` | Number | | Duration after which build record 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` |
263264

264265
## Troubleshooting
265266

dist/index.js

+9-9
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

+35-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {Util} from '@docker/actions-toolkit/lib/util';
1515

1616
import {BuilderInfo} from '@docker/actions-toolkit/lib/types/buildx/builder';
1717
import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker/docker';
18+
import {UploadArtifactResponse} from '@docker/actions-toolkit/lib/types/github';
1819

1920
import * as context from './context';
2021

@@ -163,17 +164,27 @@ actionsToolkit.run(
163164
if (stateHelper.isSummarySupported) {
164165
await core.group(`Generating build summary`, async () => {
165166
try {
166-
const exportRetentionDays = buildExportRetentionDays();
167+
const recordUploadEnabled = buildRecordUploadEnabled();
168+
let recordRetentionDays: number | undefined;
169+
if (recordUploadEnabled) {
170+
recordRetentionDays = buildRecordRetentionDays();
171+
}
172+
167173
const buildxHistory = new BuildxHistory();
168174
const exportRes = await buildxHistory.export({
169175
refs: stateHelper.buildRef ? [stateHelper.buildRef] : []
170176
});
171-
core.info(`Build record exported to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`);
172-
const uploadRes = await GitHub.uploadArtifact({
173-
filename: exportRes.dockerbuildFilename,
174-
mimeType: 'application/gzip',
175-
retentionDays: exportRetentionDays
176-
});
177+
core.info(`Build record written to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`);
178+
179+
let uploadRes: UploadArtifactResponse | undefined;
180+
if (recordUploadEnabled) {
181+
uploadRes = await GitHub.uploadArtifact({
182+
filename: exportRes.dockerbuildFilename,
183+
mimeType: 'application/gzip',
184+
retentionDays: recordRetentionDays
185+
});
186+
}
187+
177188
await GitHub.writeBuildSummary({
178189
exportRes: exportRes,
179190
uploadRes: uploadRes,
@@ -221,11 +232,25 @@ function buildSummaryEnabled(): boolean {
221232
return true;
222233
}
223234

224-
function buildExportRetentionDays(): number | undefined {
235+
function buildRecordUploadEnabled(): boolean {
236+
if (process.env.DOCKER_BUILD_RECORD_UPLOAD) {
237+
return Util.parseBool(process.env.DOCKER_BUILD_RECORD_UPLOAD);
238+
}
239+
return true;
240+
}
241+
242+
function buildRecordRetentionDays(): number | undefined {
243+
let val: string | undefined;
225244
if (process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS) {
226-
const res = parseInt(process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS);
245+
core.warning('DOCKER_BUILD_EXPORT_RETENTION_DAYS is deprecated. Use DOCKER_BUILD_RECORD_RETENTION_DAYS instead.');
246+
val = process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS;
247+
} else if (process.env.DOCKER_BUILD_RECORD_RETENTION_DAYS) {
248+
val = process.env.DOCKER_BUILD_RECORD_RETENTION_DAYS;
249+
}
250+
if (val) {
251+
const res = parseInt(val);
227252
if (isNaN(res)) {
228-
throw Error(`Invalid build export retention days: ${process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS}`);
253+
throw Error(`Invalid build record retention days: ${val}`);
229254
}
230255
return res;
231256
}

0 commit comments

Comments
 (0)