Skip to content

Commit 2b4b207

Browse files
ci(ghcr): allow manual dispatch to build images for .github PRs
Pull requests that touch .github are excluded from the automatic pull_request trigger, so their image builds cannot be tested at all. Add workflow_dispatch and widen the job conditions so a maintainer with write access can start the build manually, mirroring the setup in buildx.yml. A manual run builds an arbitrary branch, which is unreviewed code just like a pull request. Extend the attestation guards in the build, merge and grafana actions accordingly, so manual runs push unsigned images.
1 parent 8a692e2 commit 2b4b207

5 files changed

Lines changed: 22 additions & 14 deletions

File tree

.github/actions/build/action.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ runs:
8282
cache-to: type=registry,ref=ghcr.io/${{ inputs.repository }}:buildcache-${{ matrix.cache_id }}-${{ steps.normalize_version.outputs.normalized_version }},mode=max
8383
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
8484
- name: Generate SBOM for pushed image
85-
# Skip on pull_request: PR builds are unreviewed code. Attesting them
86-
# would yield signed attestations that pass `gh attestation verify
87-
# --repo teslamate-org/teslamate`, which consumers read as "official".
88-
if: github.event_name != 'pull_request'
85+
# Skip on pull_request and workflow_dispatch: both build unreviewed
86+
# code. Attesting them would yield signed attestations that pass
87+
# `gh attestation verify --repo teslamate-org/teslamate`, which
88+
# consumers read as "official".
89+
if: github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch'
8990
uses: anchore/sbom-action@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0
9091
with:
9192
image: ${{ env.REGISTRY_IMAGE }}@${{ steps.build.outputs.digest }}
@@ -94,7 +95,7 @@ runs:
9495
upload-artifact: false
9596
upload-release-assets: false
9697
- name: Attest build provenance
97-
if: github.event_name != 'pull_request'
98+
if: github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch'
9899
uses: actions/attest-build-provenance@0f67c3f4856b2e3261c31976d6725780e5e4c373 # v4.1.1
99100
with:
100101
# attest-* reads the registry from the first path segment of subject-name,
@@ -106,7 +107,7 @@ runs:
106107
subject-digest: ${{ steps.build.outputs.digest }}
107108
push-to-registry: true
108109
- name: Attest SBOM
109-
if: github.event_name != 'pull_request'
110+
if: github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch'
110111
uses: actions/attest@508db95dd578ae2727ebd6217d5ba78e4fbda05d # v4.2.1
111112
with:
112113
subject-name: >-

.github/actions/grafana/action.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ runs:
4444
- name: Attest grafana provenance
4545
# grafana is a single multi-arch build, so steps.build.outputs.digest is
4646
# the manifest-list digest that `gh attestation verify oci://...:tag`
47-
# resolves to. Skip on pull_request: see build action for the rationale.
48-
if: github.event_name != 'pull_request'
47+
# resolves to. Skip on unreviewed builds: see build action for the
48+
# rationale.
49+
if: github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch'
4950
uses: actions/attest-build-provenance@0f67c3f4856b2e3261c31976d6725780e5e4c373 # v4.1.1
5051
with:
5152
# See build action: qualify Docker Hub short names with docker.io.

.github/actions/merge/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ runs:
5050
echo "digest=${DIGEST}" >> "$GITHUB_OUTPUT"
5151
echo "manifest list digest: ${DIGEST}"
5252
- name: Attest manifest provenance
53-
# Skip on pull_request: see build action for the rationale.
54-
if: github.event_name != 'pull_request'
53+
# Skip on unreviewed builds: see build action for the rationale.
54+
if: github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch'
5555
uses: actions/attest-build-provenance@0f67c3f4856b2e3261c31976d6725780e5e4c373 # v4.1.1
5656
with:
5757
# See build action: qualify Docker Hub short names with docker.io.

.github/workflows/ghcr_build.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ on:
1515
- "!.github/**" # Important: Exclude PRs related to .github from auto-run
1616
- "!.github/workflows/**" # Important: Exclude PRs related to .github/workflows from auto-run
1717
- "!.github/actions/**" # Important: Exclude PRs related to .github/actions from auto-run
18+
# Pull requests touching .github are excluded from the automatic runs above,
19+
# since the workflow definition that would run is the one from the pull
20+
# request. This is the deliberate way to run the ghcr build for them anyway, by
21+
# someone with write access. The job conditions below allow for it.
22+
workflow_dispatch:
1823

1924
env:
2025
REGISTRY_IMAGE: ghcr.io/${{ github.repository }}
@@ -32,15 +37,15 @@ jobs:
3237

3338
check_if_pr_from_outside_repo:
3439
needs: check_paths
35-
if: needs.check_paths.outputs.githubfolder == 'false'
40+
if: needs.check_paths.outputs.githubfolder == 'false' || github.event_name == 'workflow_dispatch'
3641
uses: ./.github/workflows/check_if_pr_from_outside_repo.yml
3742

3843
teslamate_build:
3944
name: Build images
4045
needs:
4146
- check_paths
4247
- check_if_pr_from_outside_repo
43-
if: needs.check_paths.outputs.githubfolder == 'false' && needs.check_if_pr_from_outside_repo.outputs.is_pr_from_outside_repo == 'false'
48+
if: (needs.check_paths.outputs.githubfolder == 'false' && needs.check_if_pr_from_outside_repo.outputs.is_pr_from_outside_repo == 'false') || (github.event_name == 'workflow_dispatch' && needs.check_if_pr_from_outside_repo.outputs.is_pr_from_outside_repo == 'false')
4449
strategy:
4550
fail-fast: false
4651
matrix:
@@ -73,7 +78,7 @@ jobs:
7378
needs:
7479
- check_paths
7580
- teslamate_build
76-
if: needs.check_paths.outputs.githubfolder == 'false'
81+
if: needs.check_paths.outputs.githubfolder == 'false' || github.event_name == 'workflow_dispatch'
7782
runs-on: ubuntu-24.04
7883
timeout-minutes: 10
7984
steps:
@@ -95,7 +100,7 @@ jobs:
95100
needs:
96101
- check_paths
97102
- check_if_pr_from_outside_repo
98-
if: needs.check_paths.outputs.githubfolder == 'false' && needs.check_if_pr_from_outside_repo.outputs.is_pr_from_outside_repo == 'false'
103+
if: (needs.check_paths.outputs.githubfolder == 'false' && needs.check_if_pr_from_outside_repo.outputs.is_pr_from_outside_repo == 'false') || (github.event_name == 'workflow_dispatch' && needs.check_if_pr_from_outside_repo.outputs.is_pr_from_outside_repo == 'false')
99104
runs-on: ubuntu-24.04
100105
steps:
101106
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Breaking for automations on discovered entities: the Health sensor is inverted (
2727
- test: stop the app in test_helper instead of relying on --no-start (#5615 - @swiffer)
2828
- build(deps): update flake.lock (#5613)
2929
- build(deps): update flake.lock (#5645)
30+
- ci(ghcr): allow manual dispatch to build images for .github PRs (#5641 - @JakobLichterfeld)
3031

3132
#### Dashboards
3233

0 commit comments

Comments
 (0)