Skip to content

Commit

Permalink
feat: add prevent-no-label-execution workflow (#19)
Browse files Browse the repository at this point in the history
* 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
kenji-miyake authored and Kenji Miyake committed Dec 14, 2021
1 parent e10d480 commit 196d29d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/prevent-no-label-execution.yaml
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
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
```
### [prevent-no-label-execution](.github/workflows/prevent-no-label-execution.yaml)
This workflow checks if the PR has a specific label.
It is useful for preventing `pull_request_target` event and self-hosted runners from being executed without the label.

#### Usage

```yaml
jobs:
prevent-no-label-execution:
uses: autowarefoundation/autoware-github-actions/prevent-no-label-execution.yaml@tier4/proposal
with:
label: ARM64
build-and-test-arm:
needs: check-run-condition
if: ${{ needs.check-run-condition.outputs.run == 'true' }}
runs-on: [self-hosted, linux, ARM64]
# ...
```

## Supported composite actions

Please see the `README.md` in each directory.
Expand Down

0 comments on commit 196d29d

Please sign in to comment.