Skip to content

[CONNECT-2858] Update build script to fail with a clear error if a tag exists already #53

[CONNECT-2858] Update build script to fail with a clear error if a tag exists already

[CONNECT-2858] Update build script to fail with a clear error if a tag exists already #53

Workflow file for this run

name: "Build and Test"
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build:
name: "Build"
runs-on:
- ubuntu-latest
env:
GRADLE_OPTS: "-Djava.security.egd=file:/dev/./urandom -Dorg.gradle.parallel=true"
container:
image: azul/zulu-openjdk:11
steps:
- name: "Install packages"
run: apt-get update && apt-get install -y git
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-tags: true
- name: "Validate version tag doesn't exist"
run: |
VERSION=$(grep '^version=' gradle.properties | cut -d'=' -f2)
TAG="v${VERSION}"
REPO_URL="https://github.com/${{ github.repository }}"
if git ls-remote --tags "${REPO_URL}" | grep -q "refs/tags/${TAG}$"; then
echo "============================================="
echo "ERROR: Tag ${TAG} already exists!"
echo ""
echo "Please bump the version in gradle.properties"
echo "============================================="
exit 1
fi
echo "✓ Version ${VERSION} is valid (tag ${TAG} does not exist yet)"
- name: "Gradle cache"
uses: actions/cache@v4
with:
path: |
~/.gradle
key: gradle-v1-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties', '**/*.gradle*') }}
- name: "Assemble jar"
run: GRADLE_USER_HOME=$HOME/.gradle ./gradlew assemble --console=plain --no-daemon
- name: "Test if publishing works"
run: GRADLE_USER_HOME=$HOME/.gradle ./gradlew publishToMavenLocal --console=plain --no-daemon --stacktrace
- name: "Tag release"
if: github.ref == 'refs/heads/main'
run: GRADLE_USER_HOME=$HOME/.gradle ./gradlew tagRelease --console=plain --no-daemon