Skip to content

Commit

Permalink
PMM-4817 move git tags script to pmm (#2376) (#2403)
Browse files Browse the repository at this point in the history
* PMM-4817 move create-tags script to pmm

* PMM-4817 update the notes

* PMM-4817 add more comments

* PMM-4817 add popd before continue

* PMM-4817 use pmm-submodules vs distinct repos

* PMM-4817 clone a specific branch, not main

* PMM-4817 update the description

* PMM-4817 do not delete the directory if it exists

* PMM-4817 popd on push failure
  • Loading branch information
Alex Tymchuk committed Aug 9, 2023
1 parent 708ce86 commit a657acc
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 48 deletions.
77 changes: 77 additions & 0 deletions build/scripts/create-tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/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:
# - clones pmm-submodules repository and checks out the branch corresponding to the version
# - skips git ssh configuration and expects the user to set it up ahead of time
# - uses the current user's creds and email to push tags to the repos, therefore sufficient git permissions are required

set +o errexit
set +o nounset
set -o xtrace

# List of repositories whose release branches need to be tagged
declare repos=(
"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)
if [ -n "$CI" ]; then
# Configure git settings globally
git config --global advice.detachedHead false
git config --global user.email "[email protected]"
git config --global user.name "PMM Jenkins"

# Configure git to push using ssh
export GIT_SSH_COMMAND="/usr/bin/ssh -i ${SSHKEY} -o StrictHostKeyChecking=no -o LogLevel=error -o UserKnownHostsFile=/dev/null"
fi

TAG="v${VERSION}"
echo "We will be tagging repos with a tag: $TAG"

REPO_DIR=pmm-submodules
if [ -d "$REPO_DIR" ]; then
echo "Error: the directory $REPO_DIR already exists, exiting..."
exit 0 # this is on purpose, we don't want to fail the pipeline
fi

if ! git clone --branch "pmm-${VERSION}" --single-branch https://github.com/Percona-Lab/pmm-submodules "$REPO_DIR"; then
echo "Fatal: failed to clone pmm-submodules, branch pmm-${VERSION}"
exit 0
fi

cd "$REPO_DIR" >/dev/null
git submodule update

for REPO in "${repos[@]}"; do
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
echo "Fatal: tag $TAG already exists in $REPO, exiting..."
break
fi

if [ -n "$CI" ]; then
# We can't sign tags in CI, so we create them without signing
git tag --message="Version $VERSION." "$TAG"
else
git tag --message="Version $VERSION." --sign "$TAG"
fi
if ! git push origin "$TAG"; then
echo "Fatal: failed to tag the repository $REPO with $TAG, exiting..."
popd >/dev/null
break
fi
popd >/dev/null
done

git submodule status
cd -
rm -rf "$REPO_DIR"
unset repos
48 changes: 0 additions & 48 deletions build/scripts/create-tags.py

This file was deleted.

0 comments on commit a657acc

Please sign in to comment.