Skip to content

Commit

Permalink
Merge pull request #238 from crazy-max/build-checks
Browse files Browse the repository at this point in the history
generate GitHub annotations for build checks
  • Loading branch information
crazy-max authored Aug 6, 2024
2 parents 28c6eb5 + 4c69466 commit 955c005
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 3 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,53 @@ jobs:
targets: app
env:
DOCKER_BUILD_RECORD_RETENTION_DAYS: ${{ matrix.days }}

checks:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
buildx-version:
- latest
- v0.14.1
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ matrix.buildx-version }}
driver-opts: |
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
-
name: Build
uses: ./
with:
workdir: ./test
files: |
./lint.hcl
annotations-disabled:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
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: ./
with:
workdir: ./test
files: |
./lint.hcl
env:
DOCKER_BUILD_CHECKS_ANNOTATIONS: false
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ The following outputs are available

| Name | Type | Default | Description |
|--------------------------------------|--------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `DOCKER_BUILD_CHECKS_ANNOTATIONS` | Bool | `true` | If `false`, GitHub annotations are not generated for [build checks](https://docs.docker.com/build/checks/) |
| `DOCKER_BUILD_SUMMARY` | Bool | `true` | If `false`, [build summary](https://docs.docker.com/build/ci/github-actions/build-summary/) generation is disabled |
| `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 |
| `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` |
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ actionsToolkit.run(
const args: string[] = await context.getArgs(inputs, definition, toolkit);
const buildCmd = await toolkit.buildx.getCommand(args);
const buildEnv = Object.assign({}, process.env, {
BUILDX_BAKE_GIT_AUTH_TOKEN: gitAuthToken
BUILDX_BAKE_GIT_AUTH_TOKEN: gitAuthToken,
BUILDX_METADATA_WARNINGS: 'true'
}) as {
[key: string]: string;
};
Expand Down Expand Up @@ -164,6 +165,21 @@ actionsToolkit.run(
}
});

if (buildChecksAnnotationsEnabled()) {
const warnings = toolkit.buildxBake.resolveWarnings(metadata);
if (refs.length > 0 && warnings && warnings.length > 0) {
const annotations = await Buildx.convertWarningsToGitHubAnnotations(warnings, refs);
core.debug(`annotations: ${JSON.stringify(annotations, null, 2)}`);
if (annotations && annotations.length > 0) {
await core.group(`Generating GitHub annotations (${annotations.length} build checks found)`, async () => {
for (const annotation of annotations) {
core.warning(annotation.message, annotation);
}
});
}
}
}

await core.group(`Check build summary support`, async () => {
if (!buildSummaryEnabled()) {
core.info('Build summary disabled');
Expand Down Expand Up @@ -255,6 +271,13 @@ async function buildRefs(toolkit: Toolkit, since: Date, builder?: string): Promi
return refs;
}

function buildChecksAnnotationsEnabled(): boolean {
if (process.env.DOCKER_BUILD_CHECKS_ANNOTATIONS) {
return Util.parseBool(process.env.DOCKER_BUILD_CHECKS_ANNOTATIONS);
}
return true;
}

function buildSummaryEnabled(): boolean {
if (process.env.DOCKER_BUILD_NO_SUMMARY) {
core.warning('DOCKER_BUILD_NO_SUMMARY is deprecated. Set DOCKER_BUILD_SUMMARY to false instead.');
Expand Down
10 changes: 10 additions & 0 deletions test/lint-other.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
frOM busybox as base

Check warning on line 1 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'frOM' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 1 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'frOM' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 1 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'frOM' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 1 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'frOM' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/
cOpy lint-other.Dockerfile .

Check warning on line 2 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'cOpy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 2 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'cOpy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 2 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'cOpy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

froM busybox aS notused

Check warning on line 4 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'froM' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 4 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'froM' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 4 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'froM' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/
COPY lint-other.Dockerfile .

from scratch

Check warning on line 7 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'from' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 7 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'from' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 7 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'from' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/
COPy --from=base \

Check warning on line 8 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'COPy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 8 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'COPy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 8 in test/lint-other.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'COPy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/
/lint-other.Dockerfile \
/
12 changes: 12 additions & 0 deletions test/lint.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
frOM busybox as base

Check warning on line 1 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'frOM' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 1 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'frOM' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 1 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'frOM' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 1 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'frOM' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/
cOpy lint.Dockerfile .

Check warning on line 2 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'cOpy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 2 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'cOpy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 2 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'cOpy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 2 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'cOpy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

from scratch

Check warning on line 4 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'from' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 4 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'from' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 4 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'from' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 4 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'from' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/
MAINTAINER [email protected]

Check warning on line 5 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

The MAINTAINER instruction is deprecated, use a label instead to define an image author

MaintainerDeprecated: Maintainer instruction is deprecated in favor of using label More info: https://docs.docker.com/go/dockerfile/rule/maintainer-deprecated/

Check warning on line 5 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

The MAINTAINER instruction is deprecated, use a label instead to define an image author

MaintainerDeprecated: Maintainer instruction is deprecated in favor of using label More info: https://docs.docker.com/go/dockerfile/rule/maintainer-deprecated/

Check warning on line 5 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

The MAINTAINER instruction is deprecated, use a label instead to define an image author

MaintainerDeprecated: Maintainer instruction is deprecated in favor of using label More info: https://docs.docker.com/go/dockerfile/rule/maintainer-deprecated/
COPy --from=base \

Check warning on line 6 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'COPy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 6 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'COPy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 6 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'COPy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/

Check warning on line 6 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

All commands within the Dockerfile should use the same casing (either upper or lower)

ConsistentInstructionCasing: Command 'COPy' should match the case of the command majority (uppercase) More info: https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/
/lint.Dockerfile \
/

CMD [ "echo", "Hello, Norway!" ]

Check warning on line 10 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

Multiple instructions of the same type should not be used in the same stage

MultipleInstructionsDisallowed: Multiple CMD instructions should not be used in the same stage because only the last one will be used More info: https://docs.docker.com/go/dockerfile/rule/multiple-instructions-disallowed/

Check warning on line 10 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

Multiple instructions of the same type should not be used in the same stage

MultipleInstructionsDisallowed: Multiple CMD instructions should not be used in the same stage because only the last one will be used More info: https://docs.docker.com/go/dockerfile/rule/multiple-instructions-disallowed/

Check warning on line 10 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

Multiple instructions of the same type should not be used in the same stage

MultipleInstructionsDisallowed: Multiple CMD instructions should not be used in the same stage because only the last one will be used More info: https://docs.docker.com/go/dockerfile/rule/multiple-instructions-disallowed/
CMD [ "echo", "Hello, Sweden!" ]
ENTRYPOINT my-program start

Check warning on line 12 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for ENTRYPOINT to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/

Check warning on line 12 in test/lint.Dockerfile

View workflow job for this annotation

GitHub Actions / checks (latest)

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for ENTRYPOINT to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/
12 changes: 12 additions & 0 deletions test/lint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
group "default" {
targets = ["lint", "lint-other", "lint-inline"]
}
target "lint" {
dockerfile = "lint.Dockerfile"
}
target "lint-other" {
dockerfile = "lint-other.Dockerfile"
}
target "lint-inline" {
dockerfile-inline = "FRoM alpine\nENTRYPOINT [\"echo\", \"hello\"]"
}

0 comments on commit 955c005

Please sign in to comment.