Skip to content

Commit 02dec9b

Browse files
Copilotdarthkali
andauthored
Implement build and release pipeline for backend with semantic versioning (#54)
* Initial plan * Add semantic release configuration and enhance backend build pipeline Co-authored-by: darthkali <[email protected]> * Add .gitignore to backend and remove node_modules from tracking Co-authored-by: darthkali <[email protected]> * Fix YAML linting issues in backend-build-and-push.yaml Co-authored-by: darthkali <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: darthkali <[email protected]>
1 parent 4d50591 commit 02dec9b

File tree

5 files changed

+6859
-19
lines changed

5 files changed

+6859
-19
lines changed
Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,65 @@
11
---
2-
name: Backend Build & Push
2+
name: Backend Build & Push
33

44
# Migrated from GitLab CI - supports manual dispatch
55
"on":
66
workflow_dispatch:
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 backend container - migrated from build-container-backend
1517
build-and-push-backend:
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+
- uses: actions/setup-python@v5
31+
with:
32+
python-version: '3.12'
33+
34+
- name: Install Poetry
35+
run: pip install --root-user-action=ignore poetry --quiet
2236

23-
- name: Set version
24-
id: version
37+
- name: Install Python dependencies
38+
working-directory: backend
39+
run: poetry install --quiet
40+
41+
- name: Setup Node.js for semantic-release
42+
uses: actions/setup-node@v4
43+
with:
44+
node-version: '20'
45+
cache: 'npm'
46+
cache-dependency-path: backend/package-lock.json
47+
48+
- name: Install Node.js dependencies for semantic-release
49+
run: |
50+
cd backend
51+
npm ci
52+
53+
- name: Set initial version (pre-build)
54+
id: pre-version
2555
run: |
26-
if [ "${{ github.ref_type }}" == "tag" ]; then
27-
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
28-
else
29-
echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV
30-
fi
3156
echo "SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
3257
# Set image name for backend
33-
LLM_EVAL_BACKEND_IMAGE="ghcr.io/${{ github.repository }}"
34-
LLM_EVAL_BACKEND_IMAGE="${LLM_EVAL_BACKEND_IMAGE}/llm-eval-backend"
35-
echo "LLM_EVAL_BACKEND_IMAGE=${LLM_EVAL_BACKEND_IMAGE}" >> \
36-
$GITHUB_ENV
58+
BACKEND_IMAGE="ghcr.io/${{ github.repository }}/backend"
59+
echo "BACKEND_IMAGE=${BACKEND_IMAGE}" >> $GITHUB_ENV
60+
61+
# Set initial version for build
62+
echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV
3763
3864
- uses: docker/setup-buildx-action@v3
3965

@@ -51,11 +77,31 @@ jobs:
5177
file: backend/Dockerfile
5278
build-args: |
5379
VERSION=${{ env.VERSION }}
54-
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
80+
push: >-
81+
${{ github.event_name == 'push' &&
82+
github.ref == 'refs/heads/main' }}
5583
tags: |
56-
${{ env.LLM_EVAL_BACKEND_IMAGE }}:${{ env.SHORT_SHA }}
57-
${{ github.ref_type == 'tag' &&
58-
format('{0}:{1}', env.LLM_EVAL_BACKEND_IMAGE,
59-
github.ref_name) || '' }}
84+
${{ env.BACKEND_IMAGE }}:${{ env.SHORT_SHA }}
6085
cache-from: type=gha
6186
cache-to: type=gha,mode=max
87+
88+
# Only run semantic release after successful build on main branch
89+
- name: Run semantic-release
90+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
91+
id: semantic
92+
env:
93+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94+
run: |
95+
cd backend
96+
npm run semantic-release
97+
98+
NEW_VERSION=$(node -p "require('./package.json').version")
99+
BACKEND_VERSION="backend-v$NEW_VERSION"
100+
101+
102+
# Tag the existing image with the backend-prefixed semantic version
103+
docker pull ${{ env.BACKEND_IMAGE }}:${{ env.SHORT_SHA }}
104+
docker tag ${{ env.BACKEND_IMAGE }}:${{ env.SHORT_SHA }} \
105+
${{ env.BACKEND_IMAGE }}:$BACKEND_VERSION
106+
docker push ${{ env.BACKEND_IMAGE }}:$BACKEND_VERSION
107+
echo "Tagged and pushed image with backend version: $BACKEND_VERSION"

backend/.gitignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Node.js dependencies for semantic-release
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Python
8+
__pycache__/
9+
*.py[cod]
10+
*$py.class
11+
*.so
12+
.Python
13+
build/
14+
develop-eggs/
15+
dist/
16+
downloads/
17+
eggs/
18+
.eggs/
19+
lib/
20+
lib64/
21+
parts/
22+
sdist/
23+
var/
24+
wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
29+
# Environment variables
30+
.env
31+
.env.local
32+
.env.development.local
33+
.env.test.local
34+
.env.production.local
35+
36+
# IDE
37+
.vscode/
38+
.idea/
39+
*.swp
40+
*.swo
41+
*~
42+
43+
# OS generated files
44+
.DS_Store
45+
.DS_Store?
46+
._*
47+
.Spotlight-V100
48+
.Trashes
49+
ehthumbs.db
50+
Thumbs.db
51+
52+
# Coverage reports
53+
htmlcov/
54+
.coverage
55+
.coverage.*
56+
coverage.xml
57+
*.cover
58+
.hypothesis/
59+
.pytest_cache/
60+
61+
# Semantic release generated files
62+
CHANGELOG.md

backend/.releaserc.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"branches": ["main"],
3+
"tagFormat": "backend-v${version}",
4+
"plugins": [
5+
"@semantic-release/commit-analyzer",
6+
"@semantic-release/release-notes-generator",
7+
[
8+
"@semantic-release/changelog",
9+
{
10+
"changelogFile": "CHANGELOG.md"
11+
}
12+
],
13+
[
14+
"@semantic-release/github",
15+
{
16+
"assets": [
17+
{
18+
"path": "CHANGELOG.md",
19+
"label": "Changelog"
20+
}
21+
]
22+
}
23+
]
24+
]
25+
}

0 commit comments

Comments
 (0)