-
Notifications
You must be signed in to change notification settings - Fork 8
200 lines (187 loc) · 8.13 KB
/
changeset-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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: Changeset Release
on:
workflow_call:
inputs:
os:
required: true
type: string
node-version:
required: true
type: string
concurrency:
group: changeset-release-${{ github.ref }}
cancel-in-progress: true
env:
HUSKY: 0
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
GITHUB_TOKEN: ${{ secrets.CHANGESETS_TOKEN }}
jobs:
changesets:
runs-on: ${{ inputs.os }}
if: github.repository == 'justeattakeaway/pie' && ${{ github.event_name != 'pull_request' }} &&
(contains(github.ref_name, 'main') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'feature'))
steps:
# Checkout the Repo
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
persist-credentials: false
# Setup Repo
- name: Setup Repo
uses: ./.github/actions/setup-repo
with:
node-version: ${{ inputs.node-version }}
os: ${{ inputs.os }}
- name: Append NPM token to .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
# Build Packages
- name: Build
if: ${{ github.event_name != 'pull_request' }} &&
(contains(github.ref_name, 'main') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'feature'))
uses: ./.github/actions/run-script
with:
script-name: "build"
- name: Check for pre.json file existence
id: check_files
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
with:
files: ".changeset/pre.json"
- name: exit prerelease mode
# If .changeset/pre.json does not exist and we did not recently exit
# prerelease mode.
if: steps.check_files.outputs.files_exists == 'true' && contains(github.ref_name, 'main')
run: npx changeset pre exit
- name: Create latest release PR
id: changesets-main
if: contains(github.ref_name, 'main')
uses: changesets/action@c8bada60c408975afd1a20b3db81d6eee6789308 # v1.4.9
with:
version: yarn changeset:version
publish: yarn changeset:publish
commit: "release: release packages with 'latest' tag"
# If .changeset/pre.json does not exist and we did not recently exit
# prerelease mode, enter prerelease mode with tag beta
- name: Enter beta prerelease mode
id: changesets-beta
if: steps.check_files.outputs.files_exists == 'false' && contains(github.ref_name, 'beta')
# If .changeset/pre.json does not exist and we did not recently exit
# prerelease mode, enter prerelease mode with tag beta
run: npx changeset pre enter beta
- name: Create beta release PR
if: contains(github.ref_name, 'beta')
uses: changesets/action@c8bada60c408975afd1a20b3db81d6eee6789308 # v1.4.9
with:
version: yarn changeset:version
publish: yarn changeset:publish
commit: "release: release packages with 'beta' tag"
- name: Enter feature prerelease mode
id: changesets-feature
if: steps.check_files.outputs.files_exists == 'false' && contains(github.ref_name, 'feature')
# If .changeset/pre.json does not exist and we did not recently exit
# prerelease mode, enter prerelease mode with tag next
run: npx changeset pre enter next
- name: Create feature release PR
if: contains(github.ref_name, 'feature')
uses: changesets/action@c8bada60c408975afd1a20b3db81d6eee6789308 # v1.4.9
with:
version: yarn changeset:version
publish: yarn changeset:publish
commit: "release: release packages with 'next' tag"
# This script performs the following logic:
# 1. Defines a list of packages with their versions.
# 2. Separates the 'pie-docs' and 'pie-storybook' packages, which have a higher priority, into a distinct list called `PRIORITIZED_PACKAGES`.
# 3. Filters out and creates a separate list (`REST_PACKAGES`) excluding:
# - The aforementioned 'pie-docs' and 'pie-storybook' packages.
# - Any package whose name starts with "wc-" (Example apps).
# - The 'pie-monorepo' package.
# 4. Combines the prioritized and the rest of the packages into one list (`COMBINED_PACKAGES`).
# 5. For each package in `COMBINED_PACKAGES`, creates a Slack message block:
# - For 'pie-docs', a specific message is generated pointing to 'pie.design'.
# - For 'pie-storybook', a distinct message is generated pointing to 'webc.pie.design'.
# - For all other packages, a generic message is generated, including links to the GitHub release and npm.
- name: Generate Slack payload blocks
if: steps.changesets-main.outputs.published == 'true'
id: generate_payload
run: |
PACKAGES='${{ steps.changesets-main.outputs.publishedPackages}}'
PRIORITIZED_PACKAGES=$(echo $PACKAGES | jq -c '[.[] | select(.name == "pie-docs" or .name == "pie-storybook")]')
REST_PACKAGES=$(echo $PACKAGES | jq -c '[.[] | select((.name != "pie-docs" and .name != "pie-storybook") and (.name | startswith("wc-") | not) and .name != "pie-monorepo")]')
PRIORITIZED_BLOCKS=$(echo $PACKAGES | jq -c '
map(select(.name == "pie-docs" or .name == "pie-storybook")) |
if length > 0 then
[{"type": "divider"}, {"type": "header", "text": {"type": "plain_text", "text": ":rocket: Deployment Summary"}}] +
(map(
if .name == "pie-docs" then
{
"type": "section",
"block_id": "sectionBlockWithButton",
"text": {
"type": "mrkdwn",
"text": "*PIE Docs*"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Visit :book:",
"emoji": true
},
"url": "https://pie.design"
}
}
elif .name == "pie-storybook" then
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*PIE Storybook*"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Visit :pie_team_logo:",
"emoji": true
},
"url": "https://webc.pie.design"
}
}
else
empty
end
))
else
.
end
')
REST_COMPONENT_BLOCKS=$(echo $REST_PACKAGES | jq -c '
if length > 0 then
[{"type": "divider"}] +
[{"type": "header", "text": {"type": "plain_text", "text": ":parcel: Package Update Summary"}}] +
map(
{"type": "section", "text": {"type": "mrkdwn", "text": "- *\(.name | sub("@justeattakeaway/pie-"; "") | (.[0:1] | ascii_upcase) + .[1:])* was updated to `\(.version)` | <https://github.com/justeattakeaway/pie/releases/tag/\(.name)@\(.version)|Changelog> | <https://www.npmjs.com/package/\(.name)|npm>" }}
)
else
[]
end
')
BLOCKS=$(echo "[${PRIORITIZED_BLOCKS},${REST_COMPONENT_BLOCKS}]" | jq -c 'add')
echo "BLOCKS=$BLOCKS" >> $GITHUB_ENV
- name: Send a Slack notification on publish
if: steps.changesets-main.outputs.published == 'true'
uses: slackapi/slack-github-action@fcfb566f8b0aab22203f066d80ca1d7e4b5d05b3 # v1.27.1
with:
channel-id: ${{ secrets.RELEASE_SLACK_CHANNEL_ID }}
payload: |
{
"blocks": ${{ env.BLOCKS }},
"unfurl_links": false,
"unfurl_media": false
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}