Skip to content

Commit 9c7676b

Browse files
authored
[ci] Remove pull_request_target workflows (#13581)
Removes the remaining `pull_request_target` triggers in `.github/workflows/`: - Replaces `pull_request_label.yml` with `labeler-trigger.yml` (`pull_request`) and `labeler.yml` (`workflow_run`), matching flutter/flutter#195536. - Removes `remove_cicd.yml`, since `CICD` label management is now handled in Cocoon (matching flutter/flutter#189087). Part of flutter/flutter#193185 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 3d61a70 commit 9c7676b

4 files changed

Lines changed: 146 additions & 96 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2026 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
# Unprivileged half of the pull request labeler.
6+
#
7+
# This workflow runs on `pull_request` with a read-only token and no access to
8+
# secrets. It records the pull request number in a `labeler-metadata` artifact
9+
# so that the privileged `labeler.yml` workflow can apply labels via
10+
# `workflow_run`. The labels themselves are computed in `labeler.yml` from the
11+
# trusted `.github/labeler.yml` on the default branch.
12+
13+
name: Pull Request Labeler Trigger
14+
15+
on:
16+
pull_request:
17+
types: [opened, synchronize, reopened]
18+
19+
# Declare default permissions as read only.
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
record:
25+
name: Record PR for labeling
26+
runs-on: ubuntu-latest
27+
if: ${{ github.repository == 'flutter/packages' }}
28+
steps:
29+
- name: Record PR number
30+
env:
31+
PR_NUMBER: ${{ github.event.pull_request.number }}
32+
run: |
33+
mkdir -p labeler-metadata
34+
jq -n --arg pr "$PR_NUMBER" '{pr_number: $pr}' > labeler-metadata/metadata.json
35+
36+
- name: Upload labeler metadata
37+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
38+
with:
39+
name: labeler-metadata
40+
path: labeler-metadata/
41+
retention-days: 1
42+
if-no-files-found: error

‎.github/workflows/labeler.yml‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Copyright 2026 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
# Privileged half of the pull request labeler.
6+
#
7+
# Edit `.github/labeler.yml` to configure labels.
8+
#
9+
# Runs after `labeler-trigger.yml` completes. The artifact produced by that
10+
# workflow is UNTRUSTED (a pull request can modify the trigger workflow), so the
11+
# PR number is only used after binding it to the triggering run's head commit.
12+
# The label configuration is read from the default branch, not the PR.
13+
#
14+
# Pull requests from first-time contributors need a maintainer to approve their
15+
# `pull_request` runs. Until then, the trigger run is created already concluded
16+
# as `action_required`, without running anything or uploading an artifact. That
17+
# run fires the `requested` event (but not `completed`), so on `requested` with
18+
# `action_required` the PR is looked up from the run's head branch and SHA
19+
# instead. Otherwise those PRs would not be labeled until approved, and would
20+
# not show up in the triage queries where maintainers find runs to approve.
21+
22+
name: Pull Request Labeler
23+
24+
on:
25+
# Safe because this only consumes an artifact from the triggering run as
26+
# untrusted data (validated and bound to the PR's head SHA); no PR code is
27+
# checked out or executed.
28+
workflow_run: # zizmor: ignore[dangerous-triggers]
29+
workflows: [Pull Request Labeler Trigger]
30+
types: [requested, completed]
31+
32+
# Declare default permissions as read only.
33+
permissions:
34+
contents: read
35+
36+
jobs:
37+
triage:
38+
if: >-
39+
github.repository == 'flutter/packages' &&
40+
github.event.workflow_run.event == 'pull_request' &&
41+
github.event.workflow_run.path == '.github/workflows/labeler-trigger.yml' &&
42+
((github.event.action == 'completed' && github.event.workflow_run.conclusion == 'success') ||
43+
(github.event.action == 'requested' && github.event.workflow_run.conclusion == 'action_required'))
44+
permissions:
45+
actions: read
46+
contents: read
47+
pull-requests: write
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Download labeler metadata
51+
if: github.event.action == 'completed'
52+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
53+
with:
54+
name: labeler-metadata
55+
path: ${{ runner.temp }}/labeler-metadata
56+
run-id: ${{ github.event.workflow_run.id }}
57+
github-token: ${{ github.token }}
58+
59+
- name: Validate PR
60+
id: validate
61+
env:
62+
EVENT_ACTION: ${{ github.event.action }}
63+
GH_TOKEN: ${{ github.token }}
64+
REPO: ${{ github.repository }}
65+
RUN_HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
66+
RUN_HEAD_OWNER: ${{ github.event.workflow_run.head_repository.owner.login }}
67+
RUN_HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }}
68+
RUN_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
69+
run: |
70+
set -euo pipefail
71+
if [ "$EVENT_ACTION" = "requested" ]; then
72+
# Awaiting approval: no artifact, so find the open PR for the run's
73+
# head branch. This only uses data from GitHub's event payload.
74+
PR_NUMBER=$(gh api -X GET "repos/$REPO/pulls" \
75+
-f state=open -f head="$RUN_HEAD_OWNER:$RUN_HEAD_BRANCH" |
76+
jq -r --arg sha "$RUN_HEAD_SHA" '[.[] | select(.head.sha == $sha)] | .[0].number // empty')
77+
if [ -z "$PR_NUMBER" ]; then
78+
echo "::notice::No open PR found for $RUN_HEAD_OWNER:$RUN_HEAD_BRANCH at $RUN_HEAD_SHA; skipping."
79+
exit 0
80+
fi
81+
else
82+
PR_NUMBER=$(jq -r '.pr_number // empty' "$RUNNER_TEMP/labeler-metadata/metadata.json")
83+
fi
84+
if ! [[ "$PR_NUMBER" =~ ^[1-9][0-9]*$ ]]; then
85+
echo "::error::Invalid PR number."
86+
exit 1
87+
fi
88+
89+
# Bind the PR number to the pull request that actually triggered the run.
90+
gh api "repos/$REPO/pulls/$PR_NUMBER" > "$RUNNER_TEMP/pr.json"
91+
if [ "$(jq -r '.head.sha' "$RUNNER_TEMP/pr.json")" != "$RUN_HEAD_SHA" ] ||
92+
[ "$(jq -r '.head.repo.full_name // empty' "$RUNNER_TEMP/pr.json")" != "$RUN_HEAD_REPO" ]; then
93+
# Most likely a newer push; its own run will label the PR.
94+
echo "::notice::PR #$PR_NUMBER has changed since the trigger ran; skipping."
95+
exit 0
96+
fi
97+
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
98+
99+
# Source available at https://github.com/actions/labeler/blob/main/README.md
100+
- uses: actions/labeler@b8dd2d9be0f68b860e7dae5dae7d772984eacd6d # v6.2.0
101+
if: steps.validate.outputs.pr_number != ''
102+
with:
103+
pr-number: ${{ steps.validate.outputs.pr_number }}
104+
sync-labels: true

‎.github/workflows/pull_request_label.yml‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎.github/workflows/remove_cicd.yml‎

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)