-
Notifications
You must be signed in to change notification settings - Fork 1
134 lines (116 loc) · 4.19 KB
/
release.yml
File metadata and controls
134 lines (116 loc) · 4.19 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
name: Release
on:
push:
branches:
- master
- "release/*"
workflow_dispatch:
inputs:
version-type:
description: "Version bump type"
required: true
default: "patch"
type: choice
options:
- patch
- minor
- major
- prerelease
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
version-bump:
name: Version Bump & Release
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'chore(release):')"
outputs:
version: ${{ steps.version.outputs.new_version }}
tag: ${{ steps.version.outputs.tag }}
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run verify
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Check actor permission
id: check_perm
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PERM=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/collaborators/${{ github.actor }}/permission" \
| python -c "import sys, json; print(json.load(sys.stdin).get('permission',''))")
echo "permission=$PERM" >> $GITHUB_OUTPUT
- name: Determine version bump
id: bump-type
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "type=${{ github.event.inputs.version-type }}" >> $GITHUB_OUTPUT
else
# Auto-detect version bump based on commit messages
if git log --format=%B -n 20 | grep -q "BREAKING CHANGE\|!:"; then
echo "type=major" >> $GITHUB_OUTPUT
elif git log --format=%B -n 20 | grep -qE "^feat(\(.+\))?:"; then
echo "type=minor" >> $GITHUB_OUTPUT
else
echo "type=patch" >> $GITHUB_OUTPUT
fi
fi
- name: Bump version
id: version
run: |
npm version ${{ steps.bump-type.outputs.type }} --no-git-tag-version
NEW_VERSION=$(node -p "require('./package.json').version")
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Update CHANGELOG
run: |
if [ ! -f CHANGELOG.md ]; then
echo "# Changelog" > CHANGELOG.md
echo "" >> CHANGELOG.md
fi
# Add new version entry
sed -i "2i\\## [${{ steps.version.outputs.new_version }}] - $(date +%Y-%m-%d)\n" CHANGELOG.md
- name: Commit and tag
run: |
git add package.json CHANGELOG.md
git commit -m "chore(release): bump version to ${{ steps.version.outputs.new_version }}"
git tag ${{ steps.version.outputs.tag }}
git push origin HEAD --tags
- name: Create GitHub Release
if: steps.check_perm.outputs.permission == 'write' || steps.check_perm.outputs.permission == 'admin'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.tag }}
release_name: Release ${{ steps.version.outputs.new_version }}
body: |
## Changes
See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/${{ steps.version.outputs.tag }}/CHANGELOG.md) for details.
## Installation
```bash
npm install @typeup/dom@${{ steps.version.outputs.new_version }}
```
draft: false
prerelease: ${{ contains(steps.version.outputs.new_version, '-') }}