From 550223c2d5bd25cee6b2175d55008a8debb661b5 Mon Sep 17 00:00:00 2001 From: iliyangermanov Date: Sat, 6 Jul 2024 23:23:33 +0300 Subject: [PATCH] Fix automatic_release.yml (Attempt 4) --- .github/workflows/automatic_release.yml | 19 +++++++++---- .github/workflows/create_release_tag.yml | 35 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/create_release_tag.yml diff --git a/.github/workflows/automatic_release.yml b/.github/workflows/automatic_release.yml index 5833149d9f..75b4ceed07 100644 --- a/.github/workflows/automatic_release.yml +++ b/.github/workflows/automatic_release.yml @@ -34,13 +34,20 @@ jobs: echo "NEW_VERSION_NAME=$CURRENT_DATE" >> $GITHUB_ENV echo "NEW_VERSION_CODE=$NEW_VERSION_CODE" >> $GITHUB_ENV - - name: Commit and push changes + - name: Create a new branch, commit and push changes run: | + NEW_BRANCH="auto-update-$(date +'%Y%m%d%H%M%S')" + git checkout -b $NEW_BRANCH git add gradle/libs.versions.toml git commit -m "Automatic release - v${{ env.NEW_VERSION_NAME }} (${{ env.NEW_VERSION_CODE }})" - git push + git push --set-upstream origin $NEW_BRANCH - - name: Create and push tag - run: | - git tag v${{ env.NEW_VERSION_NAME }}-${{ env.NEW_VERSION_CODE }} - git push origin v${{ env.NEW_VERSION_NAME }}-${{ env.NEW_VERSION_CODE }} \ No newline at end of file + - name: Create a Pull Request + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "Automatic release - v${{ env.NEW_VERSION_NAME }} (${{ env.NEW_VERSION_CODE }})" + branch: $NEW_BRANCH + title: "Automatic release - v${{ env.NEW_VERSION_NAME }} (${{ env.NEW_VERSION_CODE }})" + body: "This PR updates the version-name to v${{ env.NEW_VERSION_NAME }} and increments the version-code to ${{ env.NEW_VERSION_CODE }}." + labels: auto-update \ No newline at end of file diff --git a/.github/workflows/create_release_tag.yml b/.github/workflows/create_release_tag.yml new file mode 100644 index 0000000000..ccff827984 --- /dev/null +++ b/.github/workflows/create_release_tag.yml @@ -0,0 +1,35 @@ +name: Create Tag for Release + +on: + pull_request: + types: [closed] + +jobs: + create_tag: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'auto-update') + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history for all branches and tags + + - name: Set up Git + run: | + git config --global user.email "actions@github.com" + git config --global user.name "GitHub Actions" + + - name: Get version name and code from file + id: get_version + run: | + VERSION_NAME=$(grep 'version-name =' gradle/libs.versions.toml | awk -F'=' '{print $2}' | tr -d ' "') + VERSION_CODE=$(grep 'version-code =' gradle/libs.versions.toml | awk -F'=' '{print $2}' | tr -d ' "') + echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV + echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV + + - name: Create and push tag + run: | + TAG_NAME="v${{ env.VERSION_NAME }}-${{ env.VERSION_CODE }}" + git tag $TAG_NAME + git push origin $TAG_NAME \ No newline at end of file