Skip to content

Instantly share code, notes, and snippets.

@sureshjoshi
Created April 29, 2024 02:41
Show Gist options
  • Save sureshjoshi/2260f08a1d81e7209f7b5d0901c955ad to your computer and use it in GitHub Desktop.
Save sureshjoshi/2260f08a1d81e7209f7b5d0901c955ad to your computer and use it in GitHub Desktop.
Updating Pants example repos
#! /bin/bash
VERSION="$1"
OWNER="${2:-sureshjoshi}"
echo "Updating all repos to use pants version $VERSION for owner $OWNER"
if [ -z "$VERSION" ]; then
echo "Please provide a version string as the first argument."
exit 1
fi
REPOS=(
"example-adhoc"
"example-codegen"
"example-django"
"example-docker"
"example-golang"
"example-javascript"
"example-jvm"
"example-kotlin"
"example-python"
"example-serverless"
"example-visibility"
)
for repo in "${REPOS[@]}"; do
echo ""
echo "********** Updating $repo **********"
echo ""
rm -rf $repo
# Sync your personal fork with pantsbuild in case it's out of date
gh repo sync "$OWNER/$repo"
# Clone your personal fork
gh repo clone "$OWNER/$repo"
(cd $repo
# Updates the pants_version inside of pants.toml
sed -i '' "s/pants_version = .*/pants_version = \"$VERSION\"/g" pants.toml
# Check if there were any changes
if [[ $(git status -s) == "" ]]; then
echo "*** No changes to commit for $repo with version $VERSION... Continuing..."
continue
fi
# Run a sanity check to make sure the repo is still in a good state
if ! $(pants lint test ::); then
echo "*** pants sanity check failed for $repo with version $VERSION. This repo will not be updated... $result"
continue
fi
# Commit the changes
git add pants.toml
git commit -m "Upgrade to Pants $VERSION"
# Push the changes to your personal fork, and create a PR to pantsbuild
git push
gh pr create --title "Upgrade to Pants $VERSION" --body ""
)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment