-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (115 loc) · 3.76 KB
/
release.yml
File metadata and controls
129 lines (115 loc) · 3.76 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
# Reusable workflow for releasing GitHub Actions
#
# Usage:
# jobs:
# release:
# uses: actions-mn/shared/.github/workflows/release.yml@main
# with:
# version: '1.2.0' # Optional, defaults to package.json version
# create_release: true
name: Release
on:
workflow_call:
inputs:
version:
description: 'Version to release (e.g., 1.2.0, leave empty to use package.json version)'
required: false
type: string
create_release:
description: 'Create a GitHub Release'
required: false
type: boolean
default: true
git_user_email:
description: 'Git user email for commits'
required: false
type: string
default: '41898282+github-actions[bot]@users.noreply.github.com'
git_user_name:
description: 'Git user name for commits'
required: false
type: string
default: 'github-actions[bot]'
release_body:
description: 'Release body template (optional)'
required: false
type: string
default: ''
permissions:
contents: write
id-token: write
jobs:
release:
name: Release
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
- name: Install dependencies
run: |
for i in {1..3}; do
npm ci && break || sleep 10
done
- name: Get version
id: version
run: |
if [ -n "${{ inputs.version }}" ]; then
VERSION="${{ inputs.version }}"
else
VERSION=$(node -p "require('./package.json').version")
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_STEP_SUMMARY
echo "Releasing version: $VERSION"
- name: Update version in package.json
if: inputs.version != ''
run: |
VERSION="${{ steps.version.outputs.version }}"
npm version $VERSION --no-git-tag-version
git add package.json
git config user.email "${{ inputs.git_user_email }}"
git config user.name "${{ inputs.git_user_name }}"
git commit -m "chore: bump version to v$VERSION"
- name: Run tests
run: npm test
- name: Build
run: npm run build
- name: Commit dist
run: |
VERSION="${{ steps.version.outputs.version }}"
git config user.email "${{ inputs.git_user_email }}"
git config user.name "${{ inputs.git_user_name }}"
git add dist
git commit -m "chore: build v$VERSION" || echo "No dist changes to commit"
- name: Create and push tag
run: |
VERSION="${{ steps.version.outputs.version }}"
git tag -a "v$VERSION" -m "Release v$VERSION"
git push origin main
git push origin "v$VERSION"
- name: Update major version tag
run: |
VERSION="${{ steps.version.outputs.version }}"
MAJOR_VERSION=$(echo "$VERSION" | cut -d. -f1)
git tag -f "v$MAJOR_VERSION" "v$VERSION"
git push origin "v$MAJOR_VERSION" --force
echo "Updated v$MAJOR_VERSION to point to v$VERSION"
- name: Create GitHub Release
if: inputs.create_release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.version }}
name: v${{ steps.version.outputs.version }}
body: ${{ inputs.release_body }}
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}