Skip to content

Commit fb8b7a3

Browse files
[cherry-pick] Allow cherry-pick bot PRs in engineering system changes check (#311505)
Allow cherry-pick bot PRs in engineering system changes check (#311475) * Allow cherry-pick bot PRs in engineering system changes check Add an exception for PRs created by vs-code-engineering[bot] whose title starts with [cherry-pick] and that carry the cherry-pick-artifact label. * Fetch cherry-pick-artifact label via API at runtime The label is applied ~2s after PR creation, so the webhook payload may not include it. Fetch current labels from the API instead, gated behind cheap event-payload checks to avoid extra API calls on unrelated PRs. * Add label retry loop and consolidate guard expressions Retry the cherry-pick-artifact label check up to 3 times (2s apart) to handle the ~2s delay between PR creation and label application. Consolidate the repeated exception guards into a single 'allowed' step with a 'blocked' output, simplifying downstream conditions. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ce749f9 commit fb8b7a3

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

.github/workflows/no-engineering-system-changes.yml

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,30 +88,62 @@ jobs:
8888
fi
8989
env:
9090
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91+
- name: Allow cherry-pick bot PRs
92+
id: cherry_pick_exception
93+
if: ${{ steps.engineering_systems_check.outputs.engineering_systems_modified == 'true' && steps.bot_field_exception.outputs.allowed != 'true' && github.event.pull_request.user.login == 'vs-code-engineering[bot]' && startsWith(github.event.pull_request.title, '[cherry-pick]') }}
94+
run: |
95+
# The label is applied ~2s after PR creation, so the webhook payload
96+
# may not include it yet. Fetch current labels from the API with retries.
97+
for attempt in 1 2 3; do
98+
if gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels --jq '.[].name' | grep -qx 'cherry-pick-artifact'; then
99+
echo "Cherry-pick PR by vs-code-engineering bot with cherry-pick-artifact label — allowing"
100+
echo "allowed=true" >> $GITHUB_OUTPUT
101+
exit 0
102+
fi
103+
if [ "$attempt" -lt 3 ]; then
104+
echo "cherry-pick-artifact label not present yet (attempt $attempt/3); retrying in 2s"
105+
sleep 2
106+
fi
107+
done
108+
echo "Cherry-pick PR by bot but missing cherry-pick-artifact label after retries — not allowed"
109+
echo "allowed=false" >> $GITHUB_OUTPUT
110+
env:
111+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
- name: Determine if engineering system changes are allowed
113+
id: allowed
114+
if: ${{ steps.engineering_systems_check.outputs.engineering_systems_modified == 'true' }}
115+
run: |
116+
if [[ "${{ steps.bot_field_exception.outputs.allowed }}" == "true" || "${{ steps.cherry_pick_exception.outputs.allowed }}" == "true" ]]; then
117+
echo "Engineering system changes are allowed by an exception"
118+
echo "blocked=false" >> $GITHUB_OUTPUT
119+
else
120+
echo "No exception applies — enforcing restrictions"
121+
echo "blocked=true" >> $GITHUB_OUTPUT
122+
fi
91123
- name: Prevent Copilot from modifying engineering systems
92-
if: ${{ steps.engineering_systems_check.outputs.engineering_systems_modified == 'true' && steps.bot_field_exception.outputs.allowed != 'true' && github.event.pull_request.user.login == 'Copilot' }}
124+
if: ${{ steps.allowed.outputs.blocked == 'true' && github.event.pull_request.user.login == 'Copilot' }}
93125
run: |
94126
echo "Copilot is not allowed to modify .github/workflows, build folder files, or package.json files."
95127
echo "If you need to update engineering systems, please do so manually or through authorized means."
96128
exit 1
97129
- uses: octokit/request-action@b91aabaa861c777dcdb14e2387e30eddf04619ae # v3.0.0
98130
id: get_permissions
99-
if: ${{ steps.engineering_systems_check.outputs.engineering_systems_modified == 'true' && steps.bot_field_exception.outputs.allowed != 'true' && github.event.pull_request.user.login != 'Copilot' }}
131+
if: ${{ steps.allowed.outputs.blocked == 'true' && github.event.pull_request.user.login != 'Copilot' }}
100132
with:
101133
route: GET /repos/microsoft/vscode/collaborators/${{ github.event.pull_request.user.login }}/permission
102134
env:
103135
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104136
- name: Set control output variable
105137
id: control
106-
if: ${{ steps.engineering_systems_check.outputs.engineering_systems_modified == 'true' && steps.bot_field_exception.outputs.allowed != 'true' && github.event.pull_request.user.login != 'Copilot' }}
138+
if: ${{ steps.allowed.outputs.blocked == 'true' && github.event.pull_request.user.login != 'Copilot' }}
107139
run: |
108140
echo "user: ${{ github.event.pull_request.user.login }}"
109141
echo "role: ${{ fromJson(steps.get_permissions.outputs.data).permission }}"
110142
echo "is dependabot: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}"
111143
echo "should_run: ${{ !contains(fromJson('["admin", "maintain", "write"]'), fromJson(steps.get_permissions.outputs.data).permission) }}"
112144
echo "should_run=${{ !contains(fromJson('["admin", "maintain", "write"]'), fromJson(steps.get_permissions.outputs.data).permission) && github.event.pull_request.user.login != 'dependabot[bot]' }}" >> $GITHUB_OUTPUT
113145
- name: Check for engineering system changes
114-
if: ${{ steps.engineering_systems_check.outputs.engineering_systems_modified == 'true' && steps.bot_field_exception.outputs.allowed != 'true' && steps.control.outputs.should_run == 'true' }}
146+
if: ${{ steps.allowed.outputs.blocked == 'true' && steps.control.outputs.should_run == 'true' }}
115147
run: |
116148
echo "Changes to .github/workflows/, build/ folder files, or package.json files aren't allowed in PRs."
117149
exit 1

0 commit comments

Comments
 (0)