Skip to content

Commit 81f3822

Browse files
committed
fix(github): do not skip scheduled labeler runs
1 parent fa38f73 commit 81f3822

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

‎.github/workflows/labeler.yaml‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,46 @@ on:
88
- cron: '0 * * * *'
99

1010
jobs:
11-
labeler:
11+
# this job runs when the workflow was triggered by the 'pull_request' event
12+
pr-labeler:
1213
permissions:
1314
contents: read
1415
pull-requests: write
1516
issues: write
1617
# don't run on PRs from forks (token has no write permissions)
17-
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
18+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
1819
name: "Labeler"
1920
runs-on: ubuntu-latest
2021
steps:
2122
- name: Labeler action
2223
uses: actions/labeler@v7
2324
with:
2425
sync-labels: false
26+
27+
# This job runs when the workflow was triggered by the 'workflow_dispatch' or the 'schedule' event.
28+
# This is neccessary because for PRs from forks the default short-lived GitHub token has no write permissions
29+
# and can not add labels to the PR therefore. This means we have to label all PRs from forks using the 'schedule' event.
30+
scheduled-labeler:
31+
permissions:
32+
contents: read
33+
pull-requests: write
34+
issues: write
35+
# don't run on PRs from forks (token has no write permissions)
36+
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
37+
name: "Label all open PRs"
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Fetch open PR numbers
41+
id: fetch-prs
42+
run: |
43+
numbers=$(gh pr list --repo ${{ github.repository }} --state open --limit 500 --json number --jq 'map(.number)')
44+
echo numbers=$numbers >> $GITHUB_OUTPUT
45+
env:
46+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Labeler action
49+
if: ${{ steps.fetch-prs.outputs.numbers != '' }}
50+
uses: actions/labeler@v7
51+
with:
52+
sync-labels: false
53+
pr-number: ${{ fromJSON(steps.fetch-prs.outputs.numbers) }}

0 commit comments

Comments
 (0)