-
Notifications
You must be signed in to change notification settings - Fork 288
60 lines (53 loc) · 1.84 KB
/
check_people_md_pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: Check for a new markdown file in docs/people
on:
pull_request_target:
paths:
- 'docs/people/*.md'
jobs:
check-for-new-md:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
env:
Approve: true
ADDED_FILES_COUNT: ""
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 2
- name: Count Added Files
id: count-files
run: |
PR_FILES=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" | \
jq -r '.[].filename')
ADDED_FILES_COUNT=$(echo "$PR_FILES" | grep -c '^.*[^/]$')
echo "ADDED_FILES_COUNT=$ADDED_FILES_COUNT" >> $GITHUB_ENV
echo "$ADDED_FILES_COUNT new file(s) were added"
- name: Raise error if not exactly one file was added in the pr
if: env.ADDED_FILES_COUNT != '1'
run: |
echo "Error! Expected exactly 1 file to be added." >> $GITHUB_OUTPUT
echo "Approve=false" >> $GITHUB_ENV
exit 1
- id: automerge
name: automerge
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
// Attempt to merge the pull request using the squash method
const response = await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
merge_method: "merge"
})
} catch(error) {
// Set GitHub Action as failed
core.setFailed(error.message);
}