Skip to content

Commit eb333d0

Browse files
committed
feat: only generate pre-releases when Go files change
- Add check for Go file changes before creating pre-release - Compare against latest tag to detect changes in *.go, go.mod, go.sum - Skip pre-release steps if only non-Go files (docs, workflows, etc.) changed - Prevents unnecessary builds and releases for non-code changes
1 parent 532c098 commit eb333d0

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,46 @@ jobs:
149149
with:
150150
fetch-depth: 0
151151

152+
- name: Check for Go file changes
153+
id: go_changes
154+
run: |
155+
# Get the latest tag
156+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
157+
158+
if [ -z "$LATEST_TAG" ]; then
159+
echo "No previous tags found, assuming Go files changed"
160+
echo "changed=true" >> $GITHUB_OUTPUT
161+
else
162+
# Check if any Go files changed since the last tag
163+
GO_CHANGES=$(git diff --name-only ${LATEST_TAG}..HEAD -- '*.go' 'go.mod' 'go.sum' | wc -l)
164+
165+
if [ "$GO_CHANGES" -gt 0 ]; then
166+
echo "Go files changed since ${LATEST_TAG}"
167+
echo "changed=true" >> $GITHUB_OUTPUT
168+
git diff --name-only ${LATEST_TAG}..HEAD -- '*.go' 'go.mod' 'go.sum'
169+
else
170+
echo "No Go files changed since ${LATEST_TAG}"
171+
echo "changed=false" >> $GITHUB_OUTPUT
172+
fi
173+
fi
174+
152175
- name: Set up Go
176+
if: steps.go_changes.outputs.changed == 'true'
153177
uses: actions/setup-go@v5
154178
with:
155179
go-version: ${{ env.GO_VERSION }}
156180
cache: true
157181

158182
- name: Import GPG key
183+
if: steps.go_changes.outputs.changed == 'true'
159184
id: import_gpg
160185
uses: crazy-max/ghaction-import-gpg@v6
161186
with:
162187
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
163188
passphrase: ${{ secrets.GPG_PASSPHRASE }}
164189

165190
- name: Generate snapshot version
191+
if: steps.go_changes.outputs.changed == 'true'
166192
id: version
167193
run: |
168194
# Get the latest release tag (exclude pre-release tags)
@@ -186,6 +212,7 @@ jobs:
186212
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
187213
188214
- name: Run GoReleaser (snapshot)
215+
if: steps.go_changes.outputs.changed == 'true'
189216
uses: goreleaser/goreleaser-action@v6
190217
with:
191218
version: latest
@@ -194,19 +221,22 @@ jobs:
194221
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
195222

196223
- name: Generate pre-release attestations
224+
if: steps.go_changes.outputs.changed == 'true'
197225
uses: actions/attest-build-provenance@v1
198226
with:
199227
subject-path: |
200228
dist/*.zip
201229
dist/*_checksums.txt
202230
203231
- name: Upload artifacts
232+
if: steps.go_changes.outputs.changed == 'true'
204233
uses: actions/upload-artifact@v4
205234
with:
206235
name: pre-release-artifacts
207236
path: dist/*
208237

209238
- name: Create GitHub pre-release
239+
if: steps.go_changes.outputs.changed == 'true'
210240
uses: softprops/action-gh-release@v1
211241
with:
212242
name: "Development Build v${{ steps.version.outputs.version }}"

0 commit comments

Comments
 (0)