-
-
Notifications
You must be signed in to change notification settings - Fork 171
84 lines (82 loc) · 2.95 KB
/
publish.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
79
80
81
82
83
84
name: Publish
on:
workflow_dispatch:
inputs:
version_type:
type: choice
description: Version type
default: minor
options:
- major
- minor
- patch
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: refs/heads/main
- name: Setup git repo
run: |
git config user.name $GITHUB_ACTOR
git config user.email gh-actions-${GITHUB_ACTOR}@github.com
git remote add gh-origin https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm install
- name: Version
run: |
npm version ${{ github.event.inputs.version_type }} --force -m "Version %s"
- name: Push release commit and tag to GitHub
id: push
run: |
git push gh-origin HEAD:main --tags
echo "tag-name=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT
- name: Publish to npm
run: |
npm set //registry.npmjs.org/:_authToken ${{ secrets.NODE_AUTH_TOKEN }}
npm publish
- uses: actions/upload-artifact@v3
if: failure()
with:
name: npm-logs
path: ~/.npm/_logs
- name: Package release assets
run: |
zip assets.zip i18n.js i18n.d.ts
zip -gr assets.zip dist/ locales/
- name: Create a Release
id: create-release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.push.outputs.tag-name }}
generate_release_notes: true
files: assets.zip
- name: Comment on PRs with link to release they are included in
uses: actions/github-script@v6
env:
RELEASE_ID: ${{ steps.create-release.outputs.id }}
with:
script: |
const releaseId = process.env.RELEASE_ID;
console.log(`Fetching release_id: ${releaseId} ...`);
const getReleaseResponse = await github.rest.repos.getRelease({
release_id: process.env.RELEASE_ID,
owner: context.repo.owner,
repo: context.repo.repo
});
const release = getReleaseResponse.data;
const prNumbersInRelease = new Set(Array.from(release.body.matchAll(/\/pull\/(\d+)/g)).map(p=>p[1]));
for(let prNumber of prNumbersInRelease) {
console.log(`Adding comment on PR #${prNumber} ...`);
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: `The changes in this PR were just released in [${release.name}](https://github.com/${context.repo.owner}/${context.repo.repo}/releases/tag/${release.tag_name}) 🎉.`
})
}