-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (74 loc) · 3.03 KB
/
release.yml
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
name: Publish Package to npmjs
on:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
cache: "npm"
- run: git config --global user.email "[email protected]"
- run: git config --global user.name "Michael Wuergler"
- run: npm ci
- name: Extract version from tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Check for pre-release
id: check_pre_release
run: |
if [[ "${{ env.RELEASE_VERSION }}" == *-* ]]; then
echo "IS_PRE_RELEASE=true" >> $GITHUB_ENV
echo "RELEASE_TAG=next" >> $GITHUB_ENV
else
echo "IS_PRE_RELEASE=false" >> $GITHUB_ENV
echo "RELEASE_TAG=latest" >> $GITHUB_ENV
fi
- run: npm version ${{ env.RELEASE_VERSION }} --no-git-tag-version
- run: npm run build
- name: Publish to npm
run: npm publish --tag ${{ env.RELEASE_TAG }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Commit and push version bump
if: env.IS_PRE_RELEASE == 'false'
run: |
git checkout -b version-bump/${{ env.RELEASE_VERSION }}
git add package.json package-lock.json
git commit -m "chore: bump version to ${{ env.RELEASE_VERSION }}"
git push origin version-bump/${{ env.RELEASE_VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Show diff for debugging
run: git diff
# Create a Pull Request with the version bump if the release is not a pre-release
- name: Create Pull Request for Version Bump
if: success() && env.IS_PRE_RELEASE == 'false'
id: create_pull_request
uses: peter-evans/create-pull-request@v7
with:
commit-message: Update package version to ${{ env.RELEASE_VERSION }}
title: "chore: update package version to ${{ env.RELEASE_VERSION }}"
body: "Updates `package.json` version to `${{ env.RELEASE_VERSION }}`."
branch: version-bump/${{ env.RELEASE_VERSION }}
labels: version-bump
token: ${{ secrets.GITHUB_TOKEN }}
base: main
# Auto-merge the Pull Request with the version bump if the release is not a pre-release
- name: Enable Auto-Merge
if: success() && env.IS_PRE_RELEASE == 'false'
uses: peter-evans/enable-pull-request-automerge@v3
with:
pull-request-number: ${{ steps.create_pull_request.outputs.pull-request-number }}
token: ${{ secrets.GITHUB_TOKEN }}
merge-method: squash
# Clean up the version bump branch after merge
- name: Delete Version Bump Branch
if: success() && env.IS_PRE_RELEASE == 'false'
run: |
git push origin --delete version-bump/${{ env.RELEASE_VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}