-
Notifications
You must be signed in to change notification settings - Fork 1
186 lines (158 loc) · 5.73 KB
/
Copy pathrelease.yml
File metadata and controls
186 lines (158 loc) · 5.73 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
name: Release
on:
push:
branches: [main]
workflow_dispatch:
inputs:
version:
description: 'Override version (e.g. 1.2.3). Leave empty for auto-detection.'
required: false
type: string
permissions:
contents: write
jobs:
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.calc.outputs.version }}
skip: ${{ steps.calc.outputs.skip }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Calculate version from conventional commits
id: calc
run: |
set -euo pipefail
# Manual override takes precedence
if [[ -n "${OVERRIDE_VERSION}" ]]; then
echo "version=${OVERRIDE_VERSION}" >> "$GITHUB_OUTPUT"
echo "skip=false" >> "$GITHUB_OUTPUT"
echo "Using manual override: v${OVERRIDE_VERSION}"
exit 0
fi
# Get latest tag, default to v0.0.0 if none exist
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
CURRENT=${LATEST_TAG#v}
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
echo "Latest tag: ${LATEST_TAG} (${MAJOR}.${MINOR}.${PATCH})"
# Get commit subjects since last tag
if [[ "$LATEST_TAG" == "v0.0.0" ]]; then
SUBJECTS=$(git log --pretty=format:"%s")
BODIES=$(git log --pretty=format:"%b")
else
SUBJECTS=$(git log "${LATEST_TAG}..HEAD" --pretty=format:"%s")
BODIES=$(git log "${LATEST_TAG}..HEAD" --pretty=format:"%b")
fi
if [[ -z "$SUBJECTS" ]]; then
echo "No commits since last tag — skipping release"
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Commits since ${LATEST_TAG}:"
echo "$SUBJECTS" | sed 's/^/ /'
# Collect candidate conventional-commit lines from both subjects
# and body bullets. GitHub squash-merges put the PR title in the
# subject and nest each original commit as "* type: ..." in the
# body, so scanning subjects alone misses squash-merged PRs whose
# title is not itself a conventional commit.
CANDIDATES=$(
printf '%s\n' "$SUBJECTS"
printf '%s\n' "$BODIES" | sed -nE 's/^[[:space:]]*\*[[:space:]]+//p'
)
# Determine bump type from conventional commits
# Priority: major > minor > patch > none
BUMP="none"
# Check bodies for BREAKING CHANGE footer
if echo "$BODIES" | grep -qE "^BREAKING[ -]CHANGE:"; then
BUMP="major"
fi
while IFS= read -r msg; do
# type(scope)!: description → major
if echo "$msg" | grep -qE '^[a-z]+(\(.+\))?!:'; then
BUMP="major"
fi
# feat → minor (unless already major)
if echo "$msg" | grep -qE '^feat(\(.+\))?:'; then
[[ "$BUMP" == "none" || "$BUMP" == "patch" ]] && BUMP="minor"
fi
# fix, perf, refactor → patch
if echo "$msg" | grep -qE '^(fix|perf|refactor)(\(.+\))?:'; then
[[ "$BUMP" == "none" ]] && BUMP="patch"
fi
done <<< "$CANDIDATES"
if [[ "$BUMP" == "none" ]]; then
echo "No releasable commits (only docs/ci/chore/etc.) — skipping release"
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# Calculate next version
case "$BUMP" in
major) NEXT="$((MAJOR + 1)).0.0" ;;
minor) NEXT="${MAJOR}.$((MINOR + 1)).0" ;;
patch) NEXT="${MAJOR}.${MINOR}.$((PATCH + 1))" ;;
esac
echo "Bump type: ${BUMP} → v${NEXT}"
echo "version=${NEXT}" >> "$GITHUB_OUTPUT"
echo "skip=false" >> "$GITHUB_OUTPUT"
env:
OVERRIDE_VERSION: ${{ inputs.version }}
build:
needs: version
if: needs.version.outputs.skip != 'true'
strategy:
matrix:
include:
- target: aarch64-macos
name: darwin-aarch64
- target: x86_64-macos
name: darwin-x86_64
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- uses: mlugg/setup-zig@v2
with:
version: 0.15.2
- name: Run tests
if: matrix.target == 'aarch64-macos'
run: zig build test -Dversion=${{ needs.version.outputs.version }}
- name: Build release binary
run: zig build -Doptimize=ReleaseFast -Dtarget=${{ matrix.target }} -Dversion=${{ needs.version.outputs.version }}
- name: Rename binary
run: mv zig-out/bin/bru bru-${{ matrix.name }}
- uses: actions/upload-artifact@v4
with:
name: bru-${{ matrix.name }}
path: bru-${{ matrix.name }}
release:
needs: [version, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Create release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
chmod +x artifacts/bru-*
gh release create "v${{ needs.version.outputs.version }}" \
--title "v${{ needs.version.outputs.version }}" \
--generate-notes \
artifacts/bru-darwin-aarch64 \
artifacts/bru-darwin-x86_64
deploy-pages:
needs: release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./pages
force_orphan: true