Skip to content

Commit 9289154

Browse files
リリースCI追加 (#15)
* リリースCI追加 * リリースがない場合の処理追加 * 処理修正 * オブジェクトの判定処理修正 * 最新のリリースが見つからなかった場合の処理修正 * 変更処理修正 * 変更処理修正 * 権限追加 * permissionの設定削除 * バージョン情報を別ファイルに分離する * permission復活 * 鳩は唐揚げ!(自動で直してあげたよ!) (#17) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * メジャーアップデート * Revert "メジャーアップデート" This reverts commit df95357. * メジャー・マイナーバージョンのみコードで管理する * 余分な空白削除 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 094d24c commit 9289154

3 files changed

Lines changed: 129 additions & 0 deletions

File tree

.github/workflows/close-pr.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
name: close-pr
3+
4+
on:
5+
pull_request:
6+
types:
7+
- closed
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
# PR close時にCIが出したPRをcloseする
15+
close-pr:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- run: |
20+
REPO_NAME="${{ github.event.pull_request.head.repo.full_name }}"
21+
echo "REPO_NAME=${REPO_NAME}" >> "${GITHUB_ENV}"
22+
- name: Close PullRequest
23+
uses: actions/github-script@v6.1.0
24+
env:
25+
HEAD_REF: ${{github.event.pull_request.head.ref}}
26+
if: env.REPO_NAME == github.repository
27+
with:
28+
github-token: ${{secrets.GITHUB_TOKEN}}
29+
script: |
30+
const HEAD_REF = process.env["HEAD_REF"]
31+
const common_params = {
32+
owner: context.repo.owner,
33+
repo: context.repo.repo
34+
}
35+
36+
for (const head_name of ["increment-release-version" + HEAD_REF,
37+
"fix-version-pre-commit-config" + HEAD_REF,
38+
"fix-package" + HEAD_REF]) {
39+
let head = "${{github.event.pull_request.head.repo.owner.login}}:"
40+
head += head_name
41+
const pulls_list_params = {
42+
head,
43+
base: HEAD_REF,
44+
state: "open",
45+
...common_params
46+
}
47+
console.log("call pulls.list:", pulls_list_params)
48+
const pulls = await github.paginate(github.rest.pulls.list,
49+
pulls_list_params)
50+
51+
for (const pull of pulls) {
52+
const pulls_update_params = {
53+
pull_number: pull.number,
54+
state: "closed",
55+
...common_params
56+
}
57+
console.log("call pulls.update:", pulls_update_params)
58+
await github.rest.pulls.update(pulls_update_params)
59+
const git_deleteRef_params = {
60+
ref: "heads/" + head_name,
61+
...common_params
62+
}
63+
console.log("call git.deleteRef:", git_deleteRef_params)
64+
await github.rest.git.deleteRef(git_deleteRef_params)
65+
}
66+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
name: create-release
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
create-release:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3.0.2
14+
- name: Get latest release version
15+
id: get_latest_release_version
16+
uses: actions/github-script@v6.1.0
17+
with:
18+
github-token: ${{secrets.GITHUB_TOKEN}}
19+
result-encoding: string
20+
script: |
21+
try {
22+
return (await github.rest.repos.getLatestRelease({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo
25+
})).data.tag_name;
26+
} catch (e) {
27+
if (e.status === 404) {
28+
return 'v0.0.0';
29+
}
30+
31+
throw e;
32+
}
33+
- run: echo "MAJOR_VERSION=$(cat .version)" >> "${GITHUB_ENV}"
34+
- name: Increment version
35+
id: increment_version
36+
uses: actions/github-script@v6.1.0
37+
with:
38+
github-token: ${{secrets.GITHUB_TOKEN}}
39+
result-encoding: string
40+
script: |
41+
const majorVersion = process.env['MAJOR_VERSION'];
42+
let version = [];
43+
44+
if ('${{ steps.get_latest_release_version.outputs.result }}'.startsWith(majorVersion)) {
45+
const tagNames = '${{ steps.get_latest_release_version.outputs.result }}'.split('.');
46+
version = [tagNames[0], tagNames[1], Number(tagNames[2]) + 1];
47+
} else {
48+
version = [majorVersion, 0];
49+
}
50+
51+
return version.join('.');
52+
- name: Create release
53+
uses: actions/github-script@v6.1.0
54+
with:
55+
github-token: ${{secrets.GITHUB_TOKEN}}
56+
script: |
57+
await github.rest.repos.createRelease({
58+
owner: context.repo.owner,
59+
repo: context.repo.repo,
60+
tag_name: '${{ steps.increment_version.outputs.result }}',
61+
generate_release_notes: true
62+
});

.version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.0

0 commit comments

Comments
 (0)