Skip to content

Commit 2e360ef

Browse files
chore: follow up fix to verify_library_generation (#2721)
#2716 didn't quite fix what it should have. Follow up to fix the error: ``` Previous HEAD position was e54601f Merge 30c7c5b into 5d4567f Switched to a new branch 'main' branch 'main' set up to track 'origin/main'. + git fetch --no-tags --prune origin +main:refs/remotes/origin/main From https://github.com/googleapis/sdk-platform-java - [deleted] (none) -> origin/main + git checkout renovate/markupsafe-2.x error: pathspec 'renovate/markupsafe-2.x' did not match any file(s) known to git ``` --------- Co-authored-by: Joe Wang <[email protected]>
1 parent acfddd7 commit 2e360ef

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

.github/workflows/verify_library_generation.yaml

+14-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ jobs:
1616
shell: bash
1717
run: |
1818
set -ex
19-
# Checkout a detached head, and then fetch the base ref to populate the detached head.
20-
git checkout "${base_ref}"
21-
git fetch --no-tags --prune origin +${base_ref}:refs/remotes/origin/${base_ref}
22-
# Checkout a detached head, and then fetch the head ref to populate the detached head.
23-
git checkout "${head_ref}"
24-
git fetch --no-tags --prune origin +${head_ref}:refs/remotes/origin/${head_ref}
25-
changed_directories="$(git diff --name-only ${base_ref} ${head_ref})"
19+
# PRs that come from a fork need to be handled differently
20+
if [[ ${head_repo_name} == ${base_repo} ]]; then
21+
git checkout ${base_ref}
22+
git checkout ${head_ref}
23+
changed_directories="$(git diff --name-only ${base_ref} ${head_ref})"
24+
else
25+
git remote add fork ${head_repo_url}
26+
git fetch fork # create a mapping of the fork
27+
git checkout -b "${head_ref}" fork/${head_ref}
28+
changed_directories="$(git diff --name-only "fork/${head_ref}" "origin/${base_ref}")"
29+
fi
2630
if [[ ${changed_directories} =~ "library_generation/" ]]; then
2731
echo "should_run=true" >> $GITHUB_OUTPUT
2832
else
@@ -31,6 +35,9 @@ jobs:
3135
env:
3236
base_ref: ${{ github.event.pull_request.base.ref }}
3337
head_ref: ${{ github.event.pull_request.head.ref }}
38+
head_repo_url: ${{ github.event.pull_request.head.repo.html_url }}
39+
head_repo_name: ${{ github.event.pull_request.head.repo.full_name }}
40+
base_repo: ${{ github.repository }}
3441
library-generation-integration-tests:
3542
runs-on: ubuntu-22.04
3643
needs: should-run-library-generation-tests

0 commit comments

Comments
 (0)