Skip to content

Commit 6f1217e

Browse files
committed
Sync labels in write mode on schedule trigger
In order to facilitate the testing and review of proposed changes to the repository label infrastructure, the "Sync Labels" template workflow does a dry run when triggered under conditions that indicate it would not be appropriate to make real changes to the repository's labels. The changes that would have resulted are printed to the log, but not actually made. One of the criteria used to determine "dry run" mode usage is whether the event occurred on the repository's default branch. A trigger on a development branch or for a pull request should not result in a change to the labels. It turns out that GitHub does not define a `github.event.repository.default_branch` context item when a workflow is triggered by a `schedule` event. This resulted in the workflow always running in "dry run" mode on a `schedule` trigger. Since `schedule` and `repository_dispatch` triggers are only permitted for the default branch, there is no need to check whether the event's ref matches the default branch and it is safe to always run in write mode on these events.
1 parent c17b52a commit 6f1217e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: .github/workflows/sync-labels.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ jobs:
9393
id: dry-run
9494
if: >
9595
github.event_name == 'pull_request' ||
96-
github.ref != format('refs/heads/{0}', github.event.repository.default_branch)
96+
(
97+
(
98+
github.event_name == 'push' ||
99+
github.event_name == 'workflow_dispatch'
100+
) &&
101+
github.ref != format('refs/heads/{0}', github.event.repository.default_branch)
102+
)
97103
run: |
98104
# Use of this flag in the github-label-sync command will cause it to only check the validity of the
99105
# configuration.

0 commit comments

Comments
 (0)