Skip to content

Commit 2af5d44

Browse files
committed
DEVOPS-3833] ci: add approve workflow
1 parent 6970331 commit 2af5d44

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

.github/workflows/approve-pr.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Approve PR
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
pr_number:
7+
description: PR number
8+
required: true
9+
10+
jobs:
11+
approve_pr:
12+
environment: pull-request
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Get actors info
20+
id: actor_info
21+
run: |
22+
PR_AUTHOR=$(gh pr view ${{ inputs.pr_number }} --repo flathub/com.devolutions.remotedesktopmanager --json author -q '.author.login')
23+
24+
APPROVER=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
25+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/approvals")
26+
APPROVER_LOGIN=$(echo $APPROVER | jq -r '.[0].user.login')
27+
28+
echo "approver=$APPROVER_LOGIN" >> $GITHUB_OUTPUT
29+
echo "author=$PR_AUTHOR" >> $GITHUB_OUTPUT
30+
env:
31+
GH_TOKEN: ${{ secrets.DEVOLUTIONSBOT_WRITE_TOKEN }}
32+
33+
- name: Validate Approver
34+
run: |
35+
if [ "${{ steps.actor_info.outputs.author }}" == "${{ steps.actor_info.outputs.approver }}" ]; then
36+
echo "::error:: You can't approve your own PR"
37+
exit 1
38+
fi
39+
40+
- name: Merge pull request
41+
run: |
42+
echo "Waiting for checks to start..."
43+
sleep 120
44+
echo "Checking if checks have started..."
45+
gh pr checks ${{ inputs.pr_number }} --repo flathub/com.devolutions.remotedesktopmanager --watch --fail-fast
46+
gh pr merge ${{ inputs.pr_number }} --repo flathub/com.devolutions.remotedesktopmanager --squash --delete-branch --admin
47+
env:
48+
GH_TOKEN: ${{ secrets.DEVOLUTIONSBOT_WRITE_TOKEN }}

0 commit comments

Comments
 (0)