@@ -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
199permissions :
20- contents : read
10+ contents : write
11+ issues : write
12+ pull-requests : write
2113 packages : write
2214
2315jobs :
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
0 commit comments