Skip to content

Commit

Permalink
Merge pull request #72 from NikitaSkrynnik/automerge
Browse files Browse the repository at this point in the history
Use GitHub CLI for `automerge` and `check-mergeability` workflows
  • Loading branch information
denis-tingaikin authored Apr 17, 2024
2 parents 382f5e7 + bbd8c87 commit eef140a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 36 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/automerge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
45 changes: 19 additions & 26 deletions .github/workflows/check-mergeability.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

0 comments on commit eef140a

Please sign in to comment.