-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (86 loc) · 3.43 KB
/
Copy pathrelease.yml
File metadata and controls
101 lines (86 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Release
# Runs on every push to main except the version-bump commit this workflow
# produces, preventing an infinite loop.
on:
push:
branches: [main]
jobs:
release:
if: "!startsWith(github.event.head_commit.message, 'chore: release')"
runs-on: ubuntu-latest
permissions:
contents: write # push version bump + tag, create release
packages: write # push Docker image to ghcr.io
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # full history so we can inspect commits since last tag
- uses: pnpm/action-setup@v4
with:
version: 10
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
# Inspect commit messages since the last tag (or all commits if no tag
# yet) and pick a semver bump level using conventional commits:
# BREAKING CHANGE or ! suffix → major
# feat: → minor
# anything else → patch
- name: Determine version bump
id: semver
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LATEST_TAG" ]; then
COMMITS=$(git log --pretty=format:"%s%n%b")
else
COMMITS=$(git log "${LATEST_TAG}..HEAD" --pretty=format:"%s%n%b")
fi
BUMP="patch"
while IFS= read -r line; do
if echo "$line" | grep -qE "BREAKING[- ]CHANGE|^[a-z]+(\(.+\))?!:"; then
BUMP="major"
break
elif echo "$line" | grep -qE "^feat(\(.+\))?:"; then
if [ "$BUMP" = "patch" ]; then BUMP="minor"; fi
fi
done <<< "$COMMITS"
echo "bump=$BUMP" >> "$GITHUB_OUTPUT"
- name: Bump version in package.json
id: version
run: |
NEW_VERSION=$(npm version ${{ steps.semver.outputs.bump }} --no-git-tag-version)
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ steps.version.outputs.new_version }}
ghcr.io/${{ github.repository }}:latest
# Commit the package.json bump, tag it, and push. Requires that the
# github-actions bot is allowed to push to main (configure via branch
# protection → "Allow specific actors to bypass required pull requests").
- name: Commit, tag, and push
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json
git commit -m "chore: release ${{ steps.version.outputs.new_version }}"
git tag -a "${{ steps.version.outputs.new_version }}" -m "Release ${{ steps.version.outputs.new_version }}"
git push origin main --follow-tags
- name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ steps.version.outputs.new_version }}" \
--title "${{ steps.version.outputs.new_version }}" \
--generate-notes