Skip to content

Commit

Permalink
ci: replace bash in workflow by subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
aeddi committed Nov 27, 2024
1 parent 00bc576 commit 353d362
Showing 1 changed file with 3 additions and 37 deletions.
40 changes: 3 additions & 37 deletions .github/workflows/bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,46 +42,12 @@ jobs:
pr-numbers: ${{ steps.pr-numbers.outputs.pr-numbers }}

steps:
- name: Parse event inputs
- name: Generate matrix from event
id: pr-numbers
working-directory: contribs/github-bot
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Triggered by a workflow dispatch event
if [ '${{ github.event_name }}' = 'workflow_dispatch' ]; then
# If the input is 'all', create a matrix with every open PRs
if [ '${{ inputs.pull-request-list }}' = 'all' ]; then
pr_list=`gh pr list --state 'open' --repo '${{ github.repository }}' --json 'number' --template '{{$first := true}}{{range .}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{"\""}}{{.number}}{{"\""}}{{end}}'`
[ -z "$pr_list" ] && echo 'Error: no opened PR found' >&2 && exit 1
echo "pr-numbers=[$pr_list]" >> "$GITHUB_OUTPUT"
# If the input is not 'all', test for each number in the comma separated
# list if the associated PR is opened, then add it to the matrix
else
pr_list_raw='${{ inputs.pull-request-list }}'
pr_list=''
IFS=','
for number in $pr_list; do
trimed=`echo "$number" | xargs`
pr_state=`gh pr view "$trimed" --repo '${{ github.repository }}' --json 'state' --template '{{.state}}' 2> /dev/null`
[ "$pr_state" != 'OPEN' ] && echo "Error: PR with number <$trimed> is not opened" >&2 && exit 1
done
echo "pr-numbers=[$pr_list]" >> "$GITHUB_OUTPUT"
fi
# Triggered by comment event, just add the associated PR number to the matrix
elif [ '${{ github.event_name }}' = 'issue_comment' ]; then
echo 'pr-numbers=["${{ github.event.issue.number }}"]' >> "$GITHUB_OUTPUT"
# Triggered by pull request target event, just add the associated PR number to the matrix
elif [ '${{ github.event_name }}' = 'pull_request_target' ]; then
echo 'pr-numbers=["${{ github.event.pull_request.number }}"]' >> "$GITHUB_OUTPUT"
# Should never happen
else
echo 'Error: unknown event ${{ github.event_name }}' >&2 && exit 1
fi
run: go run . matrix >> "$GITHUB_OUTPUT"

# This job processes each pull request in the matrix individually while ensuring
# that a same PR cannot be processed concurrently by mutliple runners
Expand Down

0 comments on commit 353d362

Please sign in to comment.