From 77300d0037469c33ad597d4458c4ae587b4b5ce0 Mon Sep 17 00:00:00 2001 From: Sk Niyaj Ali Date: Sat, 7 Sep 2024 04:14:51 +0530 Subject: [PATCH] Attempt#4 - Fixing Release Workflow Error --- .../actions/create-release-notes/action.yml | 2 +- .../actions/create-release-number/action.yml | 47 +++++++++++++++---- build.gradle.kts | 4 +- settings.gradle.kts | 6 +-- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/.github/actions/create-release-notes/action.yml b/.github/actions/create-release-notes/action.yml index 0cc3345af..6cc1e7464 100644 --- a/.github/actions/create-release-notes/action.yml +++ b/.github/actions/create-release-notes/action.yml @@ -33,7 +33,7 @@ runs: owner: context.repo.owner, repo: context.repo.repo, tag_name: '${{ inputs.tag-name }}', - target_commitish: 'dev', + target_commitish: 'development', previous_tag_name: '${{ steps.latest-release-tag.outputs.result }}', }) return data.body.replaceAll('`', '\'').replaceAll('"', '\'') diff --git a/.github/actions/create-release-number/action.yml b/.github/actions/create-release-number/action.yml index d9d16cf61..9d35f42b5 100644 --- a/.github/actions/create-release-number/action.yml +++ b/.github/actions/create-release-number/action.yml @@ -1,5 +1,5 @@ name: 'Create Release Numbers' -description: 'Creates the current release number based on checked out code' +description: 'Creates the current release number based on Gradle or Git history' outputs: version-code: description: 'The numeric app version' @@ -10,18 +10,45 @@ outputs: runs: using: 'composite' steps: - - name: Set Build Number + - name: Set Build Number and Version id: version-generator shell: bash run: | + # Try to get version from Gradle ./gradlew versionFile - COMMITS=`git rev-list --count HEAD` - TAGS=`git tag | grep -v beta | wc -l` + GRADLE_VERSION=$(cat version.txt) + + if [ "$GRADLE_VERSION" = "unspecified" ] || [ -z "$GRADLE_VERSION" ]; then + echo "Gradle version is unspecified or empty. Generating version from Git." + + # Get the latest tag + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") + + # Extract major, minor, patch from the tag + IFS='.' read -r MAJOR MINOR PATCH <<< "${LATEST_TAG#v}" + + # Count commits since the last tag + COMMITS_SINCE_TAG=$(git rev-list ${LATEST_TAG}..HEAD --count) + + # Calculate new patch version + NEW_PATCH=$((PATCH + COMMITS_SINCE_TAG)) + + # Generate version name + VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}" + else + echo "Using Gradle-generated version." + VERSION=$GRADLE_VERSION + fi + + # Calculate version code + COMMITS=$(git rev-list --count HEAD) + TAGS=$(git tag | grep -v beta | wc -l) VC=$((((COMMITS+TAGS) * 3) << 1)) - echo Number Commits $COMMITS - echo Number Tags $TAGS - echo Version Code $VC + + echo "Version: $VERSION" + echo "Number of Commits: $COMMITS" + echo "Number of Tags: $TAGS" + echo "Version Code: $VC" + echo "version-code=$VC" >> $GITHUB_OUTPUT - VERSION=`cat version.txt` - echo Version $VERSION - echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "version=$VERSION" >> $GITHUB_OUTPUT \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index a622eae73..f8d5de6e1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -36,7 +36,7 @@ plugins { tasks.register("versionFile") { group = "publishing" doLast { - println(project.version) - project.rootProject.file("version.txt").writeText(project.version.toString()) + println(project.version.toString()) + project.file("version.txt").writeText(project.version.toString()) } } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index bc7089c8e..52e91b495 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,6 +8,7 @@ pluginManagement { gradlePluginPortal() } } + dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.PREFER_PROJECT) repositories { @@ -26,7 +27,7 @@ extensions.configure { setDefaultInferredScope("patch") stages("beta", "final") setScopeCalc { java.util.Optional.of(org.ajoberstar.reckon.core.Scope.PATCH) } -// setScopeCalc(calcScopeFromProp().or(calcScopeFromCommitMessages())) + setScopeCalc(calcScopeFromProp().or(calcScopeFromCommitMessages())) setStageCalc(calcStageFromProp()) setTagWriter { it.toString() } } @@ -80,5 +81,4 @@ include(":libs:material3-navigation") include(":libs:mifos-passcode") // Kotlin Multiplatform Modules -include(":shared") - +include(":shared") \ No newline at end of file