|
| 1 | +# Copyright 2021 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +DATABASE_PATHS=("FirebaseDatabase.*" \ |
| 16 | + ".github/workflows/database\\.yml" \ |
| 17 | + "Example/Database/" \ |
| 18 | + "Interop/Auth/Public/\.\*.h") |
| 19 | +FUNCTIONS_PATHS=("Functions.*" \ |
| 20 | + ".github/workflows/functions\\.yml" \ |
| 21 | + "Interop/Auth/Public/\.\*.h" \ |
| 22 | + "FirebaseMessaging/Sources/Interop/\.\*.h") |
| 23 | + |
| 24 | +# Set default flag variables which will determine if an sdk workflow will be triggererd. |
| 25 | +echo "::set-output name=database_run_job::false" |
| 26 | +echo "::set-output name=functions_run_job::false" |
| 27 | + |
| 28 | +# Get most rescent ancestor commit. |
| 29 | +common_commit=$(git merge-base remotes/origin/${pr_branch} remotes/origin/master) |
| 30 | +echo "The common commit is ${common_commit}." |
| 31 | + |
| 32 | +# List changed file from the base commit. This is generated by comparing the |
| 33 | +# head of the branch and the common commit from the master branch. |
| 34 | +echo "=============== list changed files ===============" |
| 35 | +cat < <(git diff --name-only $common_commit remotes/origin/${pr_branch}) |
| 36 | + |
| 37 | +echo "============= paths of changed files =============" |
| 38 | +git diff --name-only $common_commit remotes/origin/${pr_branch} > updated_files.txt |
| 39 | + |
| 40 | +# Loop over updated files if their path match patterns then flags to trigger |
| 41 | +# SDK pod test workflow will be set to true. |
| 42 | +while IFS= read -r file |
| 43 | +do |
| 44 | + for path in "${DATABASE_PATHS[@]}" |
| 45 | + do |
| 46 | + if [[ "${file}" =~ $path ]]; then |
| 47 | + echo "This file is updated under the path, ${path}" |
| 48 | + echo "::set-output name=database_run_job::true" |
| 49 | + break |
| 50 | + fi |
| 51 | + done |
| 52 | + for path in "${FUNCTIONS_PATHS[@]}" |
| 53 | + do |
| 54 | + if [[ "${file}" =~ $path ]]; then |
| 55 | + echo "This file is updated under the path, ${path}" |
| 56 | + echo "::set-output name=functions_run_job::true" |
| 57 | + break |
| 58 | + fi |
| 59 | + done |
| 60 | +done < updated_files.txt |
0 commit comments