This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
204 lines (197 loc) · 8.91 KB
/
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
201
202
203
204
on:
workflow_dispatch:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: "Release Manager"
jobs:
get-prs:
runs-on: ubuntu-latest
outputs:
pr_number: ${{ steps.get_prs.outputs.pr_number }}
steps:
- uses: actions/checkout@v4
# headがrelease/かつopenのPRを1つ取得
- name: Get PRs
run: |
echo "pr_number=$(gh pr list --limit 1 --search "head:release/ is:open" --json number --jq '.[] | .number')" >> $GITHUB_OUTPUT
id: get_prs
dispatch-release:
permissions:
contents: write
issues: write
pull-requests: write
needs: get-prs
runs-on: ubuntu-latest
if: ${{ needs.get-prs.outputs.pr_number != '' }}
# 開いているリリースのパッチバージョンを上げる
name: "Dispatch Release"
steps:
- uses: actions/checkout@v4
- name: git config
run: |
git config --local user.email "[email protected]"
git config --local user.name "LuckyBeast"
# pr_numberからPR情報を取得
- name: Get PR
run: |
PR_JSON=$(gh pr view ${{ needs.get-prs.outputs.pr_number }} --json isDraft,headRefName)
echo "PR_IS_DRAFT=$(echo $PR_JSON | jq -r '.isDraft')" >> $GITHUB_OUTPUT
echo "PR_HEAD_REF=$(echo $PR_JSON | jq -r '.headRefName')" >> $GITHUB_OUTPUT
id: get_pr
# checkout PR
- uses: actions/checkout@v4
with:
ref: ${{ steps.get_pr.outputs.PR_HEAD_REF }}
# jqでpackage.jsonから現在のバージョンを取得
- name: Get current version
run: |
jq -r '.version' package.json
echo "current_version=$(jq -r '.version' package.json)" >> $GITHUB_OUTPUT
id: get_current_version
# current_versionを加工してtarget_versionを取得
- name: Get target version
uses: actions/script@v7
env:
CURRENT_VERSION: ${{ steps.get_current_version.outputs.current_version }}
with:
script: |
return process.env.CURRENT_VERSION.split('-')[0];
result-encoding: string
id: next_target_version
# バージョンをインクリメント
- name: Increment version
uses: actions/script@v7
env:
CURRENT_VERSION: ${{ steps.get_current_version.outputs.current_version }}
PR_IS_DRAFT: ${{ steps.get_pr.outputs.PR_IS_DRAFT == 'true' }}
with:
script: |
console.log(process.env.PR_IS_DRAFT, '${{ steps.get_pr.outputs.PR_IS_DRAFT }}')
const [major, minor, _patch, _pre] = process.env.CURRENT_VERSION.split('.');
const pre = Number(_pre);
if (Number.isNaN(pre)) {
console.error('Invalid pre version', year, month, process.env.CURRENT_VERSION, major, minor, _patch);
throw new Error('Invalid pre version');
}
if (process.env.PR_IS_DRAFT) {
if (_patch.endsWith('beta')) {
return `${major}.${minor}.${_patch}.${pre + 1}`;
}
return `${major}.${minor}.${_patch.split('-')[0]}-beta.${pre + 1}`;
}
if (_patch.endsWith('rc')) {
return `${major}.${minor}.${_patch}.${pre + 1}`;
}
return `${major}.${minor}.${_patch.split('-')[0]}-rc.${pre + 1}`;
result-encoding: string
id: next_release_version
# バージョンをpackage.jsonに書き込み
- name: Write version
run: |
jq '.version = "${{ steps.next_release_version.outputs.result }}"' package.json > package.json.tmp && mv package.json.tmp package.json
jq '.version = "${{ steps.next_release_version.outputs.result }}"' packages/misskey-js/package.json > packages/misskey-js/package.json.tmp && mv packages/misskey-js/package.json.tmp packages/misskey-js/package.json
# release/ブランチとタグを作成
- name: Commit version
run: |
git commit -am "Bump version to ${{ steps.next_release_version.outputs.result }}"
git push origin HEAD:release/${{ steps.next_target_version.outputs.result }}
git tag "${{ steps.next_release_version.outputs.result }}"
git push origin "${{ steps.next_release_version.outputs.result }}"
# CHANGELOG.mdのUnreleasedの内容を取得
- name: Get changelog
run: |
{
echo 'changelog<<EOF'
sed -n '/## ${{ steps.next_target_version.outputs.result }}/,/^## /p' CHANGELOG.md | sed -e 1d -e '$d'
echo EOF
} >> $GITHUB_OUTPUT
id: changelog
# リリースを作成
- name: Create release
run: |
gh release create "${{ steps.next_release_version.outputs.result }}" --prerelease --title "${{ steps.next_release_version.outputs.result }}" --notes "${{ steps.changelog.outputs.changelog }}"
# PRのnotesを更新
- name: Update PR
run: |
gh pr edit ${{ needs.get-prs.outputs.pr_number }} --body "${{ steps.changelog.outputs.changelog }}"
create-release:
permissions:
contents: write
issues: write
pull-requests: write
needs: get-prs
runs-on: ubuntu-latest
if: ${{ needs.get-prs.outputs.pr_number == '' }}
# 日付ベースでリリースを作成
name: "Create Release"
steps:
- uses: actions/checkout@v4
- name: git config
run: |
git config --local user.email "[email protected]"
git config --local user.name "LuckyBeast"
# jqでpackage.jsonから現在のバージョンを取得
- name: Get current version
run: |
jq -r '.version' package.json
echo "current_version=$(jq -r '.version' package.json)" >> $GITHUB_OUTPUT
id: get_current_version
# バージョンをインクリメント
- name: Increment version
uses: actions/script@v7
env:
CURRENT_VERSION: ${{ steps.get_current_version.outputs.current_version }}
with:
script: |
const now = new Date();
const year = now.toLocaleDateString('en-US', { year: 'numeric', timeZone: 'Asia/Tokyo' });
const month = now.toLocaleDateString('en-US', { month: 'numeric', timeZone: 'Asia/Tokyo' });
const [major, minor, _patch] = process.env.CURRENT_VERSION.split('.');
const patch = Number(_patch.split('-')[0]);
if (Number.isNaN(patch)) {
console.error('Invalid patch version', year, month, process.env.CURRENT_VERSION, major, minor, _patch);
throw new Error('Invalid patch version');
}
if (year !== major || month !== minor) {
return `${year}.${month}.0`;
} else {
return `${major}.${minor}.${patch + 1}`;
}
result-encoding: string
id: next_target_version
- name: beta 0
run: echo "result=${{ steps.next_target_version.outputs.result }}-beta.0" >> $GITHUB_OUTPUT
id: next_release_version
# バージョンをpackage.jsonに書き込み
- name: Write version
run: |
jq '.version = "${{ steps.next_release_version.outputs.result }}"' package.json > package.json.tmp && mv package.json.tmp package.json
jq '.version = "${{ steps.next_release_version.outputs.result }}"' packages/misskey-js/package.json > packages/misskey-js/package.json.tmp && mv packages/misskey-js/package.json.tmp packages/misskey-js/package.json
# CHANGELOG.mdのUnreleasedの内容を取得
- name: Get changelog
run: |
{
echo 'changelog<<EOF'
sed -n '/## 202x.x.x (Unreleased)/,/^## /p' CHANGELOG.md | sed -e 1d -e '$d'
echo EOF
} >> $GITHUB_OUTPUT
id: changelog
# CHANGELOG.mdのバージョンの書き換え
- name: Modify CHANGELOG.md
run: |
sed -i 's/## 202x.x.x (Unreleased)/## ${{ steps.next_target_version.outputs.result }}/' CHANGELOG.md
# release/ブランチとタグを作成
- name: Commit version
run: |
git commit -am "Bump version to ${{ steps.next_release_version.outputs.result }}"
git push origin HEAD:release/${{ steps.next_target_version.outputs.result }}
git tag "${{ steps.next_release_version.outputs.result }}"
git push origin "${{ steps.next_release_version.outputs.result }}"
# リリースを作成
- name: Create release
run: |
gh release create "${{ steps.next_release_version.outputs.result }}" --prerelease --title "${{ steps.next_release_version.outputs.result }}" --notes "${{ steps.changelog.outputs.changelog }}"
# PRを作成
- name: Create PR
run: |
gh pr create --draft --title "Release: ${{ steps.next_target_version.outputs.result }}" --body "${{ steps.changelog.outputs.changelog }}" --head release/${{ steps.next_target_version.outputs.result }} --base ${{ github.ref_name }}