-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaction.yml
More file actions
130 lines (128 loc) · 6.77 KB
/
action.yml
File metadata and controls
130 lines (128 loc) · 6.77 KB
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
name: "diff-pr-management"
author: "dev-hato Development Team"
description: "PRのブランチに対して、フォーマッタを実行した結果をPRにするGitHub Actionsです。"
inputs:
github-token: # id of input
description: "GitHubのトークン。"
required: true
branch-name-prefix:
description: "branch名の接頭語。"
required: false
default: fix
pr-title-prefix:
description: "PRのタイトルの接頭語。"
required: false
default: fix
pr-description-prefix:
description: "本文の接頭語。"
required: false
default: ""
pr-labels:
description: "PRに付与するラベル。カンマ区切りで指定する。"
required: false
default: ""
exit-failure:
description: "実行完了時にCIを失敗させるかどうか。"
required: false
default: "true"
working-directory:
description: "実行対象のディレクトリ"
required: false
default: ""
no-verify:
description: "`git commit`, `git push` 時のフックを無効化する"
required: false
default: "false"
runs:
using: "composite"
steps:
# 差分があったときに検知する
- name: Detect diff
id: diff
shell: bash
if: github.event_name != 'pull_request' || github.event.action != 'closed'
working-directory: ${{inputs.working-directory}}
run: ${{ github.action_path }}/src/detect_diff.sh
- name: Set env
id: set-env
shell: bash
env:
HEAD_REF: ${{github.event.pull_request.head.ref || github.ref_name}}
PR_DESCRIPTION_PREFIX_VALUE: ${{inputs.pr-description-prefix}}
PR_NUMBER: ${{github.event.pull_request.number}}
PR_TITLE_PREFIX: ${{inputs.pr-title-prefix}}
PR_LABELS: ${{inputs.pr-labels}}
BRANCH_NAME_PREFIX: ${{inputs.branch-name-prefix}}
run: | # zizmor: ignore[github-env]
echo "HEAD_REF=${HEAD_REF}" >>"${GITHUB_ENV}"
delimiter="$(openssl rand -hex 8)"
echo "PR_DESCRIPTION_PREFIX<<${delimiter}" >> "$GITHUB_ENV"
echo "${PR_DESCRIPTION_PREFIX_VALUE}" >> "$GITHUB_ENV"
echo "${delimiter}" >> "$GITHUB_ENV"
echo "PR_NUMBER=${PR_NUMBER}" >> "$GITHUB_ENV"
echo "PR_TITLE_PREFIX=${PR_TITLE_PREFIX}" >> "$GITHUB_ENV"
echo "PR_LABELS=${PR_LABELS}" >> "$GITHUB_ENV"
echo "BRANCH_NAME_PREFIX=${BRANCH_NAME_PREFIX}" >> "$GITHUB_ENV"
# 差分があったときは、コミットを作りpushする
- name: Push
env:
TOKEN: ${{inputs.github-token}}
NO_VERIFY: ${{inputs.no-verify}}
if: steps.diff.outputs.result != '' && ((github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'repository_dispatch')
working-directory: ${{inputs.working-directory}}
run: ${{ github.action_path }}/src/push.sh
shell: bash
- name: Get a number of PullRequests
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
if: steps.diff.outputs.result != '' && ((github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'repository_dispatch')
id: get_number_of_pull_requests
with:
github-token: ${{inputs.github-token}}
script: |
const {script} = require('${{ github.action_path }}/dist/get_number_of_pull_requests.js')
return await script(github, context)
# pushしたブランチで修正PRを作る
- name: Create PullRequest
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
if: steps.diff.outputs.result != '' && steps.get_number_of_pull_requests.outputs.result == 0 && ((github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'repository_dispatch')
id: create_pull_request
with:
github-token: ${{inputs.github-token}}
script: |
const {script} = require('${{ github.action_path }}/dist/create_pull_request.js')
return await script(github, context)
# 元のPRを出したユーザーを修正PRにアサインする
- name: Assign a user
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
if: steps.diff.outputs.result != '' && steps.get_number_of_pull_requests.outputs.result == 0 && github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.user.login != 'dependabot[bot]' && github.event.pull_request.user.login != 'renovate[bot]' && github.event.pull_request.user.login != 'Copilot'
env:
PR_NUMBER: ${{steps.create_pull_request.outputs.result}}
with:
github-token: ${{inputs.github-token}}
script: |
const {script} = require('${{ github.action_path }}/dist/assign_a_user.js')
await script(github, context)
# 修正PRのタイトルやDescription、ラベルを更新する
- name: Update PullRequest
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
if: steps.diff.outputs.result != '' && ((github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'repository_dispatch')
id: update_pull_request
with:
github-token: ${{inputs.github-token}}
script: |
const {script} = require('${{ github.action_path }}/dist/update_pull_request.js')
return await script(github, context)
# 既に修正PRがある状態で、手動でformatを修正した場合、修正PRを閉じる
- name: Close PullRequest
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
if: (github.event_name == 'pull_request' && (github.event.action == 'closed' || steps.diff.outputs.result == '')) || ((github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'repository_dispatch') && steps.diff.outputs.result == '')
with:
github-token: ${{inputs.github-token}}
script: |
const {script} = require('${{ github.action_path }}/dist/close_pull_request.js')
await script(github, context)
# exit-failureがtrueで差分がある場合は異常終了する
- name: Exit
if: (github.event_name != 'pull_request' || github.event.action != 'closed') && steps.diff.outputs.result != '' && inputs.exit-failure == 'true'
run: exit 1
shell: bash