OS-firs time #121
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |