-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (68 loc) · 2.74 KB
/
plan-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: "🚀 Release on Comment"
on:
issue_comment:
types: [created]
jobs:
release:
runs-on: ubuntu-latest
if: github.event.issue.pull_request
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: ⬢ Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "16"
- name: 💬 Parse comment for release version
id: parse_version
run: |
COMMENT_BODY="${{ github.event.comment.body }}"
if [[ $COMMENT_BODY =~ ^release\ ([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
echo "RELEASE_VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
else
echo "Comment does not match 'release <semver>' format."
exit 1
fi
- name: 👍 Add thumbs-up reaction to comment
run: |
COMMENT_ID=${{ github.event.comment.id }}
curl -s -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.squirrel-girl-preview+json" \
-X POST "https://api.github.com/repos/${{ github.repository }}/issues/comments/$COMMENT_ID/reactions" \
-d '{"content":"+1"}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: ✍️ Update package.json version
run: |
jq '.version = env.RELEASE_VERSION' package.json > temp.json && mv temp.json package.json
shell: bash
- name: 🔖 Commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add package.json
git commit -m "chore(release): Set version to $RELEASE_VERSION"
- name: 📤 Push commit
run: |
git push origin "HEAD:${{ github.event.pull_request.head.ref }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: ✍️ Update PR title
run: |
DATE=$(date +'%Y-%m-%d')
gh pr edit ${{ github.event.issue.number }} --title "chore(release): $DATE ($RELEASE_VERSION)"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 📣 Post release confirmation comment
run: |
DATE=$(date +'%Y-%m-%d')
RELEASE_VERSION=${{ env.RELEASE_VERSION }}
COMMENT_BODY="### 🚀 Release planned: $DATE ($RELEASE_VERSION)"
curl -s -H "Authorization: token $GITHUB_TOKEN" \
-X POST "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \
-d "{\"body\": \"$COMMENT_BODY\"}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}