diff --git a/.circleci/adjust-pom-version.sh b/.circleci/adjust-pom-version.sh new file mode 100755 index 00000000..054fbdf2 --- /dev/null +++ b/.circleci/adjust-pom-version.sh @@ -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 to: $SLUG-SNAPSHOT" +sed -i "s/.*/$SLUG-SNAPSHOT<\/revision>/" $POM +git diff $POM diff --git a/.circleci/config.yml b/.circleci/config.yml index 5981d2fa..42bdf306 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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" }} diff --git a/qqq-dev-tools/bin/get-latest-snapshot.sh b/qqq-dev-tools/bin/get-latest-snapshot.sh index 11025009..232842d5 100755 --- a/qqq-dev-tools/bin/get-latest-snapshot.sh +++ b/qqq-dev-tools/bin/get-latest-snapshot.sh @@ -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" diff --git a/qqq-dev-tools/bin/git-tag b/qqq-dev-tools/bin/git-tag index 923f9f63..ddb02dd8 100755 --- a/qqq-dev-tools/bin/git-tag +++ b/qqq-dev-tools/bin/git-tag @@ -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 diff --git a/qqq-dev-tools/bin/update-all-qqq-deps.sh b/qqq-dev-tools/bin/update-all-qqq-deps.sh index baa73113..846eefeb 100755 --- a/qqq-dev-tools/bin/update-all-qqq-deps.sh +++ b/qqq-dev-tools/bin/update-all-qqq-deps.sh @@ -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