@@ -59,11 +59,10 @@ jobs:
5959
6060 if [[ "${head_repo}" != "${REPOSITORY}" ]]; then
6161 echo "same_repo=false" >> "${GITHUB_OUTPUT}"
62- exit 0
62+ else
63+ echo "same_repo=true" >> "${GITHUB_OUTPUT}"
6364 fi
6465
65- echo "same_repo=true" >> "${GITHUB_OUTPUT}"
66-
6766 if [[ "${pr_head_sha}" != "${RUN_HEAD_SHA}" ]]; then
6867 echo "stale=true" >> "${GITHUB_OUTPUT}"
6968 exit 0
7574 shell : bash
7675 run : |
7776 echo "Skip stale bazel update for PR #${{ steps.pr.outputs.pr_number }}."
77+ - name : Download Fork Bazel Files Artifact
78+ if : steps.pr.outputs.same_repo != 'true' && steps.pr.outputs.stale != 'true'
79+ uses : actions/download-artifact@v4
80+ with :
81+ name : bazel-files
82+ path : bazel-artifact
83+ repository : ${{ github.repository }}
84+ run-id : ${{ github.event.workflow_run.id }}
85+ github-token : ${{ github.token }}
86+ - name : Report fork PR Bazel changes
87+ if : steps.pr.outputs.same_repo != 'true' && steps.pr.outputs.stale != 'true'
88+ shell : bash
89+ env :
90+ PR_NUMBER : ${{ steps.pr.outputs.pr_number }}
91+ REPOSITORY : ${{ github.repository }}
92+ RUN_ID : ${{ github.event.workflow_run.id }}
93+ run : |
94+ set -euo pipefail
95+
96+ patch_path="${PWD}/bazel-artifact/bazel.patch"
97+ if [[ ! -f "${patch_path}" ]]; then
98+ echo "Missing bazel.patch artifact for fork PR #${PR_NUMBER}." >&2
99+ exit 1
100+ fi
101+
102+ if [[ ! -s "${patch_path}" ]]; then
103+ echo "No generated Bazel changes for fork PR #${PR_NUMBER}."
104+ exit 0
105+ fi
106+
107+ {
108+ echo "Generated Bazel changes cannot be committed automatically for fork PR #${PR_NUMBER}."
109+ echo "Run: gh run download ${RUN_ID} --repo ${REPOSITORY} --name bazel-files --dir bazel-artifact && git apply bazel-artifact/bazel.patch"
110+ } | tee -a "${GITHUB_STEP_SUMMARY}"
111+
112+ exit 1
78113 - name : Checkout PR branch
79114 if : steps.pr.outputs.same_repo == 'true' && steps.pr.outputs.stale != 'true'
80115 uses : actions/checkout@v6
@@ -101,7 +136,7 @@ jobs:
101136 set -euo pipefail
102137
103138 patch_path="${PWD}/bazel-artifact/bazel.patch"
104- summary="$(git apply --summary "${patch_path}")"
139+ summary="$(git -C pr apply --summary "${patch_path}")"
105140
106141 while IFS= read -r line; do
107142 case "${line}" in
@@ -126,6 +161,12 @@ jobs:
126161 echo "Unexpected patch path: ${path}" >&2
127162 exit 1
128163 ;;
164+ build/BUILD.bazel|build/*/BUILD.bazel)
165+ ;;
166+ WORKSPACE|WORKSPACE.bazel|build|build/*)
167+ echo "Unsafe patch path: ${path}" >&2
168+ exit 1
169+ ;;
129170 DEPS.bzl|*.bazel|*.bzl)
130171 ;;
131172 *)
@@ -139,7 +180,7 @@ jobs:
139180 exit 1
140181 fi
141182 seen_paths["${path}"]=1
142- done < <(git apply --numstat -z "${patch_path}")
183+ done < <(git -C pr apply --numstat -z "${patch_path}")
143184
144185 git -C pr apply --check --index "${patch_path}"
145186 git -C pr apply --index "${patch_path}"
0 commit comments