Skip to content

Commit 96daea3

Browse files
Copilotdarthkali
andauthored
feat: implement semantic versioning for frontend with build-first release strategy (#43)
* Initial plan * feat: implement semantic versioning for frontend with semantic-release - Add semantic-release dependencies and configuration - Create frontend-semantic-release.yaml workflow - Modify frontend-build-and-push.yaml to support semantic versioning - Update frontend.yaml to integrate semantic release - Configure conventional commit patterns (fix=patch, feat=minor, feat!=major) Co-authored-by: darthkali <46423967+darthkali@users.noreply.github.com> * docs: add semantic versioning documentation Add comprehensive documentation explaining the new semantic versioning workflow, commit conventions, and Docker image tagging strategy. Co-authored-by: darthkali <46423967+darthkali@users.noreply.github.com> * fix: move semantic release after successful build to prevent orphaned releases Co-authored-by: darthkali <46423967+darthkali@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: darthkali <46423967+darthkali@users.noreply.github.com>
1 parent b828e70 commit 96daea3

File tree

6 files changed

+11008
-4890
lines changed

6 files changed

+11008
-4890
lines changed

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

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,52 @@ name: Frontend Build & Push
77
workflow_call:
88

99
permissions:
10-
contents: read
10+
contents: write
11+
issues: write
12+
pull-requests: write
1113
packages: write
1214

1315
jobs:
1416
# Build and push frontend container - migrated from build-container-ui
1517
build-and-push-frontend:
1618
runs-on: ubuntu-latest
1719
permissions:
18-
contents: read
20+
contents: write
21+
issues: write
22+
pull-requests: write
1923
packages: write
2024
steps:
2125
- 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
36+
37+
- name: Install dependencies
38+
run: |
39+
cd frontend
40+
npm ci
2241
23-
- name: Set version
24-
id: version
42+
- name: Set initial version (pre-build)
43+
id: pre-version
2544
run: |
45+
echo "SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
46+
# Set image name for frontend
47+
RAG_EVAL_UI_IMAGE="ghcr.io/${{ github.repository }}/rag-eval-ui"
48+
echo "RAG_EVAL_UI_IMAGE=${RAG_EVAL_UI_IMAGE}" >> $GITHUB_ENV
49+
50+
# Set initial version for build
2651
if [ "${{ github.ref_type }}" == "tag" ]; then
2752
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
2853
else
2954
echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV
3055
fi
31-
echo "SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
32-
# Set image name for frontend
33-
RAG_EVAL_UI_IMAGE="ghcr.io/${{ github.repository }}/rag-eval-ui"
34-
echo "RAG_EVAL_UI_IMAGE=${RAG_EVAL_UI_IMAGE}" >> $GITHUB_ENV
3556
3657
- uses: docker/setup-buildx-action@v3
3758

@@ -57,3 +78,31 @@ jobs:
5778
github.ref_name) || '' }}
5879
cache-from: type=gha
5980
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.yaml

Lines changed: 5 additions & 1 deletion
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
@@ -33,7 +35,9 @@ jobs:
3335
uses: ./.github/workflows/frontend-test.yaml
3436

3537
# 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
3639
build-and-push:
3740
name: Build and Push
3841
needs: [lint, security-scan, test]
42+
if: always() && !cancelled() && !failure() && (needs.lint.result == 'success' && needs.security-scan.result == 'success' && needs.test.result == 'success')
3943
uses: ./.github/workflows/frontend-build-and-push.yaml

frontend/.releaserc.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"branches": ["main"],
3+
"plugins": [
4+
"@semantic-release/commit-analyzer",
5+
"@semantic-release/release-notes-generator",
6+
[
7+
"@semantic-release/changelog",
8+
{
9+
"changelogFile": "CHANGELOG.md"
10+
}
11+
],
12+
[
13+
"@semantic-release/npm",
14+
{
15+
"npmPublish": false
16+
}
17+
],
18+
[
19+
"@semantic-release/github",
20+
{
21+
"assets": [
22+
{
23+
"path": "CHANGELOG.md",
24+
"label": "Changelog"
25+
}
26+
]
27+
}
28+
],
29+
[
30+
"@semantic-release/git",
31+
{
32+
"assets": ["package.json", "package-lock.json", "CHANGELOG.md"],
33+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
34+
}
35+
]
36+
]
37+
}

frontend/SEMANTIC_VERSIONING.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Frontend Semantic Versioning
2+
3+
This document describes the automated semantic versioning system implemented for the frontend component.
4+
5+
## Overview
6+
7+
The frontend now uses [semantic-release](https://github.com/semantic-release/semantic-release) to automatically generate semantic versions based on conventional commit messages and create GitHub releases.
8+
9+
## How It Works
10+
11+
### Conventional Commits
12+
13+
The versioning is triggered by conventional commit messages on the `main` branch:
14+
15+
- **`fix:`****Patch version** (e.g., 1.0.0 → 1.0.1)
16+
- Bug fixes and patches
17+
- Example: `fix: resolve navigation issue in sidebar`
18+
19+
- **`feat:`****Minor version** (e.g., 1.0.0 → 1.1.0)
20+
- New features and enhancements
21+
- Example: `feat: add dark mode support`
22+
23+
- **`feat!:`** or **`BREAKING CHANGE:`****Major version** (e.g., 1.0.0 → 2.0.0)
24+
- Breaking changes and major updates
25+
- Example: `feat!: redesign user authentication system`
26+
27+
### Workflow Integration
28+
29+
The semantic versioning is integrated into the CI/CD pipeline:
30+
31+
1. **Lint, Security Scan, and Tests** run in parallel
32+
2. **Semantic Release** runs only on `main` branch pushes (after successful tests)
33+
3. **Build and Push** uses the semantic version for Docker image tagging
34+
35+
### Automated Actions
36+
37+
When a release is triggered, the system automatically:
38+
39+
- ✅ Analyzes commit messages since the last release
40+
- ✅ Determines the next version number
41+
- ✅ Updates `package.json` version
42+
- ✅ Generates `CHANGELOG.md`
43+
- ✅ Creates a GitHub release with release notes
44+
- ✅ Tags Docker images with the semantic version
45+
- ✅ Commits version changes back to the repository
46+
47+
## Docker Image Tagging
48+
49+
Images are tagged with multiple tags:
50+
51+
- **Short SHA**: `ghcr.io/codecentric/llm-eval/rag-eval-ui:a1b2c3d4` (always)
52+
- **Semantic Version**: `ghcr.io/codecentric/llm-eval/rag-eval-ui:1.2.3` (when semantic release creates a new version)
53+
- **Git Tag**: `ghcr.io/codecentric/llm-eval/rag-eval-ui:v1.2.3` (for manual git tags)
54+
55+
## Configuration Files
56+
57+
- **`.releaserc.json`**: Semantic-release configuration
58+
- **`frontend-semantic-release.yaml`**: GitHub workflow for semantic release
59+
- **`frontend-build-and-push.yaml`**: Updated to support semantic versioning
60+
- **`frontend.yaml`**: Main workflow orchestrating the entire pipeline
61+
62+
## Development Workflow
63+
64+
### For Pull Requests
65+
- Commits can use any message format
66+
- No releases are created
67+
- Docker images are still built and tagged with SHA
68+
69+
### For Main Branch
70+
- Use conventional commit messages
71+
- Semantic releases are created automatically
72+
- Docker images get semantic version tags
73+
74+
### Example Commit Messages
75+
76+
```bash
77+
# Patch release (1.0.0 → 1.0.1)
78+
git commit -m "fix: resolve memory leak in chart component"
79+
80+
# Minor release (1.0.0 → 1.1.0)
81+
git commit -m "feat: add export functionality to evaluation results"
82+
83+
# Major release (1.0.0 → 2.0.0)
84+
git commit -m "feat!: migrate to new API endpoints
85+
86+
BREAKING CHANGE: API endpoints have changed from /api/v1 to /api/v2"
87+
```
88+
89+
## Benefits
90+
91+
- 🔄 **Automated versioning** - No manual version management
92+
- 📝 **Automatic changelog** - Generated from commit messages
93+
- 🏷️ **Consistent tagging** - Docker images tagged with semantic versions
94+
- 📊 **Release tracking** - GitHub releases with detailed notes
95+
- 🚀 **CI/CD integration** - Seamless workflow integration
96+
97+
## Troubleshooting
98+
99+
### No Release Created
100+
- Ensure commits follow conventional format
101+
- Check that you're pushing to `main` branch
102+
- Verify the commit introduces changes worthy of a release
103+
104+
### Failed Release
105+
- Check GitHub Actions logs in the `Semantic Release` workflow
106+
- Ensure `GITHUB_TOKEN` has sufficient permissions
107+
- Verify all dependencies are properly installed

0 commit comments

Comments
 (0)