-
Notifications
You must be signed in to change notification settings - Fork 2
143 lines (121 loc) · 4.1 KB
/
prerelease.yml
File metadata and controls
143 lines (121 loc) · 4.1 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
name: Prerelease
on:
push:
branches:
- main
permissions:
contents: write
concurrency:
group: release
cancel-in-progress: false
jobs:
prerelease:
name: Prerelease
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "lts/*"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Determine next version and generate notes
id: version
run: |
# Get latest non-pre release tag
LATEST_TAG=$(git tag -l 'v*' | grep -v '\-pre' | sort -V | tail -1)
if [ -z "$LATEST_TAG" ]; then
echo "next=0.1.0" >> $GITHUB_OUTPUT
echo "No previous tag found" > release-notes.md
exit 0
fi
# Parse version components
VERSION=${LATEST_TAG#v}
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
# Get commit hashes and messages since last tag
COMMITS=$(git log ${LATEST_TAG}..HEAD --pretty=format:"%H %s" 2>/dev/null || echo "")
# Categorize commits
BREAKING=""
FEATURES=""
FIXES=""
OTHER=""
while IFS= read -r line; do
[ -z "$line" ] && continue
HASH=$(echo "$line" | cut -d' ' -f1)
MSG=$(echo "$line" | cut -d' ' -f2-)
SHORT_HASH=${HASH:0:7}
if echo "$MSG" | grep -qE "^.*!:|BREAKING CHANGE:"; then
BREAKING="${BREAKING}- ${MSG} (${SHORT_HASH})\n"
elif echo "$MSG" | grep -qE "^feat(\(.+\))?:"; then
FEATURES="${FEATURES}- ${MSG} (${SHORT_HASH})\n"
elif echo "$MSG" | grep -qE "^fix(\(.+\))?:"; then
FIXES="${FIXES}- ${MSG} (${SHORT_HASH})\n"
else
OTHER="${OTHER}- ${MSG} (${SHORT_HASH})\n"
fi
done <<< "$COMMITS"
# Determine bump type based on commits
if [ -n "$BREAKING" ]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [ -n "$FEATURES" ]; then
MINOR=$((MINOR + 1))
PATCH=0
else
PATCH=$((PATCH + 1))
fi
echo "next=${MAJOR}.${MINOR}.${PATCH}" >> $GITHUB_OUTPUT
# Generate release notes
{
echo "## What's Changed"
echo ""
if [ -n "$BREAKING" ]; then
echo "### Breaking Changes"
echo -e "$BREAKING"
fi
if [ -n "$FEATURES" ]; then
echo "### Features"
echo -e "$FEATURES"
fi
if [ -n "$FIXES" ]; then
echo "### Bug Fixes"
echo -e "$FIXES"
fi
if [ -n "$OTHER" ]; then
echo "### Other Changes"
echo -e "$OTHER"
fi
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${LATEST_TAG}...v${MAJOR}.${MINOR}.${PATCH}-pre"
} > release-notes.md
- name: Create or update pre-release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
NEXT_VERSION="${{ steps.version.outputs.next }}"
TAG="v${NEXT_VERSION}-pre"
# Delete existing release for this tag if it exists
if gh release view "$TAG" &>/dev/null; then
echo "Deleting existing release: $TAG"
gh release delete "$TAG" --yes || true
fi
# Delete the tag if it exists (locally and remotely)
if git rev-parse "$TAG" &>/dev/null; then
echo "Deleting existing tag: $TAG"
git tag -d "$TAG" || true
git push origin ":refs/tags/$TAG" || true
fi
# Create new pre-release with categorized notes
echo "Creating pre-release: $TAG"
gh release create "$TAG" \
--prerelease \
--notes-file release-notes.md \
--target main \
--title "$TAG"