Updates to work with branch-specific maven deployments in/with circleci

This commit is contained in:
2023-05-09 10:43:23 -05:00
parent cedc1edfac
commit 815bd8b0ce
5 changed files with 78 additions and 5 deletions

23
.circleci/adjust-pom-version.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
if [ -z "$CIRCLE_BRANCH" ] && [ -z "$CIRCLE_TAG" ]; then
echo "Error: env vars CIRCLE_BRANCH and CIRCLE_TAG were not set."
exit 1;
fi
if [ "$CIRCLE_BRANCH" == "dev" ] || [ "$CIRCLE_BRANCH" == "staging" ] || [ "$CIRCLE_BRANCH" == "main" ]; then
echo "On a primary branch [$CIRCLE_BRANCH] - will not edit the pom version.";
exit 0;
fi
if [ -n "$CIRCLE_BRANCH" ]; then
SLUG=$(echo $CIRCLE_BRANCH | sed 's/[^a-zA-Z0-9]/-/g')
else
SLUG=$(echo $CIRCLE_TAG | sed 's/^snapshot-//g')
fi
POM=$(dirname $0)/../pom.xml
echo "Updating $POM <revision> to: $SLUG-SNAPSHOT"
sed -i "s/<revision>.*/<revision>$SLUG-SNAPSHOT<\/revision>/" $POM
git diff $POM

View File

@ -82,6 +82,10 @@ commands:
mvn_jar_deploy:
steps:
- checkout
- run:
name: Adjust pom version
command: |
.circleci/adjust-pom-version.sh
- restore_cache:
keys:
- v1-dependencies-{{ checksum "pom.xml" }}

View File

@ -9,6 +9,34 @@ CURRENT_VERSION="$(cat $QQQ_DEV_TOOLS_DIR/CURRENT-SNAPSHOT-VERSION)"
MODULE_LIST_FILE=$QQQ_DEV_TOOLS_DIR/MODULE_LIST
. $QQQ_DEV_TOOLS_DIR/.env
BRANCH=$(git rev-parse --abbrev-ref HEAD)
SLUG=$(echo $BRANCH | sed 's/[^a-zA-Z0-9]/-/g')
function checkForBranchBuild
{
artifact=$1
#############################################################
## on standard branches, don't look for branch deployments ##
#############################################################
if [ "$BRANCH" == "dev" ] || [ "$BRANCH" == "staging" ] || [ "$BRANCH" == "main" ]; then
echo 0;
return;
fi
###################################################################
## else, do look for a branch deployment, and return accordingly ##
###################################################################
curl -s --user ${GITHUB_USER}:${GITHUB_TOKEN} https://maven.pkg.github.com/Kingsrook/qqq-maven-registry/com/kingsrook/qqq/${artifact}/${SLUG}-SNAPSHOT/maven-metadata.xml | grep unable.to.fetch
if [ "$?" == "1" ]; then
echo 1;
return;
fi
echo 0;
return;
}
function getLatestVersion
{
artifact=$1
@ -23,10 +51,10 @@ function getLatestVersion
return
fi
timetsamp=$(xpath -q -e '/metadata/versioning/snapshot/timestamp/text()' /tmp/metadata.xml)
timestamp=$(xpath -q -e '/metadata/versioning/snapshot/timestamp/text()' /tmp/metadata.xml)
buildNumber=$(xpath -q -e '/metadata/versioning/snapshot/buildNumber/text()' /tmp/metadata.xml)
echo "$version-$timetsamp-$buildNumber"
echo "$version-$timestamp-$buildNumber"
}
function promptForVersion
@ -70,11 +98,18 @@ else
artifact=$1
version=$2
if [ "$version" == "-l" ]; then
version=$CURRENT_VERSION
useSlug=$(checkForBranchBuild $artifact)
if [ "$useSlug" == "1" ]; then
version=$SLUG
else
version=$CURRENT_VERSION
fi
echo "Using $version for $artifact" >&2
fi
if [ -z "$artifact" -o -z "$version" ]; then
if [ -z "$ar^tifact" -o -z "$version" ]; then
echo "Usage: $0 artifact snapshot-version-prefix"
echo " or: $0 artifact -l (latest of CURRENT_VERSION, or branch-slug, if it has been deployed)"
echo " or: $0 -i (interactive mode)"
echo " or: $0 -a [snapshot-version-prefix] (all mode)"
echo "Ex: $0 qqq-backend-core $CURRENT_VERSION"

View File

@ -3,6 +3,11 @@
############################################################################
## git-tag
## Add (deleting, if it already exists) a git tag to a repo (both local & remote)
##
## Usage:
## git-tag tag-name - make/update/push the specified tag-name.
## git-tag -l - list tags.
## git-tag snapshot-BRANCH_SLUG - make the tag name "snapshot-" + current branch name, in "slug" form
############################################################################
TAG=$1
@ -16,6 +21,12 @@ if [ "$TAG" == "-l" ]; then
exit 0;
fi
if [ "$TAG" == "snapshot-BRANCH_SLUG" ]; then
BRANCH=$(git rev-parse --abbrev-ref HEAD)
SLUG=$(echo $BRANCH | sed 's/[^a-zA-Z0-9]/-/g')
TAG="snapshot-$SLUG"
fi
echo
echo "== Deleting $TAG on local"
git tag -d $TAG

View File

@ -15,7 +15,7 @@ MODULE_LIST_FILE=$QQQ_DEV_TOOLS_DIR/MODULE_LIST
for module in $(cat $MODULE_LIST_FILE); do
echo "Updating $module..."
version=$(get-latest-snapshot.sh $module $CURRENT_VERSION)
version=$(get-latest-snapshot.sh $module -l)
update-dep.sh $module $version -q
done