From 2e09c57857ed21d760d6bb86e849f2e07add944f Mon Sep 17 00:00:00 2001 From: Tigerpanzer_02 Date: Wed, 28 Dec 2022 14:02:28 +0100 Subject: [PATCH] Simplified getting of maven and gradle files, no need to define anymore Fixed gradle settings file --- README.md | 4 --- action.yml | 20 ----------- examples/gradle/deploy-development.yml | 3 +- examples/gradle/deploy-master.yml | 3 +- examples/maven/deploy.yml | 3 +- src/get-version.sh | 10 ++---- src/version-bump.sh | 46 +++++++++++--------------- 7 files changed, 25 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index fb9303f..cc7f097 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,6 @@ jobs: with: github-token: ${{ secrets.github_token }} git-committer: 'BOT' - repo-build: GRADLE auto-version-bump: true - name: Print Version run: "echo 'New Version: ${{steps.bump.outputs.version}}'" @@ -56,9 +55,6 @@ jobs: * `git-email`: The email address each commit should be associated with. Defaults to a github provided noreply address * `git-username`: The GitHub username each commit should be associated with. Defaults to `version-bump[github-action]` * `git-committer`: Who should be the committer? defined git [BOT] or last committer [USER] -* `pom-path`: The path within your directory the pom.xml you intended to change is located. -* `gradle-path`: The path within your directory the build.gradle you intended to change is located. -* `repo-build`: Using MAVEN or GRADLE to bump version * `auto-version-bump`: Should we bump the version on every commit? * `auto-version-bump-splitter`: Version splitter for auto bump * `auto-version-bump-suffix`: Version suffix for auto bump diff --git a/action.yml b/action.yml index 84b17c1..7150f52 100644 --- a/action.yml +++ b/action.yml @@ -12,18 +12,6 @@ inputs: github-token: description: 'A GitHub auth token to be able to create the pull request' required: true - repo-build: - description: 'Should it use MAVEN or GRADLE' - required: true - default: 'MAVEN' - pom-path: - description: 'The relative location of your pom.xml file' - required: true - default: '.' - gradle-path: - description: 'The relative location of your build.gradle file' - required: true - default: '.' git-email: description: 'The email address used to create the version bump commit with.' required: true @@ -78,8 +66,6 @@ runs: - name: Output before version id: get-before-version shell: bash - env: - POMPATH: ${{ inputs.pom-path }} run: echo "before-version=$(${{github.action_path}}/src/get-version.sh)" >> $GITHUB_OUTPUT - name: Bump Version @@ -90,9 +76,6 @@ runs: EMAIL: ${{ inputs.git-email }} NAME: ${{ inputs.git-username }} COMMITTER: ${{ inputs.git-committer }} - REPO_BUILD: ${{ inputs.repo-build }} - POMPATH: ${{ inputs.pom-path }} - GRADLEPATH: ${{ inputs.gradle-path }} AUTO: ${{ inputs.auto-version-bump }} AUTO_SPLITTER: ${{ inputs.auto-version-bump-splitter }} AUTO_SUFFIX: ${{ inputs.auto-version-bump-suffix }} @@ -105,9 +88,6 @@ runs: id: get-outputs shell: bash env: - REPO_BUILD: ${{ inputs.repo-build }} - POMPATH: ${{ inputs.pom-path }} - GRADLEPATH: ${{ inputs.gradle-path }} BEFORE_VERSION: ${{ steps.get-outputs.outputs.version }} run: | echo "version=$(${{github.action_path}}/src/get-version.sh)" >> $GITHUB_OUTPUT diff --git a/examples/gradle/deploy-development.yml b/examples/gradle/deploy-development.yml index 51c2434..5965ce9 100644 --- a/examples/gradle/deploy-development.yml +++ b/examples/gradle/deploy-development.yml @@ -14,10 +14,9 @@ jobs: run: chmod +x gradlew - name: Bump Version id: bump - uses: Plugily-Projects/version-bump-action@v7 + uses: Plugily-Projects/version-bump-action@v8 with: github-token: ${{ secrets.github_token }} - repo-build: GRADLE auto-version-bump: true git-committer: 'BOT' - name: Print Version diff --git a/examples/gradle/deploy-master.yml b/examples/gradle/deploy-master.yml index f9e83ae..f4ab530 100644 --- a/examples/gradle/deploy-master.yml +++ b/examples/gradle/deploy-master.yml @@ -16,10 +16,9 @@ jobs: run: chmod +x gradlew - name: Bump Version id: bump - uses: Plugily-Projects/version-bump-action@v7 + uses: Plugily-Projects/version-bump-action@v8 with: github-token: ${{ secrets.github_token }} - repo-build: GRADLE auto-version-bump: false auto-version-bump-release: true git-committer: 'BOT' diff --git a/examples/maven/deploy.yml b/examples/maven/deploy.yml index 7631a58..acd074d 100644 --- a/examples/maven/deploy.yml +++ b/examples/maven/deploy.yml @@ -12,10 +12,9 @@ jobs: - name: Bump Version id: bump - uses: Plugily-Projects/maven-version-bump-action@v7 + uses: Plugily-Projects/maven-version-bump-action@v8 with: github-token: ${{ secrets.github_token }} - repo-build: MAVEN auto-version-bump: true git-committer: 'BOT' - uses: actions/cache@v2 diff --git a/src/get-version.sh b/src/get-version.sh index 192bc43..63a95d2 100755 --- a/src/get-version.sh +++ b/src/get-version.sh @@ -1,11 +1,7 @@ #!/bin/sh -if [ "${REPO_BUILD}" = "MAVEN" ]; then - cd $POMPATH && mvn help:evaluate -Dexpression=project.version -q -DforceStdout +if [ -f ./pom.xml ] ; then + mvn help:evaluate -Dexpression=project.version -q -DforceStdout else - BUILD_FILE=$GRADLEPATH/build.gradle - if [ ! -f "$BUILD_FILE" ]; then - BUILD_FILE=$GRADLEPATH/build.gradle.kts - fi - "$GRADLEPATH"/gradlew properties --no-daemon --console=plain -q --build-file "$BUILD_FILE" | grep "^version:" | awk '{printf $2}' + ./gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{printf $2}' fi diff --git a/src/version-bump.sh b/src/version-bump.sh index 9c789c5..2eb6428 100755 --- a/src/version-bump.sh +++ b/src/version-bump.sh @@ -70,43 +70,35 @@ elif [[ "${AUTO}" == "true" ]]; then BUMP_MODE="auto" fi -if [ "${REPO_BUILD}" = "GRADLE" ]; then - BUILD_FILE=$GRADLEPATH/build.gradle - TYPE=GROOVY - if [ ! -f "$BUILD_FILE" ]; then - BUILD_FILE=$GRADLEPATH/build.gradle.kts - TYPE=KOTLIN +if [ -f ./pom.xml ]; then + REPO_SYSTEM=MAVEN + BUILD_FILE=./pom.xml +else + REPO_SYSTEM=GRADLE + if [ -f gradle.properties ] && grep -E -q "version=${CURRENT_VERSION}" gradle.properties; then + BUILD_FILE=./gradle.properties + elif [ -f ./build.gradle ]; then + BUILD_FILE=./build.gradle + elif [ -f ./build.gradle.kts ]; then + BUILD_FILE=./build.gradle.kts fi fi if [[ "${BUMP_MODE}" == "none" ]]; then - echo "No matching commit tags found." - if [ "${REPO_BUILD}" = "MAVEN" ]; then - echo "pom.xml at" $POMPATH "will remain at" $OLD_VERSION - else - echo "build.gradle at" $GRADLEPATH "will remain at" $OLD_VERSION - fi - + echo "No matching commit tags found. + Version will remain at" $OLD_VERSION else echo $BUMP_MODE "version bump detected" bump $BUMP_MODE $OLD_VERSION + echo "version will be bumped from" $OLD_VERSION "to" $NEW_VERSION REPO="https://$GITHUB_ACTOR:$TOKEN@github.com/$GITHUB_REPOSITORY.git" - if [ "${REPO_BUILD}" = "MAVEN" ]; then - echo "pom.xml at" $POMPATH "will be bumped from" $OLD_VERSION "to" $NEW_VERSION + if [ "${REPO_SYSTEM}" = "MAVEN" ]; then mvn -q versions:set -DnewVersion="${NEW_VERSION}" - git add $POMPATH/pom.xml - git commit -m "Bump pom.xml from $OLD_VERSION to $NEW_VERSION" - else - echo "build.gradle at " $GRADLEPATH " will be bumped from" $OLD_VERSION "to" $NEW_VERSION - if [ "${TYPE}" == "GROOVY" ]; then - sed -i "s/$OLD_VERSION/$NEW_VERSION/" $BUILD_FILE - elif [ "${TYPE}" == "KOTLIN" ]; then - sed -i "s/version = \"$OLD_VERSION\"/version = \"$NEW_VERSION\"/" $BUILD_FILE - fi - git add $BUILD_FILE - git commit -m "Bump build.gradle from $OLD_VERSION to $NEW_VERSION" + elif [ "${REPO_SYSTEM}" = "GRADLE" ]; then + sed -i "s/\(version *= *['\"]*\)${OLD_VERSION}\(['\"]*\)/\1${NEW_VERSION}\2/" ${BUILD_FILE} fi - + git add $BUILD_FILE + git commit -m "Bump version from $OLD_VERSION to $NEW_VERSION" if [[ "${BUMP_MODE}" == "auto" ]] && [[ "${AUTO_RELEASE}" == "false" ]]; then echo "Doing no new tag for this bump because its disabled for auto mode" git push $REPO