-
Notifications
You must be signed in to change notification settings - Fork 6
67 lines (61 loc) · 2.13 KB
/
pull-request.yaml
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
61
62
63
64
65
66
67
name: Pull Request Validation
on:
pull_request:
workflow_dispatch:
inputs:
pr_number:
description: "The pull request number to validate"
required: true
type: string
jobs:
validate-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run pre-commit hooks (check only)
id: tests-step
run: |
python3 -m venv venv
source venv/bin/activate
pip install pre-commit
pre-commit install
pre-commit run --all-files
if ! git diff --exit-code; then
echo "Pre-commit hooks made changes, please commit them."
exit 1
fi
- name: Get SHA from PR number (manual runs only)
if: ${{ github.event_name == 'workflow_dispatch' }}
id: get-sha
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pr_number=${{ github.event.inputs.pr_number }}
echo "Fetching SHA for PR number: $pr_number"
sha=$(gh pr view $pr_number --json headRefOid -q '.headRefOid')
echo "SHA: $sha"
echo "sha=$sha" >> $GITHUB_OUTPUT
- name: Create Check with gh CLI (manual runs only)
if: ${{ github.event_name == 'workflow_dispatch' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pr_number=${{ github.event.inputs.pr_number }}
sha=${{ steps.get-sha.outputs.sha }}
outcome="failure"
if [[ ${{ steps.tests-step.outcome }} == "success" ]]; then
outcome="success"
fi
echo "Reporting $outcome for PR #$pr_number and SHA $sha"
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
repos/${{ github.repository }}/check-runs \
-f name='validate-pr' \
-f head_sha=$sha \
-f status='completed' \
-f conclusion=$outcome \
-f output[title]='Run PR Validation' \
-f output[summary]="PR Validated with result: $outcome"