1# Copyright 2022 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# Github action job to test core java library features on 15# downstream client libraries before they are released. 16on: 17 push: 18 branches: 19 - main 20 pull_request: 21name: generation diff 22jobs: 23 root-pom: 24 # root pom.xml does not have diff from generated one 25 runs-on: ubuntu-latest 26 steps: 27 - uses: actions/checkout@v3 28 - name: Generate root pom.xml file 29 run: | 30 bash generation/generate_root_pom.sh 31 - name: Apply versions from versions.txt files 32 run: | 33 bash generation/apply_current_versions.sh 34 - name: Fail if there's any difference 35 run: git --no-pager diff --exit-code 36 37 gapic-bom: 38 # gapic-libraries-bom does not have diff from generated one 39 runs-on: ubuntu-latest 40 steps: 41 - uses: actions/checkout@v3 42 - name: Generate gapic-libraries-bom/pom.xml 43 run: | 44 bash generation/generate_gapic_bom.sh 45 - name: Apply versions from versions.txt files 46 run: | 47 bash generation/apply_current_versions.sh 48 - name: Fail if there's any difference (To fix, run generation/apply_current_versions.sh) 49 run: git --no-pager diff --exit-code 50 51 owlbot-py: 52 # applying templated owlbot.py config doesn't create a diff 53 runs-on: ubuntu-latest 54 steps: 55 - uses: actions/checkout@v3 56 - name: Generate owlbot.py files 57 run: | 58 bash generation/update_owlbot_postprocessor_config.sh 59 - name: Fail if there's any difference (To fix, run generation/update_owlbot_postprocessor_config.sh) 60 run: git --no-pager diff --exit-code 61 62 owlbot-yaml: 63 # Each module's .Owlbot.yaml config is configured according to set_owlbot_config.sh 64 runs-on: ubuntu-latest 65 steps: 66 - uses: actions/checkout@v3 67 - name: Check if .Owlbot.yaml files are correctly configured 68 run: | 69 bash generation/set_owlbot_config.sh 70 - name: Fail if there's any difference (To fix, run generation/set_owlbot_config.sh) 71 run: git --no-pager diff --exit-code 72 73 gitignore_correctness: 74 # Generated files should not match .gitignore 75 runs-on: ubuntu-latest 76 steps: 77 - uses: actions/checkout@v3 78 - name: checking any files matching gitignore 79 # By default, GitHub Actions's bash has '-e' option to fail immediately 80 # upon non-zero exit code. Not using it here to catch the exit code 1. 81 shell: /usr/bin/bash --noprofile --norc -o pipefail {0} 82 run: | 83 find . -type f -name '*.java' -not -path './.git/*' \ 84 |git check-ignore --no-index --verbose --stdin 85 # https://git-scm.com/docs/git-check-ignore returns 1 when there's no 86 # matching files with the gitignore file. 87 # "--no-index" is needed to check against tracked files. 88 if [ "$?" == 1 ]; then 89 echo "No matching files. Good." 90 exit 0 91 else 92 echo "There are gitignore matching files. Please adjust .gitignore." 93 exit 1 94 fi 95 96 consolidate-config: 97 # Parent handles config for child modules 98 runs-on: ubuntu-latest 99 steps: 100 - uses: actions/checkout@v3 101 - name: Apply consolidate_config.sh 102 run: | 103 bash generation/consolidate_config.sh 104 - name: Fail if there's any difference (To fix, run generation/consolidate_config.sh) 105 run: git --no-pager diff --exit-code 106 107 generate-readme: 108 # Ensure generate-readme.py runs fine 109 runs-on: ubuntu-latest 110 steps: 111 - uses: actions/checkout@v2 112 - uses: actions/setup-python@v4 113 # These parameters should match ones in readme.yaml 114 with: 115 python-version: '3.7' 116 architecture: 'x64' 117 - run: python3 -m pip install --require-hashes -r .github/requirements.txt 118 - run: python3 generate-readme.py 119 120 group_id_check_for_maps_libraries: 121 runs-on: ubuntu-latest 122 steps: 123 - uses: actions/checkout@v3 124 - name: Install Maps modules 125 run: | 126 IncludedNonCloudModules=$(find java-maps-* -name 'pom.xml' \ 127 |sed -e 's|/pom.xml$||' |xargs |sed -e 's/ /,/g') 128 echo "Included modules: ${IncludedNonCloudModules}" 129 mvn -B -V -ntp install --also-make --projects "${IncludedNonCloudModules}" \ 130 -DskipTests 131 132 - name: Ensure Maps libraries have com.google.maps group IDs 133 run: | 134 for POM in $(find java-maps-* -name 'pom.xml'); do 135 group_id=$(mvn -q exec:exec -Dexec.executable=echo -Dexec.args='${project.groupId}' \ 136 --projects $POM 2>/dev/null ) 137 echo "${group_id}" |grep -q com.google.maps 138 # 0 if match; otherwise 1 139 match=$? 140 if [ "${match}" == "1" ]; then 141 echo "Unexpected group ID '${group_id}' found in ${POM}" 142 exit 1 143 fi 144 echo "Passed ${POM}" 145 done 146 echo "All group IDs start with com.google.maps. Good." 147 148 package_name_check: 149 runs-on: ubuntu-latest 150 steps: 151 - uses: actions/checkout@v3 152 - name: Ensure no new invalid package name in Java files 153 shell: bash 154 run: | 155 # grep returns "1" (error) when no output 156 set +e 157 echo "Finding files matching '*main/java/google/*.java'" 158 # In past, we published Java classes with wrong package names (google.) 159 # due to improper java_package field in proto files (https://protobuf.dev/programming-guides/proto3/#options). 160 # This check excludes these existing files. 161 162 # java/com/google : This is the standard package 163 # samples : Samples are not shipped as a library 164 # grafeas : java-grafeas is known to have special package name 165 # cloud-build v2 : java_package was not configured when we published 166 # the Cloud Build V2 client library 167 # the rest : the same as above 168 invalid_files=$(find . -name '*.java' \ 169 |grep --invert-match 'java/com/google' \ 170 |grep --invert-match samples \ 171 |grep --invert-match grafeas \ 172 |grep --invert-match 'cloud-build.*v2' \ 173 |grep --invert-match 'google/monitoring/v3/DroppedLabelsOuterClass.java' \ 174 |grep --invert-match 'google/cloud/policytroubleshooter/v1/Explanations.java') 175 if [ -n "${invalid_files}" ]; then 176 echo "New invalid package name found. Check the files: ${invalid_files}" 177 exit 1 178 fi 179 echo "No new invalid package names in Java files" 180 181 182