Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GitHub CLI for automerge and check-mergeability workflows #72

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}