forked from tamaina/sandbox-actions-release
-
Notifications
You must be signed in to change notification settings - Fork 1
125 lines (119 loc) · 4.47 KB
/
create-prerelease.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
name: "Release Manager/Create Pre-release"
on:
workflow_call:
inputs:
pr_number:
type: string
description: 'PR number'
required: true
user:
type: string
description: 'User name'
default: 'github-actions[bot]'
package_jsons_to_rewrite:
type: string
description: 'package.jsons to rewrite (json)'
default: 'package.json'
use_external_app_to_release:
type: boolean
default: false
indent:
type: string
description: '`tab` or number of spaces'
default: tab
secrets:
RELEASE_APP_ID:
description: 'App ID for app to create release'
RELEASE_APP_PRIVATE_KEY:
description: 'Private key for app to create release'
permissions:
contents: write
issues: write
pull-requests: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
create-prerelease:
name: "Create Pre-release"
runs-on: ubuntu-latest
if: ${{ inputs.pr_number != '' }}
# 開いているリリースのパッチバージョンを上げる
steps:
- uses: actions/checkout@v4
- name: Initialize
uses: joinmisskey/release-actions/.github/actions/checkout-pr@main
with:
pr_number: ${{ inputs.pr_number }}
user: ${{ inputs.user }}
id: get_pr
- name: Get target version
uses: joinmisskey/release-actions/.github/actions/get-target-version@main
id: v
# バージョンをインクリメント
- name: Increment version
uses: actions/script@v7
env:
CURRENT_VERSION: ${{ steps.v.outputs.current_version }}
pr_is_draft: ${{ steps.get_pr.outputs.pr_is_draft }}
with:
script: |
const [major, minor, _patch, _pre] = process.env.CURRENT_VERSION.split('.');
const pre = Number(_pre);
if (Number.isNaN(pre)) {
console.error('Invalid pre version', process.env.CURRENT_VERSION, major, minor, _patch);
throw new Error('Invalid pre version');
}
if (process.env.pr_is_draft == 'true') {
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: release_version
# バージョンをpackage.jsonに書き込み
- name: Write version
uses: joinmisskey/release-actions/.github/actions/rewrite-package-json@main
with:
version: ${{ steps.release_version.outputs.result }}
package_jsons: ${{ inputs.package_jsons_to_rewrite }}
indent: ${{ inputs.indent }}
# push、タグを作成
- name: Commit version
run: |
git commit -am "Bump version to $VERSION_NAME"
git push
git tag "$VERSION_NAME"
git push origin "$VERSION_NAME"
env:
VERSION_NAME: ${{ steps.release_version.outputs.result }}
TARGET_VERSION: ${{ steps.v.outputs.target_version }}
# CHANGELOG.mdの内容を取得
- name: Get changelog
uses: joinmisskey/release-actions/.github/actions/get-changelog@main
with:
version: ${{ steps.v.outputs.target_version }}
id: changelog
# リリースを作成
- uses: actions/create-github-app-token@v1
id: release-app-token
if: inputs.use_external_app_to_release
with:
app-id: ${{ secrets.RELEASE_APP_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
- name: Create release
env:
GITHUB_TOKEN: ${{ inputs.use_external_app_to_release && steps.release-app-token.outputs.token || secrets.GITHUB_TOKEN }}
VERSION_NAME: ${{ steps.release_version.outputs.result }}
CHANGELOG: ${{ steps.changelog.outputs.changelog }}
run: |
gh release create "$VERSION_NAME" --prerelease --title "$VERSION_NAME" --notes "$CHANGELOG"
# PRのnotesを更新
# (通常release-edit-with-pushで更新されているためここで更新されることはない)
#- name: Update PR
# run: |
# gh pr edit ${{ inputs.pr_number }} --body "${{ steps.changelog.outputs.changelog }}"