From 5ae7c4305ffc1e69420345c635b1296f79b42f80 Mon Sep 17 00:00:00 2001 From: boholder Date: Sun, 19 May 2024 10:56:53 +0800 Subject: [PATCH 1/2] build: try to fix fast-forward workflow --- .github/workflows/fast_forward.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/fast_forward.yml b/.github/workflows/fast_forward.yml index 88611b18..c491defe 100644 --- a/.github/workflows/fast_forward.yml +++ b/.github/workflows/fast_forward.yml @@ -52,8 +52,8 @@ jobs: - name: Set environment variables run: | - MERGE_STATUS=${{ fromJson(steps.get-pr-details.outputs.data).mergeable_state }} - if [ "$MERGE_STATUS" != "clean" ]; then echo "COMMENT=[Fast Forward CI] ${{ env.HEAD_REF }} cannot be merged into ${{ env.BASE_REF }} at the moment." >> $GITHUB_ENV; fi + MERGE_STATUS=${{ fromJson(steps.get-pr-details.outputs.data).mergeable }} + if [ "$MERGE_STATUS" != "true" ]; then echo "COMMENT=[Fast Forward CI] ${{ env.HEAD_REF }} cannot be merged into ${{ env.BASE_REF }} at the moment." >> $GITHUB_ENV; fi echo "MERGE_STATUS=$MERGE_STATUS" >> $GITHUB_ENV echo "BASE_REF=${{ fromJson(steps.get-pr-details.outputs.data).base.ref }}" >> $GITHUB_ENV echo "HEAD_REF=${{ fromJson(steps.get-pr-details.outputs.data).head.ref }}" >> $GITHUB_ENV @@ -62,7 +62,7 @@ jobs: # Only runs if the merge status is "clean", clean might refer to when the merge button is green in the PR's page, there's no clear indication of it's values in docs # For forks the following script adds the fork as a remote, them merges it into base - name: Merge the head branch into base in a fast forward manner only - if: ${{ env.MERGE_STATUS == 'clean' }} + if: ${{ env.MERGE_STATUS == 'true' }} run: | git config --global user.email "action@github.com" git config --global user.name "GitHub Action" @@ -84,7 +84,7 @@ jobs: # Cuts the lines before "## Changelog" line in the PR's body using the "sed" command # Ref: https://stackoverflow.com/a/35966027 - name: Copy the changelogs from pr message to latest.md - if: ${{ env.MERGE_STATUS == 'clean' }} + if: ${{ env.MERGE_STATUS == 'true' }} run: | cd ./doc/changelogs echo "$ISSUE_BODY" > pr_msg.txt @@ -96,21 +96,21 @@ jobs: # Commit the changes if there was no error i.e., there was no issue in fetching the files and there was actually a changelog found/copied - name: Commit the changes (if any) - if: ${{ env.MERGE_STATUS == 'clean' }} + if: ${{ env.MERGE_STATUS == 'true' }} run: | if [[ "$( tail ./response.txt -n 1 )" = "No changes to write\!" ]] || [[ "$( tail ./response.txt -n 1 )" =~ "File \`(.*?)\` not found\!" ]]; then echo "COMMENT=${{ env.COMMENT }}\nNo changelogs found..." >> $GITHUB_ENV else git add doc/changelogs/latest.md git commit -m "chore(ff ci): add changelogs from #${{ github.event.issue.number }} to CHANGELOG.md" - echo "COMMENT=${{ env.COMMENT }}\nCopied the changelogs from pull request body to doc/CHANGELOG.md..." >> $GITHUB_ENV + echo "COMMENT=${{ env.COMMENT }} Copied the changelogs from pull request body to doc/CHANGELOG.md..." >> $GITHUB_ENV fi - name: Push to origin - if: ${{ env.MERGE_STATUS == 'clean' }} + if: ${{ env.MERGE_STATUS == 'true' }} run: | git push origin - echo "COMMENT=${{ env.COMMENT }}\nPushed the changes to origin." >> $GITHUB_ENV + echo "COMMENT=${{ env.COMMENT }} Pushed the changes to origin." >> $GITHUB_ENV # Post a success/failure comment to the PR. - name: Add success/failure comment to PR From 01041c462f2ea09843d4378ae3c6f395d066027c Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Sun, 19 May 2024 20:28:11 +0530 Subject: [PATCH 2/2] build: use MERGE_STATUS env var as a boolean --- .github/workflows/fast_forward.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/fast_forward.yml b/.github/workflows/fast_forward.yml index c491defe..53dd23dc 100644 --- a/.github/workflows/fast_forward.yml +++ b/.github/workflows/fast_forward.yml @@ -53,7 +53,7 @@ jobs: - name: Set environment variables run: | MERGE_STATUS=${{ fromJson(steps.get-pr-details.outputs.data).mergeable }} - if [ "$MERGE_STATUS" != "true" ]; then echo "COMMENT=[Fast Forward CI] ${{ env.HEAD_REF }} cannot be merged into ${{ env.BASE_REF }} at the moment." >> $GITHUB_ENV; fi + if $MERGE_STATUS; then echo "COMMENT=\[Fast Forward CI\] ${{ env.HEAD_REF }} cannot be merged into ${{ env.BASE_REF }} at the moment." >> $GITHUB_ENV; fi echo "MERGE_STATUS=$MERGE_STATUS" >> $GITHUB_ENV echo "BASE_REF=${{ fromJson(steps.get-pr-details.outputs.data).base.ref }}" >> $GITHUB_ENV echo "HEAD_REF=${{ fromJson(steps.get-pr-details.outputs.data).head.ref }}" >> $GITHUB_ENV @@ -62,7 +62,7 @@ jobs: # Only runs if the merge status is "clean", clean might refer to when the merge button is green in the PR's page, there's no clear indication of it's values in docs # For forks the following script adds the fork as a remote, them merges it into base - name: Merge the head branch into base in a fast forward manner only - if: ${{ env.MERGE_STATUS == 'true' }} + if: ${{ env.MERGE_STATUS }} run: | git config --global user.email "action@github.com" git config --global user.name "GitHub Action" @@ -84,7 +84,7 @@ jobs: # Cuts the lines before "## Changelog" line in the PR's body using the "sed" command # Ref: https://stackoverflow.com/a/35966027 - name: Copy the changelogs from pr message to latest.md - if: ${{ env.MERGE_STATUS == 'true' }} + if: ${{ env.MERGE_STATUS }} run: | cd ./doc/changelogs echo "$ISSUE_BODY" > pr_msg.txt @@ -96,7 +96,7 @@ jobs: # Commit the changes if there was no error i.e., there was no issue in fetching the files and there was actually a changelog found/copied - name: Commit the changes (if any) - if: ${{ env.MERGE_STATUS == 'true' }} + if: ${{ env.MERGE_STATUS }} run: | if [[ "$( tail ./response.txt -n 1 )" = "No changes to write\!" ]] || [[ "$( tail ./response.txt -n 1 )" =~ "File \`(.*?)\` not found\!" ]]; then echo "COMMENT=${{ env.COMMENT }}\nNo changelogs found..." >> $GITHUB_ENV @@ -107,7 +107,7 @@ jobs: fi - name: Push to origin - if: ${{ env.MERGE_STATUS == 'true' }} + if: ${{ env.MERGE_STATUS }} run: | git push origin echo "COMMENT=${{ env.COMMENT }} Pushed the changes to origin." >> $GITHUB_ENV @@ -133,4 +133,4 @@ jobs: issue_number: ${{ github.event.issue.number }} body: \[Fast Forward CI\] PR cannot be merged in. Check the Actions tab for details. env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}