Skip to content

Commit 5a1e33d

Browse files
author
Oleg
committed
Trigger image build only on a push to main branch
1 parent b852abd commit 5a1e33d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
username: ${{ github.actor }}
108108
password: ${{ github.token }}
109109
registry: ${{ env.IMAGE_REGISTRY }}
110-
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
110+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
111111

112112
- name: Publish
113113
id: push
@@ -116,21 +116,21 @@ jobs:
116116
image: ${{ steps.build_image.outputs.image }}
117117
tags: ${{ steps.current-version.outputs.value }} ${{ steps.build_image.outputs.tags }}
118118
registry: ${{ env.IMAGE_REGISTRY }}
119-
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
119+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
120120

121121
- name: Generate attestation for images
122122
uses: actions/attest-build-provenance@v2
123123
with:
124124
subject-name: ${{ env.IMAGE_REGISTRY }}/${{ steps.build_image.outputs.image }}
125125
subject-digest: ${{ steps.push.outputs.digest }}
126126
push-to-registry: true
127-
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
127+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
128128

129-
version-changed:
129+
mark-previous-version:
130130
needs: [build, meta]
131131
runs-on: ubuntu-latest
132132

133-
if: github.event_name == 'pull_request' && needs.build.outputs.current-version != needs.meta.outputs.latest-version
133+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.build.outputs.current-version != needs.meta.outputs.latest-version
134134

135135
permissions:
136136
contents: write
@@ -139,13 +139,13 @@ jobs:
139139
- name: Checkout current head
140140
uses: actions/checkout@v4
141141
with:
142-
ref: ${{ github.event.pull_request.base.ref }}
142+
ref: ${{ github.event.before }}
143143

144144
- name: Mark the current head with the latest version before the update
145145
run: git tag v${{ needs.build.outputs.current-version }} && git push origin v${{ needs.build.outputs.current-version }}
146146

147147
automerge:
148-
needs: [build, version-changed]
148+
needs: build
149149
runs-on: ubuntu-latest
150150

151151
if: (!cancelled() && github.event_name == 'pull_request' && github.actor == 'dependabot[bot]')

0 commit comments

Comments
 (0)