Skip to content

Commit 7b89d68

Browse files
committed
Add check for pull requests (GitHub action)
Signed-off-by: Stefan Weil <[email protected]>
1 parent 7851f8a commit 7b89d68

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

.github/workflows/pr_check.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Check pull requests.
2+
3+
name: Check pull request
4+
5+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
6+
on:
7+
# Trigger workflow on pull request.
8+
pull_request:
9+
# branches: [ ci ]
10+
11+
jobs:
12+
check_pull_request:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Fetching base and head commit (pull_request)
18+
# Source for this step: https://github.com/JensDll/should-run
19+
if: github.event_name == 'pull_request'
20+
run: |
21+
git fetch --no-tags --prune --no-recurse-submodules --depth=$((${{ github.event.pull_request.commits }} + 1)) origin ${{ github.event.pull_request.head.sha }}
22+
git fetch --no-tags --prune --no-recurse-submodules --depth=10 origin ${{ github.event.pull_request.base.sha }}
23+
git checkout --progress --force ${{ github.event.pull_request.head.sha }}
24+
25+
while [[ -n $(git rev-list shallow ^${{ github.event.pull_request.base.sha }}) ]]
26+
do
27+
git fetch --no-tags --prune --no-recurse-submodules --deepen=10 origin ${{ github.event.pull_request.base.sha }}
28+
done
29+
30+
base=$(git rev-list ${{ github.event.pull_request.head.sha }} ^${{ github.event.pull_request.base.sha }} | tail --lines 1 | xargs -I {} git rev-parse {}~1)
31+
32+
echo "BASE=$base" >> $GITHUB_ENV
33+
echo "HEAD=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
34+
- name: Check for whitespace issues.
35+
run: git log --check ${{ env.BASE }}...${{ env.HEAD }} | grep "^[^:+]*:[0-9]*:" && false || true
36+
# TODO: Add more checks here (codespell, ...).

0 commit comments

Comments
 (0)