diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..44b1e13 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,88 @@ +name: Automate Release Creation + +env: + WORKING_DIR: ./jvm-spring-web + +on: + workflow_dispatch: + inputs: + version_type: + description: 'Type of version bump (major/minor/patch)' + required: false + +jobs: + determine_next_version: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + with: + ref: main + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + - name: Determine Next Version + id: determine_version + run: | + # Use the provided version type input for the bump, default to 'patch' if not provided + VERSION_TYPE="${{ github.event.inputs.version_type || 'patch' }}" + + # Determine if a major version bump is needed (using a ceiling of 100 for minor version) + CURRENT_VERSION=$(./gradlew -q printVersion) + MINOR_VERSION=$(echo $CURRENT_VERSION | awk -F. '{print $2}') + if [[ "$MINOR_VERSION" -ge 100 ]]; then + VERSION_TYPE="major" + fi + + # Determine the next version + ./gradlew bumpVersion -Ptype=$VERSION_TYPE + NEW_VERSION=$(./gradlew -q printVersion) + echo "::set-output name=new_version::$NEW_VERSION" + working-directory: ${{ env.WORKING_DIR }} + + create_release_branch: + runs-on: ubuntu-latest + needs: determine_next_version + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + with: + ref: main + + - name: Create and Push Release Branch + run: | + RELEASE_BRANCH="release/v${{ needs.determine_next_version.outputs.new_version }}" + git checkout -b $RELEASE_BRANCH + git push origin $RELEASE_BRANCH + + build_and_release: + runs-on: ubuntu-latest + needs: create_release_branch + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + with: + ref: ${{ needs.create_release_branch.outputs.RELEASE_BRANCH }} + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ needs.determine_next_version.outputs.new_version }} + name: Release ${{ needs.determine_next_version.outputs.new_version }} + body: | + Automated release for version ${{ needs.determine_next_version.outputs.new_version }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/semVer_ci.yml b/.github/workflows/semVer_ci.yml new file mode 100644 index 0000000..01e190d --- /dev/null +++ b/.github/workflows/semVer_ci.yml @@ -0,0 +1,90 @@ +name: Semantic Versioning and Build + +env: + WORKING_DIR: ./jvm-spring-web + +on: + push: + branches: + - main + - feat/auto-release + - 'release/*' + pull_request: + branches: + - main + +jobs: + versioning: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + with: + working-directory: ${{ env.WORKING_DIR }} + + - name: Configure Git + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + working-directory: ${{ env.WORKING_DIR }} + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + working-directory: ${{ env.WORKING_DIR }} + + - name: Determine Next Version + id: determine_version + run: | + # Extracting version type (major/minor/patch) from commit message or PR title + VERSION_TYPE="patch" + if [[ "$GITHUB_REF" == refs/heads/release/* ]]; then + VERSION_TYPE="minor" + fi + + # Determine if a major version bump is needed (using a ceiling of 100 for minor version) + CURRENT_VERSION=$(./gradlew -q printVersion) + MINOR_VERSION=$(echo $CURRENT_VERSION | awk -F. '{print $2}') + if [[ "$MINOR_VERSION" -ge 100 ]]; then + VERSION_TYPE="major" + fi + + # Bumping version accordingly using a custom script or Gradle task + ./gradlew bumpVersion -Ptype=$VERSION_TYPE + NEW_VERSION=$(./gradlew -q printVersion) + echo "new_version=$NEW_VERSION" >> $GITHUB_ENV + working-directory: ${{ env.WORKING_DIR }} + + - name: Generate and Commit Summary of Changes + # Is this task, even necessary? + if: ${{ github.ref == 'refs/heads/feat/auto-release'}} + run: | + SUMMARY_FILE="change_summary.md" + git log -1 --pretty=format:"%h - %s (%an)" >> $SUMMARY_FILE + echo "Summary of changes updated in $SUMMARY_FILE" + cat $SUMMARY_FILE + git add $SUMMARY_FILE + git commit -m "Update change summary for version ${{ env.new_version }}" + git push origin HEAD + working-directory: ${{ env.WORKING_DIR }} + + - name: Commit Version Changes for Feature Branches + run: | + git add version.txt + git commit -m "Bump version to ${{ env.new_version }}" + git push origin HEAD + working-directory: ${{ env.WORKING_DIR }} + + - name: Create GitHub Release for Release Branches + if: ${{ github.ref == 'refs/heads/release/*'}} + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ env.new_version }} + name: Release ${{ env.new_version }} + body: | + $(cat change_summary.md) + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/jvm-spring-web/build.gradle b/jvm-spring-web/build.gradle index ff8f487..bfb22de 100644 --- a/jvm-spring-web/build.gradle +++ b/jvm-spring-web/build.gradle @@ -4,8 +4,12 @@ plugins { id 'java' } +apply from: 'versioning.gradle' + group = 'com.example' -version = '0.0.1-SNAPSHOT' +//version = '0.0.1-SNAPSHOT' +// Set the project version +version = readVersion() sourceCompatibility = '17' repositories { diff --git a/jvm-spring-web/change_summary.md b/jvm-spring-web/change_summary.md new file mode 100644 index 0000000..80ab06b --- /dev/null +++ b/jvm-spring-web/change_summary.md @@ -0,0 +1 @@ +fa849ef - use release action and commit changes (Madhu Chavva)a6714cd - add release workflow (Madhu Chavva)733cecc - read latest version for commit (Madhu Chavva)bdc9264 - fix set_output warning (Madhu Chavva)5c2120a - use minor version ceiling (Madhu Chavva) \ No newline at end of file diff --git a/jvm-spring-web/src/main/java/com/example/demo/services/AcmeDonutsFeatureService.java b/jvm-spring-web/src/main/java/com/example/demo/services/AcmeDonutsFeatureService.java index e13b0e7..d9b0a66 100644 --- a/jvm-spring-web/src/main/java/com/example/demo/services/AcmeDonutsFeatureService.java +++ b/jvm-spring-web/src/main/java/com/example/demo/services/AcmeDonutsFeatureService.java @@ -35,7 +35,7 @@ public void onRefresh(String featuresJson) { } void handleError(FeatureFetchException e) { - e.printStackTrace(); + //e.printStackTrace(); switch (e.getErrorCode()) { case NO_RESPONSE_ERROR -> { @@ -46,9 +46,7 @@ void handleError(FeatureFetchException e) { // SSE is not applicable for this service but this was added here for completion. } - case CONFIGURATION_ERROR, UNKNOWN -> { - throw new RuntimeException(e); - } + case CONFIGURATION_ERROR, UNKNOWN -> throw new RuntimeException(e); } } } diff --git a/jvm-spring-web/version.txt b/jvm-spring-web/version.txt new file mode 100644 index 0000000..99d85ec --- /dev/null +++ b/jvm-spring-web/version.txt @@ -0,0 +1 @@ +0.0.6 \ No newline at end of file diff --git a/jvm-spring-web/versioning.gradle b/jvm-spring-web/versioning.gradle new file mode 100644 index 0000000..ac196f6 --- /dev/null +++ b/jvm-spring-web/versioning.gradle @@ -0,0 +1,52 @@ +// versioning.gradle + +// Function to read version from file +ext.readVersion = { + def versionFile = file('version.txt') + if (versionFile.exists()) { + return versionFile.text.trim() + } else { + return '0.1.0' // Default version if file does not exist + } +} + +// Function to write version to file +def writeVersion(newVersion) { + def versionFile = file('version.txt') + versionFile.text = newVersion +} + +version = readVersion() + +// Task to print the current version +task printVersion { + doLast { + println version + } +} + +// Task to bump the version +task bumpVersion { + doLast { + def currentVersion = version.split('\\.') + def versionType = project.hasProperty('type') ? project.property('type') : 'patch' + + if (versionType == 'major') { + currentVersion[0] = (currentVersion[0].toInteger() + 1).toString() + currentVersion[1] = '0' + currentVersion[2] = '0' + } else if (versionType == 'minor') { + currentVersion[1] = (currentVersion[1].toInteger() + 1).toString() + currentVersion[2] = '0' + } else if (versionType == 'patch') { + currentVersion[2] = (currentVersion[2].toInteger() + 1).toString() + } else { + throw new GradleException("Unknown version type: $versionType. Use 'major', 'minor', or 'patch'.") + } + + def newVersion = currentVersion.join('.') + writeVersion(newVersion) + println "Version bumped to $newVersion from $version" + } +} +