From faaf1e4c2b2760e8cd95afda8a49ca54ec94886d Mon Sep 17 00:00:00 2001 From: Xavier Molloy Date: Tue, 22 Oct 2024 17:08:54 +0200 Subject: [PATCH 1/2] feat: create release start GitHub action job and modify continuous-deployment job to generate snapshots on release branches --- .github/workflows/continuous-deployment.yml | 7 +- .github/workflows/release-start.yml | 87 +++++++++++++++++++ .../workflows/scripts/updateVersionName.py | 23 +++++ 3 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release-start.yml create mode 100644 .github/workflows/scripts/updateVersionName.py diff --git a/.github/workflows/continuous-deployment.yml b/.github/workflows/continuous-deployment.yml index 95f2bf789..1caadf4f6 100644 --- a/.github/workflows/continuous-deployment.yml +++ b/.github/workflows/continuous-deployment.yml @@ -7,7 +7,7 @@ on: push: branches: - develop # Automatically generates snapshot versions - + - release/* # Automatically generates release versions workflow_dispatch: ## manually generates release versions inputs: release_version: @@ -20,22 +20,19 @@ jobs: # The type of runner that the job will run on runs-on: ubuntu-latest - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 - name: Set Up JDK uses: actions/setup-java@v3 with: - distribution: 'zulu' # See 'Supported distributions' for available options + distribution: 'zulu' java-version: '17' cache: 'gradle' - name: Change wrapper permissions run: chmod +x ./gradlew - # Create publish to maven - name: Publish to maven run: ./.github/workflows/scripts/publish-maven.sh env: diff --git a/.github/workflows/release-start.yml b/.github/workflows/release-start.yml new file mode 100644 index 000000000..7e0124512 --- /dev/null +++ b/.github/workflows/release-start.yml @@ -0,0 +1,87 @@ +name: Release start + +# Controls when the action will run. Workflow runs when manually triggered using the UI +# or API. +on: + workflow_dispatch: + # Inputs the workflow accepts. + inputs: + release_version_name: + description: 'New release version name' + required: true + type: string + + development_version_name: + description: 'Development version name' + required: true + type: string + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + create_branch: + + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.12.1 + + - name: setup git config + run: | + # setup the username and email. + git config user.name "GitHub Actions Bot" + git config user.email "" + + # override version with new version + - name: Create release branch + run: git checkout -b release/${{ inputs.release_version_name }} + + - name: Run Python script to update release branch version + run: python scripts/updateVersionName.py ${{ inputs.release_version_name }} + + - name: Push + run: | + git add . + git commit -m "Update version to ${{ inputs.release_version_name }}" + git push origin release/${{ inputs.release_version_name }} + + update_version: + + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.12.1 + + - name: setup git config + run: | + # setup the username and email. + git config user.name "GitHub Actions Bot" + git config user.email "" + + - name: Create release branch + run: git checkout -b update_version_to${{ inputs.development_version_name }} + + - name: Run Python script to update base branch version + run: python scripts/updateVersionName.py ${{ inputs.development_version_name }} + + - name: Commit and Push Changes + run: | + git add . + git commit -m "Update version to ${{ inputs.development_version_name }}" + git push origin update_version_to${{ inputs.development_version_name }} + + - name: create pull request + run: gh pr create -B develop -H update_version_to${{ inputs.development_version_name }} --title 'Merge update_version_to${{ inputs.development_version_name }} into develop' --body 'Created by Github action' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/scripts/updateVersionName.py b/.github/workflows/scripts/updateVersionName.py new file mode 100644 index 000000000..53e7433c6 --- /dev/null +++ b/.github/workflows/scripts/updateVersionName.py @@ -0,0 +1,23 @@ +import sys + +import sys +import re + +def update_version_in_gradle(file_path, new_version): + with open(file_path, 'r') as file: + content = file.read() + + # Use regex to find and replace the version value + updated_content = re.sub(r'version\s*=\s*"[0-9.]+-SNAPSHOT"', f'version = "{new_version}"', content) + + with open(file_path, 'w') as file: + file.write(updated_content) + + print("File updated successfully!") + +if len(sys.argv) > 1: + new_version = sys.argv[1] + file_path = 'build.gradle.kts' + update_version_in_gradle(file_path, new_version) +else: + print("No new version provided. To update the version, pass the new version as a command-line argument.") \ No newline at end of file From c6ef3b03dc48958678e89c76a6d4fc33997882ce Mon Sep 17 00:00:00 2001 From: Xavier Molloy Date: Tue, 22 Oct 2024 17:15:18 +0200 Subject: [PATCH 2/2] feat: remove duplicated import --- .github/workflows/scripts/updateVersionName.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/scripts/updateVersionName.py b/.github/workflows/scripts/updateVersionName.py index 53e7433c6..0eed0531b 100644 --- a/.github/workflows/scripts/updateVersionName.py +++ b/.github/workflows/scripts/updateVersionName.py @@ -1,5 +1,3 @@ -import sys - import sys import re