From 2e881986d6f81ddecd4823f6dfc684f87c2a95a9 Mon Sep 17 00:00:00 2001 From: agusgroh Date: Wed, 17 Apr 2024 08:16:57 -0300 Subject: [PATCH] SP-550 Adds GH tagging --- .../workflows/{release.yml => publish.yml} | 2 +- .github/workflows/version-tag.yml | 39 +++++++++++ src/test/java/com/scanoss/TestScanner.java | 2 +- tools/get_next_version.sh | 64 +++++++++++++++++++ 4 files changed, 105 insertions(+), 2 deletions(-) rename .github/workflows/{release.yml => publish.yml} (99%) create mode 100644 .github/workflows/version-tag.yml create mode 100755 tools/get_next_version.sh diff --git a/.github/workflows/release.yml b/.github/workflows/publish.yml similarity index 99% rename from .github/workflows/release.yml rename to .github/workflows/publish.yml index 6620213..55aa20b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: Release +name: Publish # Build, deploy and attach supported artifacts and draft release tag on: diff --git a/.github/workflows/version-tag.yml b/.github/workflows/version-tag.yml new file mode 100644 index 0000000..a5ab750 --- /dev/null +++ b/.github/workflows/version-tag.yml @@ -0,0 +1,39 @@ +name: Repo Version Tagging +# This workflow will read the version details from the repo and apply a branch + +on: + workflow_dispatch: + inputs: + run_for_real: + required: true + default: false + type: boolean + description: "Apply next tag (or Dry Run)" + +jobs: + version-tagging: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: '0' + token: ${{ secrets.SC_GH_TAG_TOKEN }} + - name: Setup Java + uses: actions/setup-java@v4 + with: + java-version: 11 + - name: Determine Tag + id: taggerVersion + run: | + app_version=$(tools/get_next_version.sh) + echo "New Proposed tag: $app_version" + echo "package_app_version=$app_version" >> $GITHUB_ENV + + - name: Apply Tag + if: ${{ inputs.run_for_real }} + id: taggerApply + run: | + echo "Applying tag ${{env.package_app_version}} ..." + git tag "${{env.package_app_version}}" + echo "Pushing changes..." + git push --tags \ No newline at end of file diff --git a/src/test/java/com/scanoss/TestScanner.java b/src/test/java/com/scanoss/TestScanner.java index efc4269..c39e711 100644 --- a/src/test/java/com/scanoss/TestScanner.java +++ b/src/test/java/com/scanoss/TestScanner.java @@ -201,7 +201,7 @@ public void TestScannerScanFileListPositive() { List fileList = Arrays.asList( "src/test/java/com/scanoss/TestScanner.java", "src/test/java/com/scanoss/TestWinnowing.java", - ".github/workflows/release.yml", + ".github/workflows/publish.yml", ".gitignore", "tmp/.gitignore" ); diff --git a/tools/get_next_version.sh b/tools/get_next_version.sh new file mode 100755 index 0000000..88d18de --- /dev/null +++ b/tools/get_next_version.sh @@ -0,0 +1,64 @@ +#!/bin/bash +### +# SPDX-License-Identifier: MIT +# +# Copyright (c) 2024, SCANOSS +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +### +# +# Get the defined package version and compare to the latest tag. Echo the new tag if it doesn't already exist. +# + +# Get current directory +export dir=$(dirname "$0") +if [ "$dir" = "" ] ; then + export dir=. +fi + + +# Get latest git tagged version +version=$(git describe --tags --abbrev=0) +if [[ -z "$version" ]] ; then + version=$(git describe --tags "$(git rev-list --tags --max-count=1)") +fi +if [[ -z "$version" ]] ; then + echo "Error: Failed to determine a valid version number" >&2 + exit 1 +fi + +# Get latest SCANOSS Java version +scanoss_java_version=$(cd "$dir"/.. && ./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout) +if [ -z "$scanoss_java_version" ]; then + echo "Error: version not found" >&2 + exit 1 +fi + + +semver_scanoss_java="v$scanoss_java_version" + +echo "Latest Tag: $version, SCANOSS Java Version: $semver_scanoss_java" >&2 + +# If the two versions are the same abort, as we don't want to apply the same tag again +if [[ "$version" == "$semver_scanoss_java" ]] ; then + echo "Latest tag and SCANOSS Java version are the same: $version" >&2 + exit 1 +fi +echo "$semver_scanoss_java" +exit 0 \ No newline at end of file