-
Notifications
You must be signed in to change notification settings - Fork 0
245 lines (233 loc) · 10.7 KB
/
release.yaml
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: Release
on:
push:
branches:
- main
tags-ignore:
- "**"
jobs:
submodules-finder:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.interrogate.outputs.result }}
exists: ${{ steps.interrogate.outputs.submodule-exists }}
steps:
- uses: actions/checkout@v3
- id: interrogate
uses: ./actions/monorepo-workspace-submodules-finder
with:
ignore-private: true
only-changed-since: latest release
- name: Check GitHub API rate limit
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SUBMODULES_JSON: ${{ steps.interrogate.outputs.result }}
run: |
RATE_LIMIT_JSON="$(gh api 'rate_limit')"
RATE_LIMIT_JSON_ARRAY="$(echo "${RATE_LIMIT_JSON}" | jq -r '.resources | [.core, .graphql]')"
RATE_LIMIT_REMAINING="$(echo "${RATE_LIMIT_JSON_ARRAY}" | jq -r 'map_values(.remaining) | min')"
submodules_count="$(echo "${SUBMODULES_JSON}" | jq -r '. | length')"
readonly RATE_LIMIT_JSON RATE_LIMIT_JSON_ARRAY RATE_LIMIT_REMAINING submodules_count
readonly needs_remaining="$((submodules_count * 4))"
echo '::group::RATE_LIMIT_JSON'
echo "${RATE_LIMIT_JSON}" | jq
echo '::endgroup::'
echo '::group::RATE_LIMIT_JSON_ARRAY'
echo "${RATE_LIMIT_JSON_ARRAY}"
echo '::endgroup::'
echo '::group::debug'
echo RATE_LIMIT_REMAINING ":${RATE_LIMIT_REMAINING};"
echo submodules_count ":${submodules_count};"
echo needs_remaining ":${needs_remaining};"
echo '::endgroup::'
if [ "${RATE_LIMIT_REMAINING}" -lt "${needs_remaining}" ]; then
RATE_LIMIT_RESET="$(echo "${RATE_LIMIT_JSON_ARRAY}" | jq -r 'map_values(.reset) | max')"
readonly RATE_LIMIT_RESET
echo "::error::Rate limit is approaching. Requires ${needs_remaining}, but remainder is ${RATE_LIMIT_REMAINING}. Please wait until $(date -ud "@${RATE_LIMIT_RESET}" '+%Y/%m/%d %T %Z')"
exit 1
fi
release-please:
runs-on: ubuntu-latest
needs: submodules-finder
if:
# If the result of the submodules-finder is an empty array, then an invalid value was specified for the matrix strategy, this job will fail, and the release workflow will also fail.
# To avoid this, run this job only if the array is not empty.
needs.submodules-finder.outputs.exists
strategy:
fail-fast: false
matrix:
include: ${{fromJson(needs.submodules-finder.outputs.result)}}
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: node
package-name: ${{ matrix.package-name }}
path: ${{ matrix.path-git-relative }}
monorepo-tags: true
token:
${{ secrets.GITHUB_TOKEN }}
# The "token" parameter is optional.
# However, it may cause an error due to the rate limit of GitHub API.
# Therefore, it should be specified explicitly.
#
# Commit to PR
#
- name: Commit to Release PR / Checkout
uses: actions/checkout@v3
with:
ref: ${{ fromJson(steps.release.outputs.pr).headBranchName }}
token: ${{ secrets.TRIGGER_TEST_GITHUB_TOKEN }}
# All commit logs are required to update CHANGELOG.md by scripts/fix-changelog.mjs
fetch-depth: 0
if: ${{ ! steps.release.outputs.releases_created && steps.release.outputs.pr }}
- name: Commit to Release PR / Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16.x
if: ${{ ! steps.release.outputs.releases_created && steps.release.outputs.pr }}
- name: Commit to Release PR / Cache .pnpm-store
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-node-16.x-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-node-16.x-
${{ runner.os }}-node-
${{ runner.os }}-
if: ${{ ! steps.release.outputs.releases_created && steps.release.outputs.pr }}
- name: Commit to Release PR / Setup pnpm
uses: ./actions/setup-pnpm
if: ${{ ! steps.release.outputs.releases_created && steps.release.outputs.pr }}
- name: Commit to Release PR / Install Dependencies
run: pnpm install
if: ${{ ! steps.release.outputs.releases_created && steps.release.outputs.pr }}
- name: Commit to Release PR / Push to PR
shell: bash
# https://qiita.com/kawaz/items/1b61ee2dd4d1acc7cc94
# https://fumiyas.github.io/2016/12/15/positional-parameters.sh-advent-calendar.html
run: |
readonly CUSTOM_RELEASE_SCRIPT_PATH='.github/workflows/post-release.sh'
readonly CUSTOM_RELEASE_SCRIPT_FULLPATH="${{ matrix.path-git-relative }}/${CUSTOM_RELEASE_SCRIPT_PATH}"
origGit="$(command -v git)"
readonly origGit
git() {
if [ "$1" = 'commit' ]; then
shift
"${origGit}" commit --author='github-actions[bot] <release-workflow+github-actions[bot]@users.noreply.github.com>' "$@"
else
"${origGit}" "$@"
fi
}
git config user.name 'GitHub'
git config user.email '[email protected]'
beforeCommitHash="$(git log --format=%H -n 1)"
readonly beforeCommitHash
echo '::group::' fix changelog
{
node scripts/fix-changelog.mjs '${{ matrix.path-git-relative }}' &&
git add '${{ matrix.path-git-relative }}/CHANGELOG.md' &&
git commit -m 'docs(${{ matrix.package-name }}): fix changelog' ;
} || true
echo '::endgroup::'
echo '::group::' update package list
{
pnpm run build:package-list &&
git add ./README.md &&
git commit -m 'docs: update package list' ;
} || true
echo '::endgroup::'
if [ -x "${CUSTOM_RELEASE_SCRIPT_FULLPATH}" ]; then
(
echo '::group::' loading "${CUSTOM_RELEASE_SCRIPT_FULLPATH}"
cd '${{ matrix.path-git-relative }}'
# shellcheck source=/dev/null
. "${CUSTOM_RELEASE_SCRIPT_PATH}"
echo '::endgroup::'
)
fi
if [ "${beforeCommitHash}" = "$(git log --format=%H -n 1)" ]; then
echo '::group::$' git commit --allow-empty -m '"chore: trigger tests"'
git commit --allow-empty -m 'chore: trigger tests'
echo '::endgroup::'
fi
echo '::group::$' git push
git push
echo '::endgroup::'
if: ${{ ! steps.release.outputs.releases_created && steps.release.outputs.pr }}
#
# Publish
#
- name: Publish / Checkout
uses: actions/checkout@v3
if: ${{ steps.release.outputs.releases_created }}
- name: Publish / Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16.x
registry-url: https://registry.npmjs.org
# Note: The `registry-url` option is required.
# If this option is not set, the "npm publish" command will not detect the environment variable NODE_AUTH_TOKEN.
if: ${{ steps.release.outputs.releases_created }}
- name: Publish / Cache .pnpm-store
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-node-16.x-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-node-16.x-
${{ runner.os }}-node-
${{ runner.os }}-
if: ${{ steps.release.outputs.releases_created }}
- name: Publish / Setup pnpm
uses: ./actions/setup-pnpm
if: ${{ steps.release.outputs.releases_created }}
- name: Publish / Install Dependencies
run: pnpm install
if: ${{ steps.release.outputs.releases_created }}
- name: Publish / Build
run: pnpm exec ultra --recursive --filter '+${{ matrix.path-git-relative }}' --build pnpm run --if-present build
# If there are other submodules in the dependency, it may be necessary to build the dependent submodule.
# Therefore, build only the submodules included in the required dependencies.
#
# Note: If the "build" script does not exist in the npm-scripts, the ultra-runner will attempt to execute the "build" command.
# And since the "build" command does not exist, the execution will fail.
# For this reason, use the "pnpm run" command and always run "build" in npm-scripts.
# If the "--if-present" option is added, no error will occur even if the "build" script does not exist.
#
# Note: DO NOT add the "--if-present" option to the end of the command.
# Execution by ultra-runner will fail.
if: ${{ steps.release.outputs.releases_created }}
- name: Publish / Update README
run: |
node ./scripts/publish-convert-readme.mjs '${{ steps.release.outputs.tag_name }}' '${{ matrix.path-git-relative }}/README.md'
if: ${{ steps.release.outputs.releases_created }}
- name: Publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: |
readonly CUSTOM_PUBLISH_SCRIPT_PATH=.github/workflows/publish.sh
cd '${{ matrix.path-git-relative }}'
if [ -x "${CUSTOM_PUBLISH_SCRIPT_PATH}" ]; then
export GITHUB_TOKEN='${{ secrets.GITHUB_TOKEN }}'
export matrix_package_name_with_scope='${{ matrix.package-name }}'
export matrix_package_name_without_scope='${{ matrix.no-scope-package-name }}'
export outputs_upload_url='${{ steps.release.outputs.upload_url }}'
export outputs_html_url='${{ steps.release.outputs.html_url }}'
export outputs_tag_name='${{ steps.release.outputs.tag_name }}'
export outputs_major='${{ steps.release.outputs.major }}'
export outputs_minor='${{ steps.release.outputs.minor }}'
export outputs_patch='${{ steps.release.outputs.patch }}'
export outputs_sha='${{ steps.release.outputs.sha }}'
export outputs_pr='${{ fromJson(steps.release.outputs.pr).number }}'
export outputs_pr_json='${{ steps.release.outputs.pr }}'
echo loading "${CUSTOM_PUBLISH_SCRIPT_PATH}"
# shellcheck source=/dev/null
source "${CUSTOM_PUBLISH_SCRIPT_PATH}"
else
# see https://stackoverflow.com/a/62675843/4907315
pnpm publish --access=public --no-git-checks
fi
shell: bash
if: ${{ steps.release.outputs.releases_created }}