Skip to content

Commit dbdf67d

Browse files
authored
Merge pull request #230 from crazy-max/build-export-disable
opt to disable build record upload
2 parents eb0e46e + 16551d9 commit dbdf67d

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
@@ -590,7 +590,30 @@ jobs:
590590
./test/config.hcl
591591
targets: app
592592

593-
export-retention-days:
593+
record-upload-disable:
594+
runs-on: ubuntu-latest
595+
steps:
596+
-
597+
name: Checkout
598+
uses: actions/checkout@v4
599+
-
600+
name: Set up Docker Buildx
601+
uses: docker/setup-buildx-action@v3
602+
with:
603+
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
604+
driver-opts: |
605+
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
606+
-
607+
name: Build
608+
uses: ./
609+
with:
610+
files: |
611+
./test/config.hcl
612+
targets: app
613+
env:
614+
DOCKER_BUILD_RECORD_UPLOAD: false
615+
616+
record-retention-days:
594617
runs-on: ubuntu-latest
595618
strategy:
596619
fail-fast: false
@@ -617,4 +640,4 @@ jobs:
617640
./test/config.hcl
618641
targets: app
619642
env:
620-
DOCKER_BUILD_EXPORT_RETENTION_DAYS: ${{ matrix.days }}
643+
DOCKER_BUILD_RECORD_RETENTION_DAYS: ${{ matrix.days }}

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ The following outputs are available
282282
| Name | Type | Default | Description |
283283
|--------------------------------------|--------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
284284
| `DOCKER_BUILD_SUMMARY` | Bool | `true` | If `false`, [build summary](https://docs.docker.com/build/ci/github-actions/build-summary/) generation is disabled |
285-
| `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` |
285+
| `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 |
286+
| `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` |
286287

287288
## Contributing
288289

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
import {BakeDefinition} from '@docker/actions-toolkit/lib/types/buildx/bake';
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
import * as stateHelper from './state-helper';
@@ -189,17 +190,27 @@ actionsToolkit.run(
189190
if (stateHelper.isSummarySupported) {
190191
await core.group(`Generating build summary`, async () => {
191192
try {
192-
const exportRetentionDays = buildExportRetentionDays();
193+
const recordUploadEnabled = buildRecordUploadEnabled();
194+
let recordRetentionDays: number | undefined;
195+
if (recordUploadEnabled) {
196+
recordRetentionDays = buildRecordRetentionDays();
197+
}
198+
193199
const buildxHistory = new BuildxHistory();
194200
const exportRes = await buildxHistory.export({
195201
refs: stateHelper.buildRefs
196202
});
197-
core.info(`Build records exported to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`);
198-
const uploadRes = await GitHub.uploadArtifact({
199-
filename: exportRes.dockerbuildFilename,
200-
mimeType: 'application/gzip',
201-
retentionDays: exportRetentionDays
202-
});
203+
core.info(`Build records written to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`);
204+
205+
let uploadRes: UploadArtifactResponse | undefined;
206+
if (recordUploadEnabled) {
207+
uploadRes = await GitHub.uploadArtifact({
208+
filename: exportRes.dockerbuildFilename,
209+
mimeType: 'application/gzip',
210+
retentionDays: recordRetentionDays
211+
});
212+
}
213+
203214
await GitHub.writeBuildSummary({
204215
exportRes: exportRes,
205216
uploadRes: uploadRes,
@@ -254,11 +265,25 @@ function buildSummaryEnabled(): boolean {
254265
return true;
255266
}
256267

257-
function buildExportRetentionDays(): number | undefined {
268+
function buildRecordUploadEnabled(): boolean {
269+
if (process.env.DOCKER_BUILD_RECORD_UPLOAD) {
270+
return Util.parseBool(process.env.DOCKER_BUILD_RECORD_UPLOAD);
271+
}
272+
return true;
273+
}
274+
275+
function buildRecordRetentionDays(): number | undefined {
276+
let val: string | undefined;
258277
if (process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS) {
259-
const res = parseInt(process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS);
278+
core.warning('DOCKER_BUILD_EXPORT_RETENTION_DAYS is deprecated. Use DOCKER_BUILD_RECORD_RETENTION_DAYS instead.');
279+
val = process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS;
280+
} else if (process.env.DOCKER_BUILD_RECORD_RETENTION_DAYS) {
281+
val = process.env.DOCKER_BUILD_RECORD_RETENTION_DAYS;
282+
}
283+
if (val) {
284+
const res = parseInt(val);
260285
if (isNaN(res)) {
261-
throw Error(`Invalid build export retention days: ${process.env.DOCKER_BUILD_EXPORT_RETENTION_DAYS}`);
286+
throw Error(`Invalid build record retention days: ${val}`);
262287
}
263288
return res;
264289
}

0 commit comments

Comments
 (0)