Skip to content

Commit bbc3f9b

Browse files
Copilotdarthkali
andcommitted
fix: move semantic release after successful build to prevent orphaned releases
Co-authored-by: darthkali <46423967+darthkali@users.noreply.github.com>
1 parent 1e217ee commit bbc3f9b

File tree

3 files changed

+63
-87
lines changed

3 files changed

+63
-87
lines changed

.github/workflows/frontend-build-and-push.yaml

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,54 @@ name: Frontend Build & Push
55
"on":
66
workflow_dispatch:
77
workflow_call:
8-
inputs:
9-
semantic-version:
10-
description: 'Semantic version from semantic-release'
11-
required: false
12-
type: string
13-
use-semantic-version:
14-
description: 'Whether to use semantic version for tagging'
15-
required: false
16-
type: boolean
17-
default: false
188

199
permissions:
20-
contents: read
10+
contents: write
11+
issues: write
12+
pull-requests: write
2113
packages: write
2214

2315
jobs:
2416
# Build and push frontend container - migrated from build-container-ui
2517
build-and-push-frontend:
2618
runs-on: ubuntu-latest
2719
permissions:
28-
contents: read
20+
contents: write
21+
issues: write
22+
pull-requests: write
2923
packages: write
3024
steps:
3125
- uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
token: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Setup Node.js
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: '20'
34+
cache: 'npm'
35+
cache-dependency-path: frontend/package-lock.json
3236

33-
- name: Set version
34-
id: version
37+
- name: Install dependencies
38+
run: |
39+
cd frontend
40+
npm ci
41+
42+
- name: Set initial version (pre-build)
43+
id: pre-version
3544
run: |
36-
if [ "${{ inputs.use-semantic-version }}" == "true" ] && [ -n "${{ inputs.semantic-version }}" ]; then
37-
echo "VERSION=${{ inputs.semantic-version }}" >> $GITHUB_ENV
38-
echo "Using semantic version: ${{ inputs.semantic-version }}"
39-
elif [ "${{ github.ref_type }}" == "tag" ]; then
40-
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
41-
else
42-
echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV
43-
fi
4445
echo "SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
4546
# Set image name for frontend
4647
RAG_EVAL_UI_IMAGE="ghcr.io/${{ github.repository }}/rag-eval-ui"
4748
echo "RAG_EVAL_UI_IMAGE=${RAG_EVAL_UI_IMAGE}" >> $GITHUB_ENV
49+
50+
# Set initial version for build
51+
if [ "${{ github.ref_type }}" == "tag" ]; then
52+
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
53+
else
54+
echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV
55+
fi
4856
4957
- uses: docker/setup-buildx-action@v3
5058

@@ -65,10 +73,36 @@ jobs:
6573
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
6674
tags: |
6775
${{ env.RAG_EVAL_UI_IMAGE }}:${{ env.SHORT_SHA }}
68-
${{ inputs.use-semantic-version == 'true' &&
69-
format('{0}:{1}', env.RAG_EVAL_UI_IMAGE, env.VERSION) || '' }}
7076
${{ github.ref_type == 'tag' &&
7177
format('{0}:{1}', env.RAG_EVAL_UI_IMAGE,
7278
github.ref_name) || '' }}
7379
cache-from: type=gha
7480
cache-to: type=gha,mode=max
81+
82+
# Only run semantic release after successful build on main branch
83+
- name: Run semantic-release
84+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
85+
id: semantic
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
run: |
89+
cd frontend
90+
npm run semantic-release
91+
92+
# If semantic release created a new version, tag and push the Docker image with semantic version
93+
- name: Tag and push semantic version
94+
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.semantic.outcome == 'success'
95+
run: |
96+
cd frontend
97+
# Get the version from package.json after semantic-release
98+
NEW_VERSION=$(node -p "require('./package.json').version")
99+
if [ -n "$NEW_VERSION" ] && [ "$NEW_VERSION" != "null" ]; then
100+
echo "Semantic release created version: $NEW_VERSION"
101+
# Tag the existing image with the semantic version
102+
docker pull ${{ env.RAG_EVAL_UI_IMAGE }}:${{ env.SHORT_SHA }}
103+
docker tag ${{ env.RAG_EVAL_UI_IMAGE }}:${{ env.SHORT_SHA }} ${{ env.RAG_EVAL_UI_IMAGE }}:$NEW_VERSION
104+
docker push ${{ env.RAG_EVAL_UI_IMAGE }}:$NEW_VERSION
105+
echo "Tagged and pushed image with semantic version: $NEW_VERSION"
106+
else
107+
echo "No new version was created by semantic-release"
108+
fi

.github/workflows/frontend-semantic-release.yaml

Lines changed: 0 additions & 51 deletions
This file was deleted.

.github/workflows/frontend.yaml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ name: Frontend Pipeline
1313
- 'frontend/**'
1414

1515
permissions:
16-
contents: read
16+
contents: write
1717
security-events: write
1818
actions: read
1919
packages: write
20+
issues: write
21+
pull-requests: write
2022

2123
jobs:
2224
# Parallel execution of lint, security-scan, and test workflows
@@ -32,19 +34,10 @@ jobs:
3234
name: Run Test
3335
uses: ./.github/workflows/frontend-test.yaml
3436

35-
# Semantic release - only on main branch pushes
36-
semantic-release:
37-
name: Semantic Release
38-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
39-
needs: [lint, security-scan, test]
40-
uses: ./.github/workflows/frontend-semantic-release.yaml
41-
4237
# Sequential build stage - runs only after parallel jobs succeed
38+
# Semantic release is integrated into build process to ensure release only happens after successful build
4339
build-and-push:
4440
name: Build and Push
45-
needs: [lint, security-scan, test, semantic-release]
41+
needs: [lint, security-scan, test]
4642
if: always() && !cancelled() && !failure() && (needs.lint.result == 'success' && needs.security-scan.result == 'success' && needs.test.result == 'success')
4743
uses: ./.github/workflows/frontend-build-and-push.yaml
48-
with:
49-
semantic-version: ${{ needs.semantic-release.outputs.new-release-version || '' }}
50-
use-semantic-version: ${{ needs.semantic-release.outputs.new-release-published == 'true' }}

0 commit comments

Comments
 (0)