diff --git a/.github/workflows/automerge.yaml b/.github/workflows/automerge.yaml index 1cac079..c088d25 100644 --- a/.github/workflows/automerge.yaml +++ b/.github/workflows/automerge.yaml @@ -11,17 +11,13 @@ 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.token }} diff --git a/.github/workflows/check-mergeability.yaml b/.github/workflows/check-mergeability.yaml index 3f97d12..665cea1 100644 --- a/.github/workflows/check-mergeability.yaml +++ b/.github/workflows/check-mergeability.yaml @@ -12,35 +12,28 @@ 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.token }}