-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (65 loc) · 2.77 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
# reference: https://semantic-release.gitbook.io/semantic-release/recipes/ci-configurations/github-actions
name: Release
run-name: ${{ github.actor }} is performing release on ${{ github.ref_name }} with ${{ github.sha }} 🚀
on: [ workflow_dispatch ]
permissions:
contents: read # for checkout
jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
id-token: write # to enable use of OIDC for npm provenance
steps:
- name: Ensure the branch is 'release/main'
if: github.ref_name != 'release/main'
run: |
echo "release can only run on branch release/main"
exit 1
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "lts/*"
- name: Install dependencies
run: npm clean-install
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
run: npm audit signatures
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
# reference:
# * https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#create-a-pull-request
# * https://docs.github.com/en/rest/guides/getting-started-with-the-rest-api?apiVersion=2022-11-28#authentication-example-for-github-actions
# * https://docs.github.com/en/actions/using-workflows/using-github-cli-in-workflows
# grant PR permission to GitHub Actions: `Allow GitHub Actions to create and approve pull requests`
# * https://github.com/huaichaow/marked-toc-extension/settings/actions
- name: Create PR to main branch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Creating PR"
pr_number="$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/huaichaow/marked-toc-extension/pulls \
-f title='regular release' \
-f body='Please pull these release!' \
-f head='release/main' \
-f base='main' --jq '.number')"
echo "Merging PR ${pr_number}"
gh api \
--method PUT \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/huaichaow/marked-toc-extension/pulls/${pr_number}/merge \
-f merge_method=rebase