From 49255db883a563315a7c8854713eb7663f57bda6 Mon Sep 17 00:00:00 2001 From: Jeff Nelson Date: Sat, 31 Oct 2026 19:53:33 -0400 Subject: [PATCH] Use the shared semantic version tool --- .agents | 2 +- .circleci/config.yml | 5 ++ .circleci/init-agent-skills.sh | 29 +++++++++++ .github/workflows/agents.yml | 2 +- build.gradle | 29 ++++++++--- version.sh | 94 ---------------------------------- 6 files changed, 57 insertions(+), 104 deletions(-) create mode 100644 .circleci/init-agent-skills.sh delete mode 100755 version.sh diff --git a/.agents b/.agents index 31f89b3..60986ed 160000 --- a/.agents +++ b/.agents @@ -1 +1 @@ -Subproject commit 31f89b30ce3f75f4b381156bf6ee1ce9752de45a +Subproject commit 60986ed0018283a8978f2567e4babad1036fb0c7 diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ab163a..3fc89cc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,6 +10,11 @@ jobs: steps: - checkout: path: ~/$CIRCLE_PROJECT_REPONAME + - run: + name: Initialize shared build tools + command: | + cd ~/$CIRCLE_PROJECT_REPONAME + bash .circleci/init-agent-skills.sh - run: name: Build and Upload context: cloudsmith-creds diff --git a/.circleci/init-agent-skills.sh b/.circleci/init-agent-skills.sh new file mode 100644 index 0000000..034c8d3 --- /dev/null +++ b/.circleci/init-agent-skills.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# Check out the pinned private build tools with the existing checkout identity +# or an optional read-only identity. Remove temporary key material on every +# exit. +set +x +set -euo pipefail +cd "$(dirname "$0")/.." + +if [ -n "${CINCHAPI_AGENT_SKILLS_READ_KEY:-}" ]; then + umask 077 + key_file=$(mktemp) + trap 'rm -f "$key_file"' EXIT + printf '%s\n' "$CINCHAPI_AGENT_SKILLS_READ_KEY" > "$key_file" + if GIT_SSH_COMMAND="ssh -i '$key_file' -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes" \ + git submodule update --init .agents; then + : + else + printf '%s\n' 'The configured read key cannot fetch the pinned agent tools.' >&2 + exit 1 + fi +else + if git submodule update --init .agents; then + : + else + printf '%s\n' 'The checkout identity needs read access to cinchapi-agent-skills.' \ + 'Set CINCHAPI_AGENT_SKILLS_READ_KEY to a dedicated read-only key if needed.' >&2 + exit 1 + fi +fi diff --git a/.github/workflows/agents.yml b/.github/workflows/agents.yml index 5563698..8f8e6a3 100644 --- a/.github/workflows/agents.yml +++ b/.github/workflows/agents.yml @@ -67,7 +67,7 @@ jobs: concurrency: group: agents-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.number }} queue: max - uses: cinchapi/cinchapi-agent-skills/.github/workflows/router.yml@31f89b30ce3f75f4b381156bf6ee1ce9752de45a + uses: cinchapi/cinchapi-agent-skills/.github/workflows/router.yml@60986ed0018283a8978f2567e4babad1036fb0c7 permissions: contents: read id-token: write diff --git a/build.gradle b/build.gradle index 2177d72..c214e78 100644 --- a/build.gradle +++ b/build.gradle @@ -5,11 +5,29 @@ plugins { id 'maven-publish' } -// The project version is controlled externally by the "version.sh" script. +/** + * Return the publication coordinate without advancing the build counter. Branch + * suffix digits remain part of the coordinate. + */ +def getPublishedVersion = { buildVersion -> + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'bash', rootProject.file('.agents/tools/version'), + '--published', buildVersion.toString() + standardOutput = stdout + } + return stdout.toString().trim() +} + +/** + * Return one semantic build version for this project and advance its counter. + * Fail if the shared tool cannot read the version or identify the branch. + */ def getVersion = { -> def stdout = new ByteArrayOutputStream() exec { - commandLine 'bash', 'version.sh' + commandLine 'bash', rootProject.file('.agents/tools/version'), + '--root', rootProject.projectDir.absolutePath standardOutput = stdout } return stdout.toString().trim() @@ -17,12 +35,7 @@ def getVersion = { -> group = 'com.cinchapi' version = getVersion() -// Drop the build component from version number and use that for -// publishing -ext.mavenVersion = version.split('\\.') -ext.mavenVersion[3] = ext.mavenVersion[3].replaceAll("[0-9]+-", "-") -ext.mavenVersion[3] = ext.mavenVersion[3].replaceAll("[0-9]+", "").trim() -ext.mavenVersion = ext.mavenVersion.join(".").replace(".-", "-").replaceAll('\\.$', "") +ext.mavenVersion = getPublishedVersion(version) task wrapper(type: Wrapper) { gradleVersion = '3.0' diff --git a/version.sh b/version.sh deleted file mode 100755 index 6125799..0000000 --- a/version.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (c) 2015 Cinchapi Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -################################################# -### Script to get or set the current version ### -################################################# - -# Bootstrap Git's ability to give the branch, if necessary -git rev-parse --abbrev-ref HEAD > /dev/null 2>&1 -if [ $? -ne 0 ]; then - git commit --allow-empty -m "Bootstrapping version.sh" -fi - -#Ensure that this script operates from the directory in which it resides -cd "$(dirname "$0")" - -BASE_VERSION_FILE=".version" -JENKINS_HOME="/opt/jenkins" -if [ -w $JENKINS_HOME ]; then - COUNTER_FILE="$JENKINS_HOME/.counter" -else - COUNTER_FILE=".counter" -fi - -if [ -z "$1" ] ; then - VERSION=`cat $BASE_VERSION_FILE` - BRANCH=`git rev-parse --abbrev-ref HEAD` - COMMIT=`git rev-parse HEAD | cut -c1-10` - - # Get counter value - if [ ! -f $COUNTER_FILE ] ; then - echo 0 > $COUNTER_FILE - fi - COUNTER=`cat $COUNTER_FILE` - ((COUNTER++)) - echo $COUNTER > $COUNTER_FILE - VERSION=$VERSION.$COUNTER - case $BRANCH in - develop ) - EXTRA="-SNAPSHOT" - ;; - feature* ) - IFS='/' - PARTS=( $BRANCH ) - EXTRA="-${PARTS[1]}" - EXTRA=`echo $EXTRA | tr '[:lower:]' '[:upper:]'` - ;; - release* ) - EXTRA="" - ;; - * ) - # At this point we do not need to refer - # to any commit hash since we'll have a - # tag that represents the overall release - EXTRA="" - ;; - esac - echo $VERSION$EXTRA -else - NEW_VERSION=$1 - if [[ $NEW_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]$ ]] ; then - echo $NEW_VERSION > $BASE_VERSION_FILE - rm $COUNTER_FILE 2>/dev/null - sed -i '' -E "s/[0-9]+\.[0-9]+\.[0-9]+/$NEW_VERSION/g" README.md - - # Find all the build.gradle files and update the version if it is - # listed. - files=( `find . -name "build.gradle" | cut -d / -f 2,3` ) - for file in "${files[@]}" - do - sed -i '' -E "s/pom.version = '[0-9]+\.[0-9]+\.[0-9]'+/pom.version = '$NEW_VERSION'/g" $file - sed -i '' -E "s/pom.version = '[0-9]+\.[0-9]+\.[0-9]-SNAPSHOT'+/pom.version = '$NEW_VERSION-SNAPSHOT'/g" $file - done - - echo "The version has been set to $NEW_VERSION" - else - echo "Please specify a valid version .." - exit 1 - fi -fi -exit 0