From e9802819eb8de494c3f3daf32bed4d0bd3a9ae51 Mon Sep 17 00:00:00 2001 From: NikitaSkrynnik Date: Wed, 17 Apr 2024 12:23:33 +0700 Subject: [PATCH 1/3] Use GitHub CLI for automerge and check-mergeability workflows Signed-off-by: NikitaSkrynnik --- .github/workflows/automerge.yaml | 17 ++++----- .github/workflows/check-mergeability.yaml | 46 ++++++++++------------- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/.github/workflows/automerge.yaml b/.github/workflows/automerge.yaml index 1cac079..5ba37bf 100644 --- a/.github/workflows/automerge.yaml +++ b/.github/workflows/automerge.yaml @@ -11,17 +11,14 @@ jobs: steps: - name: Check out the code uses: actions/checkout@v4 - - name: Fetch main - run: | - git remote -v - git fetch --depth=1 origin main + - name: Check allowed files run: | find . -type f ! -name 'go.mod' ! -name 'go.sum' ! -name '*.yaml' ! -name '*.yml' ! -name '*.txt' ! -name '*.md' ! -name '*.conf' ! -name 'Dockerfile' -exec git diff --exit-code origin/main -- {} + + - name: Merge PR - uses: ridedott/merge-me-action@master - with: - GITHUB_LOGIN: nsmbot - ENABLED_FOR_MANUAL_CHANGES: true - GITHUB_TOKEN: ${{ secrets.token }} - MAXIMUM_RETRIES: 25 + run: | + gh pr merge ${{ github.event.workflow_run.head_branch }} --squash --delete-branch + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/.github/workflows/check-mergeability.yaml b/.github/workflows/check-mergeability.yaml index 3f97d12..0c2137b 100644 --- a/.github/workflows/check-mergeability.yaml +++ b/.github/workflows/check-mergeability.yaml @@ -12,35 +12,29 @@ jobs: check_mergeability: runs-on: ubuntu-latest outputs: - pr_branch_ref: ${{ steps.check_mergeability.outputs.pr_branch_ref }} + pr_branch_ref: ${{ steps.check_pr.outputs.pr_branch_ref }} steps: - - name: Find current PR - uses: jwalton/gh-find-current-pr@v1.0.2 - id: findPr - with: - sha: ${{ github.event.workflow_run.head_sha }} - github-token: ${{ secrets.token }} - - name: Validate PR number + - name: Check out the code + uses: actions/checkout@v4 + + - name: Check PR + id: check_pr run: | - if [ -z ${{ steps.findPr.outputs.pr }} ]; then - echo "No opened PR was found for SHA ${{ github.event.workflow_run.head_sha }}" + pr_info=$(gh pr list --head ${{ github.event.workflow_run.head_branch }} --json number,mergeable,headRefName) + pr_number=$(echo $pr_info | jq -r '.[0].number') + mergeable=$(echo $pr_info | jq -r '.[0].mergeable') + pr_branch_ref=$(echo $pr_info | jq -r '.[0].headRefName') + + if [ "$pr_number" == "null" ]; then + echo "No opened PR was found for branch ${{ github.event.workflow_run.head_branch }}" exit 1 fi - - name: Get PR Info - id: get_pull_request_info - uses: octokit/request-action@v2.x - with: - route: GET /repos/${{ github.repository }}/pulls/${{ steps.findPr.outputs.pr }} - env: - GITHUB_TOKEN: ${{ secrets.token }} - - name: Check mergeability - id: check_mergeability - run: | - echo "Mergeable: ${{ fromJson(steps.get_pull_request_info.outputs.data).mergeable }}" - PR_BRANCH_REF=${{ fromJson(steps.get_pull_request_info.outputs.data).head.ref }} - echo "PR_BRANCH_REF: $PR_BRANCH_REF" - echo "pr_branch_ref=$PR_BRANCH_REF" >> $GITHUB_OUTPUT - if [ "${{ fromJson(steps.get_pull_request_info.outputs.data).mergeable }}" != "true" ]; then - echo "PR has conflicts" + echo "pr_branch_ref=$pr_branch_ref" >> $GITHUB_OUTPUT + + if [ "$mergeable" != "MERGEABLE" ]; then + echo "PR $pr_number has conflicts" exit 1 fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + From 6bb008eb88d7ab62b4c99c1b36eab3f146bb1f28 Mon Sep 17 00:00:00 2001 From: NikitaSkrynnik Date: Wed, 17 Apr 2024 12:42:33 +0700 Subject: [PATCH 2/3] use tokens from input Signed-off-by: NikitaSkrynnik --- .github/workflows/automerge.yaml | 2 +- .github/workflows/check-mergeability.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/automerge.yaml b/.github/workflows/automerge.yaml index 5ba37bf..bc07fcf 100644 --- a/.github/workflows/automerge.yaml +++ b/.github/workflows/automerge.yaml @@ -20,5 +20,5 @@ jobs: run: | gh pr merge ${{ github.event.workflow_run.head_branch }} --squash --delete-branch env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.token }} diff --git a/.github/workflows/check-mergeability.yaml b/.github/workflows/check-mergeability.yaml index 0c2137b..b62e6a2 100644 --- a/.github/workflows/check-mergeability.yaml +++ b/.github/workflows/check-mergeability.yaml @@ -36,5 +36,5 @@ jobs: exit 1 fi env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.token }} From bbd8c875bfc137a14255ef5064691448b9f63d71 Mon Sep 17 00:00:00 2001 From: NikitaSkrynnik Date: Wed, 17 Apr 2024 12:46:13 +0700 Subject: [PATCH 3/3] fix yaml linter issues Signed-off-by: NikitaSkrynnik --- .github/workflows/automerge.yaml | 1 - .github/workflows/check-mergeability.yaml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/automerge.yaml b/.github/workflows/automerge.yaml index bc07fcf..c088d25 100644 --- a/.github/workflows/automerge.yaml +++ b/.github/workflows/automerge.yaml @@ -21,4 +21,3 @@ jobs: gh pr merge ${{ github.event.workflow_run.head_branch }} --squash --delete-branch env: GH_TOKEN: ${{ secrets.token }} - diff --git a/.github/workflows/check-mergeability.yaml b/.github/workflows/check-mergeability.yaml index b62e6a2..665cea1 100644 --- a/.github/workflows/check-mergeability.yaml +++ b/.github/workflows/check-mergeability.yaml @@ -37,4 +37,3 @@ jobs: fi env: GH_TOKEN: ${{ secrets.token }} -