Skip to content

Commit

Permalink
SP-550 Adds GH tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
agustingroh committed Apr 17, 2024
1 parent c04ebda commit 2e88198
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: Publish
# Build, deploy and attach supported artifacts and draft release tag

on:
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/version-tag.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/test/java/com/scanoss/TestScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void TestScannerScanFileListPositive() {
List<String> 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"
);
Expand Down
64 changes: 64 additions & 0 deletions tools/get_next_version.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2e88198

Please sign in to comment.