-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (101 loc) · 3.48 KB
/
Copy pathrelease.yml
File metadata and controls
120 lines (101 loc) · 3.48 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version number (e.g., v1.0.0)'
required: true
type: string
prerelease:
description: 'Mark as pre-release'
required: false
type: boolean
default: false
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate version format
run: |
if [[ ! "${{ inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
echo "Error: Version must be in format v1.2.3 or v1.2.3-beta.1"
exit 1
fi
- name: Check if tag exists
run: |
if git rev-parse "${{ inputs.version }}" >/dev/null 2>&1; then
echo "Error: Tag ${{ inputs.version }} already exists"
exit 1
fi
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '24'
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 9
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run checks
run: pnpm run check
- name: Build
run: pnpm run build
- name: Update package.json version
run: |
VERSION="${{ inputs.version }}"
VERSION_WITHOUT_V="${VERSION#v}"
npm version "$VERSION_WITHOUT_V" --no-git-tag-version
- name: Commit version bump
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: bump version to ${{ inputs.version }}"
git push
- name: Create and push tag
run: |
git tag "${{ inputs.version }}"
git push origin "${{ inputs.version }}"
- name: Generate changelog
id: changelog
run: |
# Get the previous tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
# First release, get all commits
CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges)
else
# Get commits since previous tag
CHANGELOG=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges)
fi
# Save changelog to file
echo "$CHANGELOG" > changelog.txt
# Also save to output for GitHub release
echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ inputs.version }}
release_name: Release ${{ inputs.version }}
body_path: changelog.txt
draft: false
prerelease: ${{ inputs.prerelease }}
- name: Summary
run: |
echo "## Release Created! 🎉" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "**Pre-release:** ${{ inputs.prerelease }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Changelog" >> $GITHUB_STEP_SUMMARY
cat changelog.txt >> $GITHUB_STEP_SUMMARY