Skip to content

Commit 64a1887

Browse files
workflow_dispatchで動作するようにする (#226)
* workflow_dispatchで動作するようにする * test commit * 余分な変更を戻す * ベースブランチを決め打ちできるようにする * インデント修正 * README修正 (#230) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent ac52e1a commit 64a1887

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
| branch-name-prefix | branch名の接頭語。 | |
4646
| pr-title-prefix | PRのタイトルの接頭語。 | |
4747
| pr-description-prefix | 本文の接頭語。 | |
48+
| base-branch | ベースブランチ。 `pull_request` 以外のトリガーの場合は決め打ちで入力。 | |
4849

4950
## 開発
5051

action.yml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ inputs:
2020
description: '本文の接頭語。'
2121
required: true
2222
default: ""
23+
base-branch:
24+
description: 'ベースブランチ。 `pull_request` 以外のトリガーの場合は決め打ちで入力。'
25+
required: false
26+
default: ""
2327
runs:
2428
using: "composite"
2529
steps:
@@ -39,7 +43,7 @@ runs:
3943
- name: Push
4044
env:
4145
HEAD_REF: ${{github.event.pull_request.head.ref}}
42-
if: inputs.repo-name == github.repository && steps.diff.outputs.result != '' && ((github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'schedule')
46+
if: inputs.repo-name == github.repository && steps.diff.outputs.result != '' && ((github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
4347
run: |
4448
git config user.name "github-actions[bot]"
4549
EMAIL="41898282+github-actions[bot]@users.noreply.github.com"
@@ -52,13 +56,15 @@ runs:
5256
5357
if [ "${HEAD_REF}" != "" ]; then
5458
GITHUB_HEAD+="-${HEAD_REF}"
59+
elif [ "${{inputs.base-branch}}" != "" ]; then
60+
GITHUB_HEAD+="-${{inputs.base-branch}}"
5561
fi
5662
5763
git push -f "${REPO_URL}" "${GITHUB_HEAD}"
5864
shell: bash
5965
- name: Set org name
6066
uses: actions/[email protected]
61-
if: inputs.repo-name == github.repository && (github.event_name == 'pull_request' || github.event_name == 'schedule')
67+
if: inputs.repo-name == github.repository && (github.event_name == 'pull_request' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
6268
id: set_org_name
6369
with:
6470
github-token: ${{inputs.github-token}}
@@ -68,12 +74,17 @@ runs:
6874
uses: actions/[email protected]
6975
env:
7076
HEAD_REF: ${{github.event.pull_request.head.ref}}
71-
if: inputs.repo-name == github.repository && steps.diff.outputs.result != '' && ((github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'schedule')
77+
if: inputs.repo-name == github.repository && steps.diff.outputs.result != '' && ((github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
7278
id: get_pull_requests
7379
with:
7480
github-token: ${{inputs.github-token}}
7581
script: |
76-
const HEAD_REF = process.env["HEAD_REF"]
82+
let HEAD_REF = process.env["HEAD_REF"]
83+
84+
if (HEAD_REF === "" && "${{inputs.base-branch}}" !== "") {
85+
HEAD_REF = "${{inputs.base-branch}}"
86+
}
87+
7788
let head = "${{steps.set_org_name.outputs.result}}:${{inputs.branch-name-prefix}}"
7889
7990
if (HEAD_REF != "") {
@@ -96,12 +107,17 @@ runs:
96107
uses: actions/[email protected]
97108
env:
98109
HEAD_REF: ${{github.event.pull_request.head.ref}}
99-
if: inputs.repo-name == github.repository && steps.diff.outputs.result != '' && steps.get_pull_requests.outputs.result == 0 && ((github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'schedule')
110+
if: inputs.repo-name == github.repository && steps.diff.outputs.result != '' && steps.get_pull_requests.outputs.result == 0 && ((github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
100111
id: create_pull_request
101112
with:
102113
github-token: ${{inputs.github-token}}
103114
script: |
104-
const HEAD_REF = process.env["HEAD_REF"]
115+
let HEAD_REF = process.env["HEAD_REF"]
116+
117+
if (HEAD_REF === "" && "${{inputs.base-branch}}" !== "") {
118+
HEAD_REF = "${{inputs.base-branch}}"
119+
}
120+
105121
let title = "${{inputs.pr-title-prefix}}"
106122
let body = "${{inputs.pr-description-prefix}}"
107123
@@ -150,11 +166,16 @@ runs:
150166
uses: actions/[email protected]
151167
env:
152168
HEAD_REF: ${{github.event.pull_request.head.ref}}
153-
if: inputs.repo-name == github.repository && ((github.event_name == 'pull_request' && (github.event.action == 'closed' || steps.diff.outputs.result == '')) || (github.event_name == 'schedule' && steps.diff.outputs.result == ''))
169+
if: inputs.repo-name == github.repository && ((github.event_name == 'pull_request' && (github.event.action == 'closed' || steps.diff.outputs.result == '')) || ((github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && steps.diff.outputs.result == ''))
154170
with:
155171
github-token: ${{inputs.github-token}}
156172
script: |
157-
const HEAD_REF = process.env["HEAD_REF"]
173+
let HEAD_REF = process.env["HEAD_REF"]
174+
175+
if (HEAD_REF === "" && "${{inputs.base-branch}}" !== "") {
176+
HEAD_REF = "${{inputs.base-branch}}"
177+
}
178+
158179
let head_name = "${{inputs.branch-name-prefix}}"
159180
160181
if (HEAD_REF != "") {

0 commit comments

Comments
 (0)