Skip to content

Commit c848ff4

Browse files
committed
Add release workflow and separate versioning from CI
- Add release.yml triggered on version tags (v*.*.*) - Build and push Docker images with version and latest tags on release - Generate changelog and create GitHub Release automatically - Update CI to only push SHA-tagged images (no latest tag)
1 parent 4f02bef commit c848ff4

2 files changed

Lines changed: 81 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,4 @@ jobs:
5252
with:
5353
context: .
5454
push: true
55-
tags: |
56-
ghcr.io/browserup/sorcery-server:latest
57-
ghcr.io/browserup/sorcery-server:${{ github.sha }}
55+
tags: ghcr.io/browserup/sorcery-server:${{ github.sha }}

.github/workflows/release.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
packages: write
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Remove local cargo config
20+
run: rm -f .cargo/config.toml
21+
22+
- name: Install Rust
23+
uses: dtolnay/rust-action@stable
24+
25+
- name: Cache cargo
26+
uses: Swatinem/rust-cache@v2
27+
28+
- name: Build release binary
29+
run: cargo build --release
30+
31+
- name: Run tests
32+
run: cargo test
33+
34+
- name: Login to GHCR
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ghcr.io
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Extract version from tag
42+
id: version
43+
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
44+
45+
- name: Build and push Docker image
46+
uses: docker/build-push-action@v5
47+
with:
48+
context: .
49+
push: true
50+
tags: |
51+
ghcr.io/browserup/sorcery-server:${{ steps.version.outputs.VERSION }}
52+
ghcr.io/browserup/sorcery-server:latest
53+
54+
- name: Generate changelog
55+
id: changelog
56+
run: |
57+
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
58+
if [ -z "$PREVIOUS_TAG" ]; then
59+
CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges)
60+
else
61+
CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges ${PREVIOUS_TAG}..HEAD)
62+
fi
63+
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
64+
echo "$CHANGELOG" >> $GITHUB_OUTPUT
65+
echo "EOF" >> $GITHUB_OUTPUT
66+
67+
- name: Create GitHub Release
68+
uses: softprops/action-gh-release@v2
69+
with:
70+
name: Release ${{ github.ref_name }}
71+
body: |
72+
## What's Changed
73+
${{ steps.changelog.outputs.CHANGELOG }}
74+
75+
## Docker Image
76+
```bash
77+
docker pull ghcr.io/browserup/sorcery-server:${{ steps.version.outputs.VERSION }}
78+
```
79+
draft: false
80+
prerelease: ${{ contains(github.ref_name, '-') }}

0 commit comments

Comments
 (0)