@@ -109,171 +109,3 @@ jobs:
109109 format : ' table'
110110 exit-code : ' 1'
111111 severity : ' CRITICAL,HIGH'
112-
113- check-build-needed :
114- name : Check if build is needed
115- runs-on : ubuntu-latest
116- needs : [test]
117- outputs :
118- should-build : ${{ steps.check.outputs.should-build }}
119- steps :
120- - name : Checkout code
121- uses : actions/checkout@v6
122- with :
123- fetch-depth : 0
124- ref : ${{ github.ref }}
125- sha : ${{ github.sha }}
126-
127- - name : Check if build should be skipped
128- id : check
129- run : |
130- # Only check for push events (dev-build only runs on push to main)
131- if [ "${{ github.event_name }}" != "push" ]; then
132- echo "should-build=false" >> $GITHUB_OUTPUT
133- exit 0
134- fi
135-
136- # Get the current commit SHA
137- CURRENT_SHA="${{ github.sha }}"
138-
139- # Get commit message from git log
140- COMMIT_MSG=$(git log -1 --format="%s" "$CURRENT_SHA" 2>/dev/null || echo "")
141-
142- echo "Checking commit: $CURRENT_SHA"
143- echo "Commit message: $COMMIT_MSG"
144-
145- # Check if it's a release commit (pattern: "chore(main): release" or similar)
146- # BUT: Always run CI for release-please branches and PRs
147- if echo "$COMMIT_MSG" | grep -qiE "^(chore|release|version).*(release|version|changelog)"; then
148- # Check if this is from a release-please branch or PR (should always run CI)
149- if echo "${{ github.ref }}" | grep -qiE "release-please" || echo "${{ github.head_ref }}" | grep -qiE "release-please"; then
150- echo "Release commit from release-please branch/PR - running CI"
151- echo "should-build=true" >> $GITHUB_OUTPUT
152- exit 0
153- fi
154- # Check if commit message explicitly says to skip CI
155- if echo "$COMMIT_MSG" | grep -qiE "[skip ci]|[ci skip]|skip ci"; then
156- echo "Skip reason: [skip ci] detected in commit message"
157- echo "should-build=false" >> $GITHUB_OUTPUT
158- exit 0
159- fi
160- echo "Skip reason: Release commit detected (not from release-please branch)"
161- echo "should-build=false" >> $GITHUB_OUTPUT
162- exit 0
163- fi
164-
165- # For push events, check changed files against base branch
166- BASE_SHA="${{ github.event.before }}"
167- HEAD_SHA="${{ github.event.after }}"
168-
169- if [ -z "$BASE_SHA" ] || [ "$BASE_SHA" = "0000000000000000000000000000000000" ]; then
170- # Initial commit or no base, check all files
171- CHANGED_FILES=$(git ls-tree -r --name-only HEAD)
172- else
173- # Get list of changed files
174- CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
175- fi
176-
177- if [ -z "$CHANGED_FILES" ]; then
178- echo "No changed files detected, skipping build"
179- echo "should-build=false" >> $GITHUB_OUTPUT
180- exit 0
181- fi
182-
183- # Documentation file patterns to ignore
184- DOC_PATTERNS="^README\.md$|^CHANGELOG\.md$|^docs/|\.md$|^LICENSE"
185-
186- # Check if all changed files are documentation
187- NON_DOC_FILES=$(echo "$CHANGED_FILES" | grep -vE "$DOC_PATTERNS" || true)
188-
189- if [ -z "$NON_DOC_FILES" ]; then
190- echo "Skip reason: Only documentation files changed"
191- echo "Changed files:"
192- echo "$CHANGED_FILES" | sed 's/^/ - /'
193- echo "should-build=false" >> $GITHUB_OUTPUT
194- else
195- echo "Build needed: Non-documentation files changed"
196- echo "Non-doc files:"
197- echo "$NON_DOC_FILES" | sed 's/^/ - /'
198- echo "should-build=true" >> $GITHUB_OUTPUT
199- fi
200-
201- dev-build :
202- name : Development Build
203- runs-on : ubuntu-latest
204- needs : [test, check-build-needed]
205- if : |
206- github.event_name == 'push' &&
207- needs.check-build-needed.outputs.should-build == 'true'
208- permissions :
209- contents : read
210- packages : write
211-
212- steps :
213- - name : Checkout code
214- uses : actions/checkout@v6
215- with :
216- fetch-depth : 0
217- ref : ${{ github.ref }}
218- sha : ${{ github.sha }}
219-
220- - name : Set up Docker Buildx
221- uses : docker/setup-buildx-action@v3
222-
223- - name : Log in to GHCR
224- uses : docker/login-action@v3
225- with :
226- registry : ${{ env.REGISTRY }}
227- username : ${{ github.actor }}
228- password : ${{ secrets.GITHUB_TOKEN }}
229-
230- - name : Generate dev tag
231- id : meta
232- run : |
233- # Create a semver-compatible dev tag with commits since last release and commit SHA
234- SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
235-
236- # Get the last release tag (excluding pre-release tags)
237- LAST_TAG=$(git describe --tags --abbrev=0 --match="v[0-9]*.[0-9]*.[0-9]*" 2>/dev/null || echo "")
238-
239- if [ -z "$LAST_TAG" ]; then
240- # No release tags found, use 0.0.0 and count all commits
241- VERSION="0.0.0"
242- COMMIT_COUNT=$(git rev-list --count HEAD)
243- else
244- # Extract version from tag (remove 'v' prefix)
245- VERSION=${LAST_TAG#v}
246- # Count commits since last release
247- COMMIT_COUNT=$(git rev-list --count ${LAST_TAG}..HEAD)
248- fi
249-
250- DEV_TAG="v${VERSION}-dev.${COMMIT_COUNT}.${SHORT_SHA}"
251- echo "dev_tag=${DEV_TAG}" >> $GITHUB_OUTPUT
252- echo "Last release tag: ${LAST_TAG:-'none'}"
253- echo "Base version: ${VERSION}"
254- echo "Commits since last release: ${COMMIT_COUNT}"
255- echo "Generated dev tag: ${DEV_TAG}"
256-
257- - name : Extract metadata
258- id : docker_meta
259- uses : docker/metadata-action@v5
260- with :
261- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
262- tags : |
263- ${{ steps.meta.outputs.dev_tag }}
264- dev
265-
266- - name : Build and push Docker image
267- uses : docker/build-push-action@v6
268- with :
269- context : .
270- platforms : linux/amd64,linux/arm64
271- push : true
272- tags : ${{ steps.docker_meta.outputs.tags }}
273- labels : ${{ steps.docker_meta.outputs.labels }}
274- cache-from : type=gha
275- cache-to : type=gha,mode=min
276- build-args : |
277- VERSION=${{ steps.meta.outputs.dev_tag }}
278- COMMIT=${{ github.sha }}
279- BUILD_DATE=${{ github.event.head_commit.timestamp }}
0 commit comments