Skip to content

Commit 431d958

Browse files
committed
chore: Add comments for the scripts
1 parent 2ad1597 commit 431d958

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

.github/scripts/test_dependency_compatibility.sh

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,34 @@
33
# This script generates a maven command to test unit and integration tests for
44
# the repo. The outputted maven command will be in the rough following format
55
# `mvn verify ... -D{dependency.name}.version={dependency.version]`. The variables
6-
# ${dependency.name} and ${dependency.version} come from the upper-bound dependencies
7-
# file called `dependencies.txt` located in the root of sdk-platform-java.
6+
# ${dependency.name} and ${dependency.version} are parsed from the input to the script.
87
#
9-
# The upper-bound dependencies file will be in the format of:
8+
# There are two inputs to the script:
9+
# 1. -f {file}: File for the upper-bound dependencies to test
10+
# 2. -l {deps_list}: Comma-separated list of dependencies to test
11+
# If both inputs are supplied, the deps_list has precedence. For Github Actions workflow,
12+
# the default run will run with the upper-bounds file. A `workflow_dispatch` option takes in
13+
# an input for the deps_list to manually run a subset of dependencies
14+
#
15+
# The default upper-bound dependencies file is `dependencies.txt` located in the root
16+
# of sdk-platform-java. The upper-bound dependencies file will be in the format of:
1017
# ${dependency.name}=${dependency.version}
18+
#
19+
# The deps_list is in the format of `dep1=1.0,dep2=2.0`
1120

1221
set -ex
1322

14-
file=''
15-
dependency_list=''
16-
1723
function print_help() {
1824
echo "Unexpected input argument for this script."
19-
echo "Use -f for the directory of the upper-bound dependencies file."
20-
echo "Use -l for a comma-separate list of dependencies to test (Format: dep1=1.0,dep2=2.0)"
25+
echo "Use -f {file} for the directory of the upper-bound dependencies file."
26+
echo "Use -l {deps_list} for a comma-separated list of dependencies to test (Format: dep1=1.0,dep2=2.0)"
2127
}
2228

29+
# Default to the upper bounds file in the root of the repo
30+
file='dependencies.txt'
31+
dependency_list=''
32+
33+
# The colon (:) after the letter means that there is an input associated with the flag
2334
while getopts 'f:l:' flag; do
2435
case "${flag}" in
2536
f) file="${OPTARG}" ;;
@@ -28,6 +39,7 @@ while getopts 'f:l:' flag; do
2839
esac
2940
done
3041

42+
# Error if both the file and deps_list inputs is empty
3143
if [[ -z "${file}" && -z "${dependency_list}" ]]; then
3244
print_help && exit 1
3345
fi
@@ -40,13 +52,13 @@ if [ -z "${dependency_list}" ]; then
4052
UPPER_BOUND_DEPENDENCY_FILE=$file
4153

4254
if [ ! -e "${UPPER_BOUND_DEPENDENCY_FILE}" ]; then
43-
echo "The inputted upper-bound dependency file '${UPPER_BOUND_DEPENDENCY_FILE}' does not exist"
55+
echo "The inputted upper-bound dependency file '${UPPER_BOUND_DEPENDENCY_FILE}' cannot be found"
4456
exit 1
4557
fi
4658

4759
# Read the file line by line
4860
while IFS= read -r line; do
49-
# Ignore comments and blank lines
61+
# Ignore any comments and blank lines
5062
if [[ "${line}" =~ ^[[:space:]]*# ]] || [[ -z "${line}" ]]; then
5163
continue
5264
fi
@@ -60,7 +72,7 @@ if [ -z "${dependency_list}" ]; then
6072
# Append the formatted property to the Maven command
6173
MAVEN_COMMAND+=" -D${dependency}=${version}"
6274
done < "${UPPER_BOUND_DEPENDENCY_FILE}"
63-
else # List of dependencies was inputted
75+
else # This else block means that a list of dependencies was inputted
6476
# Set the Internal Field Separator (IFS) to a comma.
6577
# This tells 'read' to split the string by commas into an array named DEPS.
6678
# The 'read -ra' command reads the input into an array.
@@ -69,7 +81,7 @@ else # List of dependencies was inputted
6981
# Loop through each item in the DEPS array.
7082
for DEP_PAIR in "${DEPS[@]}"; do
7183
# Skip any empty items that might result from trailing commas.
72-
if [ -z "$DEP_PAIR" ]; then
84+
if [ -z "${DEP_PAIR}" ]; then
7385
continue
7486
fi
7587

.github/workflows/dependency_compatibility_test.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ on:
1717
jobs:
1818
dependency-compatibility-test:
1919
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
2022
steps:
2123
- name: Checkout sdk-platform-java
2224
uses: actions/checkout@v4
@@ -26,15 +28,17 @@ jobs:
2628
java-version: '21'
2729
distribution: 'temurin'
2830
cache: maven
31+
# The workflow_dispatch event is for team members who want to manually test certain dependencies + version combos
32+
# The normal workflow is not from `workflow_dispatch` and will use the default upper-bounds dependencies file
2933
- name: Determine Inputted Dependencies List
3034
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.dependencies-list != '' }}
3135
run: echo "DEPENDENCIES_LIST=${{ github.event.inputs.dependencies-list }}" >> $GITHUB_ENV
32-
# Set up the for the CI
36+
# Install the modules for the rest of the CI
3337
- name: Install sdk-platform-java's modules
3438
# gapic-generator-java requires Java 8 and is irrelevant for this CI
3539
run: mvn -q -B -ntp install --projects '!gapic-generator-java' -Dcheckstyle.skip -Dfmt.skip -DskipTests -Dclirr.skip -T 1C
3640

37-
# Run in the root module which should test for everything barring showcase
41+
# Run in the root module which should test for everything except for showcase
3842
- name: Perform Dependency Compatibility Testing
3943
shell: bash
4044
run: |
@@ -43,7 +47,7 @@ jobs:
4347
else
4448
./.github/scripts/test_dependency_compatibility.sh -f dependencies.txt
4549
fi
46-
# Set up local showcase server
50+
# Set up local showcase server to run the showcase ITs
4751
- name: Parse showcase version
4852
working-directory: java-showcase/gapic-showcase
4953
run: echo "SHOWCASE_VERSION=$(mvn help:evaluate -Dexpression=gapic-showcase.version -q -DforceStdout)" >> "$GITHUB_ENV"
@@ -56,9 +60,10 @@ jobs:
5660
tar -xf showcase-*
5761
./gapic-showcase run &
5862
cd -
59-
# Run for the Showcase tests
60-
- name: Perform Dependency Compatibility Testing (Showcase)
63+
# Run specifically for showcase
64+
- name: Perform Dependency Compatibility Testing (Showcase only)
6165
shell: bash
66+
# Need to cd out of the directory to get the scripts as this step is run inside the java-showcase directory
6267
run: |
6368
if [[ -n "${{ env.DEPENDENCIES_LIST }}" ]]; then
6469
../.github/scripts/test_dependency_compatibility.sh -l ${{ env.DEPENDENCIES_LIST }}

0 commit comments

Comments
 (0)