Skip to content

Commit 3a95990

Browse files
build: move hermetic_library_generation filtering logic into the steps rather than on.pull_request (#3410)
Co-authored-by: cloud-java-bot <[email protected]>
1 parent f5d8337 commit 3a95990

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

.github/workflows/hermetic_library_generation.yaml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
name: Hermetic library generation upon generation config change through pull requests
1717
on:
1818
pull_request:
19-
paths:
20-
- 'generation_config.yaml'
21-
- '.readme-partials.yaml'
22-
- 'owlbot.py'
23-
- 'versions.txt'
24-
- '.github/.OwlBot-hermetic.yaml'
2519

2620
env:
2721
REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }}
@@ -43,6 +37,46 @@ jobs:
4337
with:
4438
fetch-depth: 0
4539
token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
40+
- name: is applicable
41+
env:
42+
# set our branch names to be the names in the "origin" remote since we aren't actually checking these branches out
43+
base_ref: origin/${{ github.base_ref }}
44+
head_ref: origin/${{ github.head_ref }}
45+
run: |
46+
#!/bin/bash -x
47+
48+
# verify we have refs so error messages are clearer
49+
git rev-parse --verify "$base_ref"
50+
git rev-parse --verify "$head_ref"
51+
52+
# list all paths that are changed between before and after
53+
changed_paths=$(git diff --name-only "$base_ref" "$head_ref")
54+
55+
# define our array of paths that are included
56+
include_list=()
57+
58+
# push our include regex values onto the array
59+
include_list+=("^.github/workflows/hermetic_library_generation.yaml$")
60+
include_list+=("^generation_config.yaml$")
61+
include_list+=("^.readme-partials.yaml$")
62+
include_list+=("^owlbot.py$")
63+
include_list+=("^versions.txt$")
64+
include_list+=("^.github/.OwlBot-hermetic.yaml$")
65+
66+
# join all the paths into a single regex
67+
pattern="$(IFS=$'|' ; echo "${include_list[*]}")"
68+
69+
# check if we have any paths that match our include list
70+
match=0
71+
echo -e "${changed_paths}" | grep -E "${pattern}" 2>&1 || match=1
72+
73+
if [[ $match == 0 ]]; then
74+
echo "SHOULD_RUN=true" >> $GITHUB_ENV
75+
else
76+
echo "This PR does not match the include list"
77+
echo "SHOULD_RUN=false" >> $GITHUB_ENV
78+
fi
79+
4680
- uses: googleapis/sdk-platform-java/.github/[email protected]
4781
if: env.SHOULD_RUN == 'true'
4882
with:

0 commit comments

Comments
 (0)