Skip to content

Commit

Permalink
PMM-4817 use pmm-submodules vs distinct repos
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Tymchuk committed Jul 21, 2023
1 parent 3ce6898 commit f90e02f
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions build/scripts/create-tags
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash
# Important: This script should never cause the pipeline to fail, so that the tags can be created outside of it.
# To run it locally, you need pass the version, i.e. export VERSION=2.39.x
# If run locally, it:
# - does not need to run inside pmm-submodules as it clones all the necessary repos
# - it clones the pmm-submodules repo and checks out the branch corresponding to the version
# - does not need to configure git to push using ssh, this user should set it all up ahead of time
# - will use the user's creds and email to tag the repos, therefore sufficient permissions are required

Expand All @@ -11,10 +12,10 @@ set -o xtrace

# List of repositories whose release branches need to be tagged
declare repos=(
"percona-platform/grafana"
"percona/grafana-dashboards"
"percona/pmm"
"Percona-Lab/pmm-submodules"
"sources/pmm/src/github.com/percona/pmm"
"sources/grafana/src/github.com/grafana/grafana"
"sources/grafana-dashboards"
"."
)

# These setting are only needed when running in CI (Jenkins or github actions)
Expand All @@ -31,37 +32,41 @@ fi
TAG="v${VERSION}"
echo "We will be tagging repos with a tag: $TAG"

for REPO in "${repos[@]}"; do
DIR_NAME=${REPO##*/} # grab the repo name from <company>/<repo>
rm -fr "$DIR_NAME" || true
mkdir -p "$DIR_NAME"
REPO_DIR=pmm-submodules
if [ -d "$REPO_DIR" ]; then
rm -rf "$REPO_DIR"
fi
git clone https://github.com/Percona-Lab/pmm-submodules "$REPO_DIR"

cd "$REPO_DIR" >/dev/null
if ! git checkout "pmm-${VERSION}"; then
echo "Fatal: failed to check out to pmm-${VERSION} branch"
cd -
rm -rf "$REPO_DIR"
exit 0 # this is on purpose, we don't want to fail the pipeline
fi
git submodule update --init --recursive

pushd "$DIR_NAME" >/dev/null
git clone https://github.com/${REPO} ./
# The default is https, and we want to set it to ssh
git remote set-url origin [email protected]:${REPO}.git
for REPO in "${repos[@]}"; do

BRANCH="pmm-${VERSION}"
if ! git checkout "$BRANCH"; then
echo "Warning: failed to checkout the repository $REPO to $BRANCH"
popd >/dev/null
rm -rf "$DIR_NAME"
continue
fi
pushd "$REPO" >/dev/null
# git remote set-url origin [email protected]:${REPO}.git
echo "SHA: $(git rev-parse HEAD)"

# If the tag already exists, we want to delete it and re-tag this SHA
if git tag -l "$TAG"; then
git tag --delete "$TAG"
git push --delete origin "$TAG"
echo "Fatal: tag $TAG already exists in $REPO, we won't continue..."
break
fi

git tag --message="Version $TAG." "$TAG"
git tag --message="Version $VERSION." "$TAG"
if ! git push origin "$TAG"; then
echo "Warning: failed to tag the repository $REPO with $TAG"
echo "Fatal: failed to tag the repository $REPO with $TAG"
break
fi
popd >/dev/null
rm -rf "$DIR_NAME"
done

cd -
rm -rf "$REPO_DIR"
unset repos

0 comments on commit f90e02f

Please sign in to comment.