Skip to content

Commit 337c064

Browse files
committed
Better label handling
1 parent 8aac344 commit 337c064

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

.github/workflows/release.yaml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,48 @@ on:
66
- 'v*'
77
- 'cabal-install-*'
88
pull_request:
9-
types: [ labeled ]
9+
types: [opened, synchronize, reopened, labeled]
1010
branches:
1111
- master
1212
schedule:
1313
- cron: '0 0 * * *'
1414
workflow_dispatch:
1515

16+
permissions:
17+
pull-requests: read
18+
19+
env:
20+
BUILD_LABEL: "run release build"
21+
1622
jobs:
23+
check-pr-labels:
24+
name: check PR labels
25+
runs-on: ubuntu-latest
26+
outputs:
27+
run_release_workflow: ${{ steps.gen_output.outputs.run_release_workflow }}
28+
steps:
29+
- id: gen_output
30+
run: |
31+
if [ "${{ github.event.action }}" == 'labeled' ] ; then
32+
if [ ${{ github.event.label.name == '${{ env.BUILD_LABEL }}' }} ] ; then
33+
echo run_release_workflow="yes" >> "$GITHUB_OUTPUT"
34+
else
35+
echo run_release_workflow="no" >> "$GITHUB_OUTPUT"
36+
fi
37+
elif [ "${{ github.event_name }}" = 'pull_request' ] ; then
38+
run_it=$(if gh api --jq '.labels.[].name' /repos/${{ github.repository }}/pulls/${{ github.event.number }} | grep --quiet '^${{ env.BUILD_LABEL }}$' ; then printf "%s" "yes" ; else printf "%s" "no" ; fi)
39+
echo "${run_it}"
40+
echo run_release_workflow="${run_it}" >> "$GITHUB_OUTPUT"
41+
else
42+
echo run_release_workflow="yes" >> "$GITHUB_OUTPUT"
43+
fi
44+
shell: bash
45+
env:
46+
GH_TOKEN: ${{ github.token }}
47+
1748
release-workflow:
18-
if: ${{ github.event.label.name == 'run release build' }}
49+
needs: ["check-pr-labels"]
50+
if: ${{ needs.check-pr-labels.outputs.run_release_workflow == 'yes' }}
1951
uses: ./.github/workflows/reusable-release.yml
2052
with:
2153
branches: '["${{ github.ref }}"]'

0 commit comments

Comments
 (0)