From 2501ecff054807257ed1f3f0fe05fe5d802c7473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Wed, 29 Jun 2022 22:35:53 +0200 Subject: [PATCH 01/18] New workflow frameworkPR for automatic submodule PR --- .github/workflows/frameworkPR.yml | 89 +++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 .github/workflows/frameworkPR.yml diff --git a/.github/workflows/frameworkPR.yml b/.github/workflows/frameworkPR.yml new file mode 100644 index 000000000..fa8203f1b --- /dev/null +++ b/.github/workflows/frameworkPR.yml @@ -0,0 +1,89 @@ +name: Check on submodules PR + +on: + pull_request: + branches: [ "master" ] + types: [ "opened", "reopened", "created", "closed", "synchronize"] + + workflow_dispatch: + +permissions: write-all + +env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + +defaults: + run: + shell: bash + +jobs: + framework-pr: + strategy: + matrix: + submodules: ["rest-for-physics/rawlib", "rest-for-physics/detectorlib", "rest-for-physics/geant4lib","rest-for-physics/tracklib", "rest-for-physics/connectorslib", "rest-for-physics/axionlib", "rest-for-physics/legacylib", "rest-for-physics/restG4"] + runs-on: ubuntu-latest + if: github.head_ref || github.ref_name != 'master' + steps: + - uses: actions/checkout@v3 + - name: Checkout submodules + uses: actions/checkout@v3 + with: + repository: ${{ matrix.submodules }} + path: submodule + - name: Check submodule branch + id: submoduleBranch + run: | + cd submodule + var=$(git ls-remote --heads origin ${{ env.BRANCH_NAME }}) + echo $var + if [[ -z $var ]]; then + echo "Branch "${{ env.BRANCH_NAME }}" not found in " ${{ matrix.submodules }} + echo "::set-output name=exist::false" + else + echo "HEAD=$(echo ${{ env.BRANCH_NAME }})" >> $GITHUB_ENV + git fetch + git checkout ${{ env.BRANCH_NAME }} + git pull + echo "::set-output name=exist::true" + fi + - name: Check PR + id: PRCheck + if: steps.submoduleBranch.outputs.exist == 'true' + run: | + cd submodule + #Check submodule PR + #gh config set git_protocol ssh --host github.com + gh auth status + gh pr status + gh pr view + prurl=$(gh pr view --json url -t '{{ .url }}') + echo "::set-output name=submoduleprurl::$prurl" + gh pr list + propen=$(gh pr list --head ${{ env.BRANCH_NAME }} --state open ) + prreview=$(gh pr list --head ${{ env.BRANCH_NAME }} --state open --search "review:required" ) + prapproved=$(gh pr list --head ${{ env.BRANCH_NAME }} --state open --search "review:approved" ) + prstatus=$(gh pr list --head ${{ env.BRANCH_NAME }} --state open --search "status" ) + echo "PR open " $propen " Review required " $prreview " Review approved " $prapproved " Status " $prstatus + if [[ -z $propen ]]; then + echo "No PR found or approved for branch " ${{ env.BRANCH_NAME }} " in submodule " ${{ matrix.submodules }} " merge is not allowed" + exit 1 + else + echo "::set-output name=mergeable::true" + fi + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + - name: Check output + run: | + echo "Mergeable " ${{ steps.PRCheck.outputs.mergeable }} + echo "Submodule PR url " ${{ steps.PRCheck.outputs.submoduleprurl }} + - name: Merge submodules + if: (github.event.action == 'closed' && github.event.pull_request.merged == true && steps.PRCheck.outputs.mergeable == 'true' && steps.submoduleBranch.outputs.exist == 'true') + run: | + cd submodule + #gh config set git_protocol ssh --host github.com + gh auth status + echo "actor " ${{ github.actor }} + gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{ steps.PRCheck.outputs.submoduleprurl }} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} From e60f3fa458ac72a0a184ef6689561c42676334bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Thu, 30 Jun 2022 13:32:00 +0200 Subject: [PATCH 02/18] Moving automerge action to a composite action so it can be used in submodules --- .github/actions/automerge/action.yml | 75 ++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/actions/automerge/action.yml diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml new file mode 100644 index 000000000..870869410 --- /dev/null +++ b/.github/actions/automerge/action.yml @@ -0,0 +1,75 @@ +name: "Automatic PR checks and merge" +description: "Checks if a particular branch and pull request exist in a repository" +inputs: + branch: + description: "Branch to checkout" + required: true + repository: + description: "Repository" + required: true + token: + description: "Authentification token" + required: true + +runs: + using: "composite" + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + repository: ${{ inputs.repository }} + path: repository + - name: Check repository branch + id: repositoryBranch + run: | + cd repository + var=$(git ls-remote --heads origin ${{ inputs.branch }}) + if [[ -z $var ]]; then + echo "Branch "${{ inputs.branch }}" not found in " ${{ inputs.repository }} + else + echo "Branch "${{ inputs.branch }}" found in " ${{ inputs.repository }} + echo "::set-output name=exist::true" + fi + shell: bash + - name: Check PR + id: PRCheck + if: steps.repositoryBranch.outputs.exist == 'true' + run: | + cd repository + #Check PR + gh auth status + gh pr status + gh pr view + prurl=$(gh pr view --json url -t '{{ .url }}') + echo "::set-output name=prurl::$prurl" + gh pr list + propen=$(gh pr list --head ${{ inputs.branch }} --state open ) + prreview=$(gh pr list --head ${{ inputs.branch }} --state open --search "review:required" ) + prapproved=$(gh pr list --head ${{ inputs.branch }} --state open --search "review:approved" ) + prstatus=$(gh pr list --head ${{ inputs.branch }} --state open --search "status" ) + echo "PR open " $propen " Review required " $prreview " Review approved " $prapproved " Status " $prstatus + if [[ -z $propen ]]; then + echo "No PR found or approved for branch " ${{ inputs.branch }} " in " ${{ inputs.repository }} " merge is not allowed" + exit 1 + else + echo "::set-output name=mergeable::true" + fi + env: + GITHUB_TOKEN: ${{ inputs.token }} + shell: bash + - name: Print outputs + run: | + echo "Mergeable " ${{ steps.PRCheck.outputs.mergeable }} + echo "PR url " ${{ steps.PRCheck.outputs.prurl }} + shell: bash + - name: Merge PR + if: (github.event.action == 'closed' && github.event.pull_request.merged == true && steps.PRCheck.outputs.mergeable == 'true' && steps.repositoryBranch.outputs.exist == 'true') + run: | + cd repository + gh auth status + echo "actor " ${{ github.actor }} + gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{ steps.PRCheck.outputs.prurl }} + GITHUB_TOKEN: ${{ inputs.token }} + shell: bash From f08522feb0689c2054d7f747a8441e2e3e9d8f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Thu, 30 Jun 2022 13:42:26 +0200 Subject: [PATCH 03/18] Using composite automerge action inside framework PR workflow --- .github/workflows/frameworkPR.yml | 64 ++----------------------------- 1 file changed, 4 insertions(+), 60 deletions(-) diff --git a/.github/workflows/frameworkPR.yml b/.github/workflows/frameworkPR.yml index fa8203f1b..dd29a5a21 100644 --- a/.github/workflows/frameworkPR.yml +++ b/.github/workflows/frameworkPR.yml @@ -26,64 +26,8 @@ jobs: steps: - uses: actions/checkout@v3 - name: Checkout submodules - uses: actions/checkout@v3 - with: + uses: ./.github/actions/automerge + with: + branch: ${{ env.BRANCH_NAME }} repository: ${{ matrix.submodules }} - path: submodule - - name: Check submodule branch - id: submoduleBranch - run: | - cd submodule - var=$(git ls-remote --heads origin ${{ env.BRANCH_NAME }}) - echo $var - if [[ -z $var ]]; then - echo "Branch "${{ env.BRANCH_NAME }}" not found in " ${{ matrix.submodules }} - echo "::set-output name=exist::false" - else - echo "HEAD=$(echo ${{ env.BRANCH_NAME }})" >> $GITHUB_ENV - git fetch - git checkout ${{ env.BRANCH_NAME }} - git pull - echo "::set-output name=exist::true" - fi - - name: Check PR - id: PRCheck - if: steps.submoduleBranch.outputs.exist == 'true' - run: | - cd submodule - #Check submodule PR - #gh config set git_protocol ssh --host github.com - gh auth status - gh pr status - gh pr view - prurl=$(gh pr view --json url -t '{{ .url }}') - echo "::set-output name=submoduleprurl::$prurl" - gh pr list - propen=$(gh pr list --head ${{ env.BRANCH_NAME }} --state open ) - prreview=$(gh pr list --head ${{ env.BRANCH_NAME }} --state open --search "review:required" ) - prapproved=$(gh pr list --head ${{ env.BRANCH_NAME }} --state open --search "review:approved" ) - prstatus=$(gh pr list --head ${{ env.BRANCH_NAME }} --state open --search "status" ) - echo "PR open " $propen " Review required " $prreview " Review approved " $prapproved " Status " $prstatus - if [[ -z $propen ]]; then - echo "No PR found or approved for branch " ${{ env.BRANCH_NAME }} " in submodule " ${{ matrix.submodules }} " merge is not allowed" - exit 1 - else - echo "::set-output name=mergeable::true" - fi - env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - - name: Check output - run: | - echo "Mergeable " ${{ steps.PRCheck.outputs.mergeable }} - echo "Submodule PR url " ${{ steps.PRCheck.outputs.submoduleprurl }} - - name: Merge submodules - if: (github.event.action == 'closed' && github.event.pull_request.merged == true && steps.PRCheck.outputs.mergeable == 'true' && steps.submoduleBranch.outputs.exist == 'true') - run: | - cd submodule - #gh config set git_protocol ssh --host github.com - gh auth status - echo "actor " ${{ github.actor }} - gh pr merge --auto --merge "$PR_URL" - env: - PR_URL: ${{ steps.PRCheck.outputs.submoduleprurl }} - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + token: ${{ secrets.GITHUB_TOKEN }} From 42e6750425ea58c33b9f67525ba1c655c42287c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Thu, 30 Jun 2022 14:08:22 +0200 Subject: [PATCH 04/18] Pulling branch after checkout for auto-merge --- .github/actions/automerge/action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index 870869410..9e47e29cc 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -26,8 +26,13 @@ runs: var=$(git ls-remote --heads origin ${{ inputs.branch }}) if [[ -z $var ]]; then echo "Branch "${{ inputs.branch }}" not found in " ${{ inputs.repository }} + echo "::set-output name=exist::false" else echo "Branch "${{ inputs.branch }}" found in " ${{ inputs.repository }} + git + git fetch + git checkout ${{ inputs.branch }} + git pull echo "::set-output name=exist::true" fi shell: bash From 80f3e1c8c2496b2adf50bf34fb120d600c6de63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Thu, 30 Jun 2022 14:09:34 +0200 Subject: [PATCH 05/18] Bug fix --- .github/actions/automerge/action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index 9e47e29cc..0cba2be13 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -29,7 +29,6 @@ runs: echo "::set-output name=exist::false" else echo "Branch "${{ inputs.branch }}" found in " ${{ inputs.repository }} - git git fetch git checkout ${{ inputs.branch }} git pull From dcb5910ca1e976b1c240982cbf0b52efb5a0239a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Thu, 30 Jun 2022 22:22:24 +0200 Subject: [PATCH 06/18] Update token --- .github/workflows/frameworkPR.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frameworkPR.yml b/.github/workflows/frameworkPR.yml index dd29a5a21..424732d35 100644 --- a/.github/workflows/frameworkPR.yml +++ b/.github/workflows/frameworkPR.yml @@ -30,4 +30,4 @@ jobs: with: branch: ${{ env.BRANCH_NAME }} repository: ${{ matrix.submodules }} - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.REST_TOKEN }} From f78f85b997d4631c260a4533b678845af38a5bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Thu, 30 Jun 2022 23:38:44 +0200 Subject: [PATCH 07/18] Check PR merge status instead of PR open --- .github/actions/automerge/action.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index 0cba2be13..307f2224d 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -46,14 +46,16 @@ runs: gh pr view prurl=$(gh pr view --json url -t '{{ .url }}') echo "::set-output name=prurl::$prurl" - gh pr list - propen=$(gh pr list --head ${{ inputs.branch }} --state open ) - prreview=$(gh pr list --head ${{ inputs.branch }} --state open --search "review:required" ) - prapproved=$(gh pr list --head ${{ inputs.branch }} --state open --search "review:approved" ) - prstatus=$(gh pr list --head ${{ inputs.branch }} --state open --search "status" ) - echo "PR open " $propen " Review required " $prreview " Review approved " $prapproved " Status " $prstatus - if [[ -z $propen ]]; then - echo "No PR found or approved for branch " ${{ inputs.branch }} " in " ${{ inputs.repository }} " merge is not allowed" + mergeStateStatus=$(gh pr view --json mergeStateStatus -t '{{ .mergeStateStatus }}') + echo "MergeStateStatus " $mergeStateStatus + #gh pr list + #propen=$(gh pr list --head ${{ inputs.branch }} --state open ) + #prreview=$(gh pr list --head ${{ inputs.branch }} --state open --search "review:required" ) + #prapproved=$(gh pr list --head ${{ inputs.branch }} --state open --search "review:approved" ) + #prstatus=$(gh pr list --head ${{ inputs.branch }} --state open --search "status" ) + #echo "PR open " $propen " Review required " $prreview " Review approved " $prapproved " Status " $prstatus + if [[ $mergeStateStatus == "CLEAN" ]]; then + echo "No valid PR found for branch " ${{ inputs.branch }} " in " ${{ inputs.repository }} " merge is not allowed" exit 1 else echo "::set-output name=mergeable::true" From 0fbe3e8c67d00af86f7e07b62faf559b53e1f9ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Thu, 30 Jun 2022 23:41:49 +0200 Subject: [PATCH 08/18] Bug fix --- .github/actions/automerge/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index 307f2224d..71e3ae539 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -55,10 +55,10 @@ runs: #prstatus=$(gh pr list --head ${{ inputs.branch }} --state open --search "status" ) #echo "PR open " $propen " Review required " $prreview " Review approved " $prapproved " Status " $prstatus if [[ $mergeStateStatus == "CLEAN" ]]; then + echo "::set-output name=mergeable::true" + else echo "No valid PR found for branch " ${{ inputs.branch }} " in " ${{ inputs.repository }} " merge is not allowed" exit 1 - else - echo "::set-output name=mergeable::true" fi env: GITHUB_TOKEN: ${{ inputs.token }} From 29ad1a2bd7df6690d2b77843a7f815278f2370f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Fri, 1 Jul 2022 10:11:11 +0200 Subject: [PATCH 09/18] Adding check if PR has been already merged, plus few improvements --- .github/actions/automerge/action.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index 71e3ae539..5cf3803f3 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -48,15 +48,8 @@ runs: echo "::set-output name=prurl::$prurl" mergeStateStatus=$(gh pr view --json mergeStateStatus -t '{{ .mergeStateStatus }}') echo "MergeStateStatus " $mergeStateStatus - #gh pr list - #propen=$(gh pr list --head ${{ inputs.branch }} --state open ) - #prreview=$(gh pr list --head ${{ inputs.branch }} --state open --search "review:required" ) - #prapproved=$(gh pr list --head ${{ inputs.branch }} --state open --search "review:approved" ) - #prstatus=$(gh pr list --head ${{ inputs.branch }} --state open --search "status" ) - #echo "PR open " $propen " Review required " $prreview " Review approved " $prapproved " Status " $prstatus - if [[ $mergeStateStatus == "CLEAN" ]]; then - echo "::set-output name=mergeable::true" - else + echo "::set-output name=mergeStateStatus::$mergeStateStatus" + if [[ $mergeStateStatus != "CLEAN" ]]; then echo "No valid PR found for branch " ${{ inputs.branch }} " in " ${{ inputs.repository }} " merge is not allowed" exit 1 fi @@ -64,17 +57,24 @@ runs: GITHUB_TOKEN: ${{ inputs.token }} shell: bash - name: Print outputs + if: steps.repositoryBranch.outputs.exist == 'true' run: | - echo "Mergeable " ${{ steps.PRCheck.outputs.mergeable }} + echo "Merge status " ${{ steps.PRCheck.outputs.mergeStateStatus }} echo "PR url " ${{ steps.PRCheck.outputs.prurl }} shell: bash - name: Merge PR - if: (github.event.action == 'closed' && github.event.pull_request.merged == true && steps.PRCheck.outputs.mergeable == 'true' && steps.repositoryBranch.outputs.exist == 'true') + if: (github.event.action == 'closed' && github.event.pull_request.merged == true && steps.PRCheck.outputs.mergeStateStatus == 'CLEAN' && steps.repositoryBranch.outputs.exist == 'true') run: | cd repository gh auth status echo "actor " ${{ github.actor }} - gh pr merge --auto --merge "$PR_URL" + prState=$(gh pr view --json pullRequestState -t '{{ .pullRequestState }}') + echo "PullRequestState " $prState + if [[ $prState == "MERGED" ]]; then + echo "PR already merged, doing nothing" + else + gh pr merge --auto --merge "$PR_URL" + fi env: PR_URL: ${{ steps.PRCheck.outputs.prurl }} GITHUB_TOKEN: ${{ inputs.token }} From 6e8f3e67f55197aee33cd09126a4c12686b86063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Fri, 1 Jul 2022 10:15:44 +0200 Subject: [PATCH 10/18] Adding check on PR state for debugging --- .github/actions/automerge/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index 5cf3803f3..dbfc71c2a 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -49,6 +49,8 @@ runs: mergeStateStatus=$(gh pr view --json mergeStateStatus -t '{{ .mergeStateStatus }}') echo "MergeStateStatus " $mergeStateStatus echo "::set-output name=mergeStateStatus::$mergeStateStatus" + prState=$(gh pr view --json pullRequestState -t '{{ .pullRequestState }}') + echo "PullRequestState " $prState if [[ $mergeStateStatus != "CLEAN" ]]; then echo "No valid PR found for branch " ${{ inputs.branch }} " in " ${{ inputs.repository }} " merge is not allowed" exit 1 From ce26d3f175ef7a99126743e9b445cba59d06ba7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Fri, 1 Jul 2022 10:20:54 +0200 Subject: [PATCH 11/18] Trying to fix retrieval of PR state --- .github/actions/automerge/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index dbfc71c2a..fbb1711c4 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -49,7 +49,7 @@ runs: mergeStateStatus=$(gh pr view --json mergeStateStatus -t '{{ .mergeStateStatus }}') echo "MergeStateStatus " $mergeStateStatus echo "::set-output name=mergeStateStatus::$mergeStateStatus" - prState=$(gh pr view --json pullRequestState -t '{{ .pullRequestState }}') + prState=$(gh pr status --json pullRequestState -t '{{ .pullRequestState }}') echo "PullRequestState " $prState if [[ $mergeStateStatus != "CLEAN" ]]; then echo "No valid PR found for branch " ${{ inputs.branch }} " in " ${{ inputs.repository }} " merge is not allowed" @@ -70,7 +70,7 @@ runs: cd repository gh auth status echo "actor " ${{ github.actor }} - prState=$(gh pr view --json pullRequestState -t '{{ .pullRequestState }}') + prState=$(gh pr status --json pullRequestState -t '{{ .pullRequestState }}') echo "PullRequestState " $prState if [[ $prState == "MERGED" ]]; then echo "PR already merged, doing nothing" From 87a45eae3c8c664383f05bc8b22bb823c58bba7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Fri, 1 Jul 2022 11:48:47 +0200 Subject: [PATCH 12/18] Addressing PR check when PR is already merged --- .github/actions/automerge/action.yml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index fbb1711c4..1e00506a1 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -49,9 +49,14 @@ runs: mergeStateStatus=$(gh pr view --json mergeStateStatus -t '{{ .mergeStateStatus }}') echo "MergeStateStatus " $mergeStateStatus echo "::set-output name=mergeStateStatus::$mergeStateStatus" - prState=$(gh pr status --json pullRequestState -t '{{ .pullRequestState }}') + prState=$($(gh pr status --json state -t '{{ .state }}')) + echo "::set-output name=prState::$prState" echo "PullRequestState " $prState - if [[ $mergeStateStatus != "CLEAN" ]]; then + if [[ $prState == "MERGED" ]]; then + echo "PR already merged" + elif [[ $mergeStateStatus == "CLEAN" ]]; then + echo "PR is in a clean state and can be merged" + else echo "No valid PR found for branch " ${{ inputs.branch }} " in " ${{ inputs.repository }} " merge is not allowed" exit 1 fi @@ -65,18 +70,12 @@ runs: echo "PR url " ${{ steps.PRCheck.outputs.prurl }} shell: bash - name: Merge PR - if: (github.event.action == 'closed' && github.event.pull_request.merged == true && steps.PRCheck.outputs.mergeStateStatus == 'CLEAN' && steps.repositoryBranch.outputs.exist == 'true') + if: (github.event.action == 'closed' && github.event.pull_request.merged == true && steps.PRCheck.outputs.mergeStateStatus == 'CLEAN' && steps.PRCheck.outputs.prState != 'MERGED') run: | cd repository gh auth status echo "actor " ${{ github.actor }} - prState=$(gh pr status --json pullRequestState -t '{{ .pullRequestState }}') - echo "PullRequestState " $prState - if [[ $prState == "MERGED" ]]; then - echo "PR already merged, doing nothing" - else - gh pr merge --auto --merge "$PR_URL" - fi + gh pr merge --auto --merge "$PR_URL" env: PR_URL: ${{ steps.PRCheck.outputs.prurl }} GITHUB_TOKEN: ${{ inputs.token }} From d8ae7494e7b0c1b7c698912486a5af63ad3efe55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Fri, 1 Jul 2022 11:50:06 +0200 Subject: [PATCH 13/18] Bug fix --- .github/actions/automerge/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index 1e00506a1..e132e5cee 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -54,7 +54,7 @@ runs: echo "PullRequestState " $prState if [[ $prState == "MERGED" ]]; then echo "PR already merged" - elif [[ $mergeStateStatus == "CLEAN" ]]; then + elif [[ $mergeStateStatus == "CLEAN" ]] echo "PR is in a clean state and can be merged" else echo "No valid PR found for branch " ${{ inputs.branch }} " in " ${{ inputs.repository }} " merge is not allowed" From 6704c0848d0b51aaba7090c3e87dae5e8f78a292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Fri, 1 Jul 2022 11:52:23 +0200 Subject: [PATCH 14/18] Another bug fix --- .github/actions/automerge/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index e132e5cee..5b76d0fcc 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -49,7 +49,7 @@ runs: mergeStateStatus=$(gh pr view --json mergeStateStatus -t '{{ .mergeStateStatus }}') echo "MergeStateStatus " $mergeStateStatus echo "::set-output name=mergeStateStatus::$mergeStateStatus" - prState=$($(gh pr status --json state -t '{{ .state }}')) + prState=$(gh pr status --json state -t '{{ .state }}') echo "::set-output name=prState::$prState" echo "PullRequestState " $prState if [[ $prState == "MERGED" ]]; then From f9b66819912719f84a69228d2e8f7d258c185c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Fri, 1 Jul 2022 12:04:53 +0200 Subject: [PATCH 15/18] Another bug fix in shell script --- .github/actions/automerge/action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index 5b76d0fcc..a51250a17 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -54,7 +54,7 @@ runs: echo "PullRequestState " $prState if [[ $prState == "MERGED" ]]; then echo "PR already merged" - elif [[ $mergeStateStatus == "CLEAN" ]] + elif [[ $mergeStateStatus == "CLEAN" ]]; then echo "PR is in a clean state and can be merged" else echo "No valid PR found for branch " ${{ inputs.branch }} " in " ${{ inputs.repository }} " merge is not allowed" @@ -68,6 +68,7 @@ runs: run: | echo "Merge status " ${{ steps.PRCheck.outputs.mergeStateStatus }} echo "PR url " ${{ steps.PRCheck.outputs.prurl }} + echo "PR state " ${{ steps.PRCheck.outputs.prState }} shell: bash - name: Merge PR if: (github.event.action == 'closed' && github.event.pull_request.merged == true && steps.PRCheck.outputs.mergeStateStatus == 'CLEAN' && steps.PRCheck.outputs.prState != 'MERGED') From 7b0f275dd5a15dca907d709409dd23c67f8b0de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Fri, 1 Jul 2022 13:40:46 +0200 Subject: [PATCH 16/18] Replacing merge status by review approved, to avoid blocking PR due to interdependencies --- .github/actions/automerge/action.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index a51250a17..79d62f278 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -52,10 +52,14 @@ runs: prState=$(gh pr status --json state -t '{{ .state }}') echo "::set-output name=prState::$prState" echo "PullRequestState " $prState + echo "::set-output name=mergeStateStatus::$mergeStateStatus" + review=$(gh pr status --json reviewDecision -t '{{ .reviewDecision }}') + echo "::set-output name=review::$review" + echo "Review decision " $review if [[ $prState == "MERGED" ]]; then echo "PR already merged" - elif [[ $mergeStateStatus == "CLEAN" ]]; then - echo "PR is in a clean state and can be merged" + elif [[ $review == "APPROVED" ]]; then + echo "PR is approved and mergeStateStatus is " $mergeStateStatus else echo "No valid PR found for branch " ${{ inputs.branch }} " in " ${{ inputs.repository }} " merge is not allowed" exit 1 @@ -67,11 +71,12 @@ runs: if: steps.repositoryBranch.outputs.exist == 'true' run: | echo "Merge status " ${{ steps.PRCheck.outputs.mergeStateStatus }} + echo "PR REVIEW " ${{ steps.PRCheck.outputs.review }} echo "PR url " ${{ steps.PRCheck.outputs.prurl }} echo "PR state " ${{ steps.PRCheck.outputs.prState }} shell: bash - name: Merge PR - if: (github.event.action == 'closed' && github.event.pull_request.merged == true && steps.PRCheck.outputs.mergeStateStatus == 'CLEAN' && steps.PRCheck.outputs.prState != 'MERGED') + if: (github.event.action == 'closed' && github.event.pull_request.merged == true && steps.PRCheck.outputs.review == 'APPROVED' && steps.PRCheck.outputs.prState != 'MERGED') run: | cd repository gh auth status From 3aa1970f86d60c9ae5c7df49764dba07509ed263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Fri, 1 Jul 2022 13:49:42 +0200 Subject: [PATCH 17/18] Replacing `gh pr status` by `gh pr view` --- .github/actions/automerge/action.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index 79d62f278..d48fc747c 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -42,18 +42,17 @@ runs: cd repository #Check PR gh auth status - gh pr status gh pr view prurl=$(gh pr view --json url -t '{{ .url }}') echo "::set-output name=prurl::$prurl" mergeStateStatus=$(gh pr view --json mergeStateStatus -t '{{ .mergeStateStatus }}') echo "MergeStateStatus " $mergeStateStatus echo "::set-output name=mergeStateStatus::$mergeStateStatus" - prState=$(gh pr status --json state -t '{{ .state }}') + prState=$(gh pr view --json state -t '{{ .state }}') echo "::set-output name=prState::$prState" echo "PullRequestState " $prState echo "::set-output name=mergeStateStatus::$mergeStateStatus" - review=$(gh pr status --json reviewDecision -t '{{ .reviewDecision }}') + review=$(gh pr view --json reviewDecision -t '{{ .reviewDecision }}') echo "::set-output name=review::$review" echo "Review decision " $review if [[ $prState == "MERGED" ]]; then From 449c2e15661a8b4915529536b54733c9c6f1fdde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Garc=C3=ADa?= <80903717+juanangp@users.noreply.github.com> Date: Tue, 15 Nov 2022 18:21:52 +0100 Subject: [PATCH 18/18] Removal of deprecated `set-output` command --- .github/actions/automerge/action.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/actions/automerge/action.yml b/.github/actions/automerge/action.yml index d48fc747c..46a51b992 100644 --- a/.github/actions/automerge/action.yml +++ b/.github/actions/automerge/action.yml @@ -26,13 +26,13 @@ runs: var=$(git ls-remote --heads origin ${{ inputs.branch }}) if [[ -z $var ]]; then echo "Branch "${{ inputs.branch }}" not found in " ${{ inputs.repository }} - echo "::set-output name=exist::false" + echo "exist=false" >> $GITHUB_OUTPUT else echo "Branch "${{ inputs.branch }}" found in " ${{ inputs.repository }} git fetch git checkout ${{ inputs.branch }} git pull - echo "::set-output name=exist::true" + echo "exist=true" >> $GITHUB_OUTPUT fi shell: bash - name: Check PR @@ -44,16 +44,15 @@ runs: gh auth status gh pr view prurl=$(gh pr view --json url -t '{{ .url }}') - echo "::set-output name=prurl::$prurl" + echo "prurl=$prurl" >> $GITHUB_OUTPUT mergeStateStatus=$(gh pr view --json mergeStateStatus -t '{{ .mergeStateStatus }}') echo "MergeStateStatus " $mergeStateStatus - echo "::set-output name=mergeStateStatus::$mergeStateStatus" + echo "mergeStateStatus=$mergeStateStatus" >> $GITHUB_OUTPUT prState=$(gh pr view --json state -t '{{ .state }}') - echo "::set-output name=prState::$prState" + echo "prState=$prState" >> $GITHUB_OUTPUT echo "PullRequestState " $prState - echo "::set-output name=mergeStateStatus::$mergeStateStatus" review=$(gh pr view --json reviewDecision -t '{{ .reviewDecision }}') - echo "::set-output name=review::$review" + echo "review=$review" >> $GITHUB_OUTPUT echo "Review decision " $review if [[ $prState == "MERGED" ]]; then echo "PR already merged"