-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add prevent-no-label-execution workflow (#19)
* feat: add prevent-no-label-execution action Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * use reusable workflow Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * fix bug Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
- Loading branch information
1 parent
e10d480
commit 196d29d
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: prevent-no-label-execution | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
label: | ||
required: true | ||
type: string | ||
outputs: | ||
run: | ||
value: ${{ jobs.prevent-no-label-execution.outputs.run }} | ||
|
||
jobs: | ||
prevent-no-label-execution: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
run: ${{ steps.prevent-no-label-execution.outputs.run }} | ||
steps: | ||
- name: Prevent no label execution | ||
id: prevent-no-label-execution | ||
run: | | ||
function check() { | ||
if [ "${{ github.event_name }}" != "pull_request" ] && [ "${{ github.event_name }}" != "pull_request_target" ]; then | ||
echo "true" | ||
return | ||
fi | ||
# Labeled now | ||
if [ "${{ github.event.label.name }}" != "" ]; then | ||
if [ "${{ github.event.label.name == inputs.label }}" = "true" ]; then | ||
echo "true" | ||
return | ||
fi | ||
echo "Skipping execution since a different label '${{ github.event.label.name }}' is added." | ||
return | ||
fi | ||
# Labeled before and synchronized | ||
if [ "${{ contains(github.event.pull_request.labels.*.name, inputs.label) }}" = "true" ]; then | ||
echo "true" | ||
return | ||
fi | ||
echo "Please add the label '${{ inputs.label }}' to run this workflow." | ||
return | ||
} | ||
echo ::set-output name=run::"$(check)" | ||
shell: bash | ||
|
||
- name: Show result | ||
run: | | ||
echo "run: ${{ steps.prevent-no-label-execution.outputs.run }}" | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters