-
Notifications
You must be signed in to change notification settings - Fork 189
162 lines (145 loc) · 5.54 KB
/
release.yml
File metadata and controls
162 lines (145 loc) · 5.54 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Release
on:
push:
branches:
- main
workflow_dispatch:
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
changelog:
name: Changelog
runs-on: ubuntu-latest
outputs:
hasChangesets: ${{ steps.changesets.outputs.hasChangesets }}
releaseExists: ${{ steps.published.outputs.exists }}
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: true
- name: Setup Node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
cache: npm
cache-dependency-path: package-lock.json
node-version-file: .nvmrc
- name: Install dependencies
run: npm ci --verbose
- name: Update release PR
id: changesets
uses: changesets/action@6a0a831ff30acef54f2c6aa1cbbc1096b066edaf # v1.7.0
with:
commit: "chore: release"
title: "chore: release"
version: npm run version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check if publish is needed
id: published
if: steps.changesets.outputs.hasChangesets == 'false'
run: |
VERSION=$(node -p "require('./package.json').version")
if gh release view "v${VERSION}" &>/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
name: Publish
needs: changelog
if: needs.changelog.outputs.hasChangesets == 'false' && needs.changelog.outputs.releaseExists == 'false'
runs-on: ubuntu-latest
environment: publish
permissions:
contents: write
steps:
- name: Gather credentials
id: credentials
uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
with:
client-id: ${{ secrets.GH_APP_CLIENT_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ github.event.repository.name }}
permission-contents: write
- name: Checkout repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: true
token: ${{ steps.credentials.outputs.token }}
- name: Setup Node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
cache: npm
cache-dependency-path: package-lock.json
node-version-file: .nvmrc
- name: Install dependencies
run: npm ci --verbose
- name: Build a production release
run: npm run build
- name: Gather version
id: version
run: |
VERSION="v$(node -p 'require("./package.json").version')"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "major=$(echo "$VERSION" | cut -d. -f1)" >> "$GITHUB_OUTPUT"
echo "minor=$(echo "$VERSION" | cut -d. -f1-2)" >> "$GITHUB_OUTPUT"
echo "$VERSION"
- name: Check if release exists
id: check
run: |
if gh release view "$VERSION" &>/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
env:
VERSION: ${{ steps.version.outputs.version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create release artifacts
if: steps.check.outputs.exists == 'false'
id: release
run: |
awk '/^## /{if(n++)exit}n' CHANGELOG.md | tail -n +3 > RELEASE.md
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b "release/$VERSION"
git rm -rf .
git checkout HEAD -- LICENSE
git checkout HEAD -- README.md
git checkout HEAD -- action.yml
git checkout HEAD -- cli/
git add --force dist/
git commit -m "chore: release"
git push origin "release/$VERSION"
SHA=$(git rev-parse HEAD)
git tag -f "$MAJOR" "$SHA"
git tag -f "$MINOR" "$SHA"
git push -f origin "$MAJOR" "$MINOR"
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
env:
VERSION: ${{ steps.version.outputs.version }}
MAJOR: ${{ steps.version.outputs.major }}
MINOR: ${{ steps.version.outputs.minor }}
- name: Create GitHub release
if: steps.check.outputs.exists == 'false'
run: gh release create "$VERSION" --target "$SHA" --title "Slack GitHub Action $VERSION" --notes-file RELEASE.md
env:
VERSION: ${{ steps.version.outputs.version }}
SHA: ${{ steps.release.outputs.sha }}
GH_TOKEN: ${{ steps.credentials.outputs.token }}
- name: Notify Slack
if: steps.check.outputs.exists == 'false'
uses: slackapi/slack-github-action@03ea5433c137af7c0495bc0cad1af10403fc800c # v3.0.2
with:
webhook: ${{ secrets.SLACK_RELEASE_ANNOUNCEMENTS_WEBHOOK_URL }}
webhook-type: webhook-trigger
payload: |
action_url: "https://github.com/${{ github.repository }}/releases/tag/${{ steps.version.outputs.version }}"
message: "Slack GitHub Action ${{ steps.version.outputs.version }}"
repository: "${{ github.repository }}"