Skip to content

Commit

Permalink
chore: remove parent and bom templates (#8800)
Browse files Browse the repository at this point in the history
* Use the actual files as templates instead.
* rename print_root_pom.sh to generate_root_pom.sh
* fully remove generate_release_please_config.sh
* fix update_versions.sh to work with single module setup
* call generate_root_versions_txt.sh in bootstrap.sh

Fixes: #8574.
  • Loading branch information
meltsufin authored Nov 16, 2022
1 parent 03eb382 commit 48ad7d8
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 217 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/generated_files_sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v3
- name: Generate root pom.xml file
run: |
bash generation/print_root_pom.sh > pom.xml
bash generation/generate_root_pom.sh
- name: Apply versions from versions.txt files
run: |
bash generation/apply_current_versions.sh
Expand Down
28 changes: 0 additions & 28 deletions generation/bom.pom.xml

This file was deleted.

11 changes: 3 additions & 8 deletions generation/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ cp -R ../../../google-cloud-pom-parent google-cloud-pom-parent
git add --all
git commit -m 'chore: add template files'

../../print_root_pom.sh > pom.xml
../../generate_root_pom.sh

git add pom.xml
git commit -am 'chore: create aggregator pom'
Expand All @@ -88,7 +88,7 @@ git commit -am 'chore: consolidate config to parent'
../../generate_gapic_bom.sh

# add the gapic bom module to root pom.xml by regenerating aggregator pom
../../print_root_pom.sh > pom.xml
../../generate_root_pom.sh

git add gapic-libraries-bom/pom.xml
git commit -am 'chore: create gapic-libraries-bom'
Expand All @@ -100,18 +100,13 @@ cp ../../gapic_bom_versions.txt gapic-libraries-bom/versions.txt
git add --all
git commit -am 'chore: delete non-auto-generated samples'

../../generate_root_versions_txt.sh
../../update_versions.sh -s
../../apply_current_versions.sh

git add --all
git commit -am 'chore: update versions to latest in maven'

# Generate Release Please configuration files
bash ../../generate_release_please_config.sh

git add --all
git commit -am 'chore: create release please configuration'

../../update_owlbot_postprocessor_config.sh

git add --all
Expand Down
2 changes: 2 additions & 0 deletions generation/generate_gapic_bom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ done
mkdir -p gapic-libraries-bom

GENERATION_DIR=$(dirname -- "$0");
perl -0pe 's/<dependencies>.*<\/dependencies>/<dependencies>\nBOM_ARTIFACT_LIST\n <\/dependencies>/s' ${GENERATION_DIR}/../gapic-libraries-bom/pom.xml > ${GENERATION_DIR}/bom.pom.xml
awk -v "dependencyManagements=$bom_lines" '{gsub(/BOM_ARTIFACT_LIST/,dependencyManagements)}1' \
"${GENERATION_DIR}/bom.pom.xml" > gapic-libraries-bom/pom.xml
rm ${GENERATION_DIR}/bom.pom.xml
52 changes: 0 additions & 52 deletions generation/generate_release_please_config.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ GENERATION_DIR=$(dirname -- "$0");
find . -mindepth 2 -maxdepth 2 -name pom.xml |sort --dictionary-order | xargs dirname \
|sed -e 's|./||' | xargs -I '{}' echo " <module>{}</module>" > /tmp/repo-modules.txt

awk -v MODULES="`awk -v ORS='\\\\n' '1' /tmp/repo-modules.txt`" '1;/<modules>/{print MODULES}' ${GENERATION_DIR}/parent.pom.xml
perl -0pe 's/<modules>.*<\/modules>/<modules>\n <\/modules>/s' ${GENERATION_DIR}/../pom.xml > ${GENERATION_DIR}/parent.pom.xml
awk -v MODULES="`awk -v ORS='\\\\n' '1' /tmp/repo-modules.txt`" '1;/<modules>/{print MODULES}' ${GENERATION_DIR}/parent.pom.xml > pom.xml
rm ${GENERATION_DIR}/parent.pom.xml
9 changes: 1 addition & 8 deletions generation/new_client/new-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,8 @@ def generate(
print("Regenerating root pom.xml")

# This script takes care of updating the root pom.xml
os.system(f"cd {monorepo_root} && generation/print_root_pom.sh > pom.xml")
os.system(f"cd {monorepo_root} && generation/generate_root_pom.sh")

print("Regenerating Release Please config files")
subprocess.check_call(
[
"bash", "generation/generate_release_please_config.sh"
],
cwd=monorepo_root,
)
print("Consolidating configurations")
subprocess.check_call(
[
Expand Down
69 changes: 0 additions & 69 deletions generation/parent.pom.xml

This file was deleted.

98 changes: 49 additions & 49 deletions generation/update_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,59 +57,59 @@ fi
count=0
missing_artifacts=()

for path in $(find . -mindepth 2 -maxdepth 2 -name pom.xml | sort | xargs dirname); do
versions_array=($(grep -E "^.*:[0-9]+\.[0-9]+\.[0-9]+.*:[0-9]+\.[0-9]+\.[0-9]+.*$" "${path}/versions.txt"))

for line in "${versions_array[@]}"; do
artifactId=$(echo "${line}" | cut -d ":" -f1)

if [[ "${artifactId}" =~ .*grafeas.* ]]; then
maven_url="https://repo1.maven.org/maven2/io/grafeas/${artifactId}/maven-metadata.xml"
elif [[ "${artifactId}" =~ .*area120.* ]] && [[ "${artifactId}" =~ ^google- ]]; then
maven_url="https://repo1.maven.org/maven2/com/google/area120/${artifactId}/maven-metadata.xml"
elif [[ "${artifactId}" =~ .*analytics.* ]] && [[ "${artifactId}" =~ ^google- ]]; then
maven_url="https://repo1.maven.org/maven2/com/google/analytics/${artifactId}/maven-metadata.xml"
elif [[ "${artifactId}" =~ ^google- ]]; then
maven_url="https://repo1.maven.org/maven2/com/google/cloud/${artifactId}/maven-metadata.xml"

path=.
versions_array=($(grep -E "^.*:[0-9]+\.[0-9]+\.[0-9]+.*:[0-9]+\.[0-9]+\.[0-9]+.*$" "${path}/versions.txt"))

for line in "${versions_array[@]}"; do
artifactId=$(echo "${line}" | cut -d ":" -f1)

if [[ "${artifactId}" =~ .*grafeas.* ]]; then
maven_url="https://repo1.maven.org/maven2/io/grafeas/${artifactId}/maven-metadata.xml"
elif [[ "${artifactId}" =~ .*area120.* ]] && [[ "${artifactId}" =~ ^google- ]]; then
maven_url="https://repo1.maven.org/maven2/com/google/area120/${artifactId}/maven-metadata.xml"
elif [[ "${artifactId}" =~ .*analytics-.* ]] && [[ "${artifactId}" =~ ^google- ]]; then
maven_url="https://repo1.maven.org/maven2/com/google/analytics/${artifactId}/maven-metadata.xml"
elif [[ "${artifactId}" =~ ^(google-|gapic) ]]; then
maven_url="https://repo1.maven.org/maven2/com/google/cloud/${artifactId}/maven-metadata.xml"
else
maven_url="https://repo1.maven.org/maven2/com/google/api/grpc/${artifactId}/maven-metadata.xml"
fi

count=$((count + 1))
echo "Module #${count} -- Downloading ${artifactId} from ${maven_url}"
# Check if the artifact exists in Maven Central, otherwise add to missing_artifacts
if curl --output /dev/null --silent --head --fail "${maven_url}"; then
metadata_file=$(retry_with_backoff 3 10 curl -s "${maven_url}" -H "Accept:application/xml" --limit-rate 200k)

# Versioning of artifacts in Maven Central follow SemVer (Major.Minor.Patch-{alpha|beta})
# This keeps track of the additional versioning after the PATCH value (alpha/beta)
# `cut` normally returns the entire string if the delimiter DNE. The `-s` makes cut return nothing
# maven_latest_version stores Major.Minor.Patch or the entire version
# maven_latest_trailing stores alpha/beta/etc. or nothing
maven_metadata_version=$(echo "${metadata_file}" | grep 'latest' | cut -d '>' -f 2 | cut -d '<' -f 1)
maven_latest_version=$(echo "${maven_metadata_version}" | cut -d "-" -f1)
maven_latest_trailing=$(echo "${maven_metadata_version}" | cut -s -d "-" -f2-)

major_version=$(echo "${maven_latest_version}" | cut -d "." -f1)
minor_version=$(echo "${maven_latest_version}" | cut -d "." -f2)
patch_version=$(echo "${maven_latest_version}" | cut -d "." -f3)
patch_version_bump=$((patch_version + 1))
if [[ -z "${maven_latest_trailing}" ]]; then
maven_version_bump="${major_version}.${minor_version}.${patch_version_bump}"
else
maven_url="https://repo1.maven.org/maven2/com/google/api/grpc/${artifactId}/maven-metadata.xml"
maven_version_bump="${major_version}.${minor_version}.${patch_version_bump}-${maven_latest_trailing}"
fi

count=$((count + 1))
echo "Module #${count} -- Downloading ${artifactId} from ${maven_url}"
# Check if the artifact exists in Maven Central, otherwise add to missing_artifacts
if curl --output /dev/null --silent --head --fail "${maven_url}"; then
metadata_file=$(retry_with_backoff 3 10 curl -s "${maven_url}" -H "Accept:application/xml" --limit-rate 200k)

# Versioning of artifacts in Maven Central follow SemVer (Major.Minor.Patch-{alpha|beta})
# This keeps track of the additional versioning after the PATCH value (alpha/beta)
# `cut` normally returns the entire string if the delimiter DNE. The `-s` makes cut return nothing
# maven_latest_version stores Major.Minor.Patch or the entire version
# maven_latest_trailing stores alpha/beta/etc. or nothing
maven_metadata_version=$(echo "${metadata_file}" | grep 'latest' | cut -d '>' -f 2 | cut -d '<' -f 1)
maven_latest_version=$(echo "${maven_metadata_version}" | cut -d "-" -f1)
maven_latest_trailing=$(echo "${maven_metadata_version}" | cut -s -d "-" -f2-)

major_version=$(echo "${maven_latest_version}" | cut -d "." -f1)
minor_version=$(echo "${maven_latest_version}" | cut -d "." -f2)
patch_version=$(echo "${maven_latest_version}" | cut -d "." -f3)
patch_version_bump=$((patch_version + 1))
if [[ -z "${maven_latest_trailing}" ]]; then
maven_version_bump="${major_version}.${minor_version}.${patch_version_bump}"
else
maven_version_bump="${major_version}.${minor_version}.${patch_version_bump}-${maven_latest_trailing}"
fi
if [[ "${snapshot_flag}" = "true" ]]; then
new_version="${artifactId}:${maven_metadata_version}:${maven_version_bump}-SNAPSHOT"
else
new_version="${artifactId}:${maven_metadata_version}:${maven_metadata_version}"
fi

sed -i.bak "s/${line}/${new_version}/g" "${path}/versions.txt" && rm "${path}/versions.txt.bak"
if [[ "${snapshot_flag}" = "true" ]]; then
new_version="${artifactId}:${maven_metadata_version}:${maven_version_bump}-SNAPSHOT"
else
missing_artifacts+=("${artifactId}")
new_version="${artifactId}:${maven_metadata_version}:${maven_metadata_version}"
fi
done

sed -i.bak "s/${line}/${new_version}/g" "${path}/versions.txt" && rm "${path}/versions.txt.bak"
else
missing_artifacts+=("${artifactId}")
fi
done

echo "These artifacts don't exist: ${missing_artifacts[*]}"
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,4 @@
</build>
</profile>
</profiles>
</project>
</project>

0 comments on commit 48ad7d8

Please sign in to comment.