.github/workflows/pr-check.yml
215 lines · 7441 bytes
1name: PR Check
2
3on:
4 pull_request:
5 branches: [main]
6 types: [opened, edited, synchronize, reopened]
7 paths:
8 - 'awesome-privacy.yml'
9 - '.github/README.md'
10
11permissions:
12 contents: read
13 pull-requests: read
14 security-events: read
15
16jobs:
17 pr-compliance:
18 name: PR Compliance
19 runs-on: ubuntu-latest
20 steps:
21 - uses: actions/checkout@v5
22 with:
23 fetch-depth: 0
24 - name: Find merge base with ${{ github.event.pull_request.base.ref }}
25 id: mb
26 env:
27 BASE_SHA: ${{ github.event.pull_request.base.sha }}
28 BASE_REF: ${{ github.event.pull_request.base.ref }}
29 run: |
30 git fetch origin "$BASE_REF" || git fetch --depth=1 origin "$BASE_SHA" || true
31 MB=$(git merge-base "$BASE_SHA" HEAD 2>/dev/null || echo "")
32 git cat-file -e "${MB}^{commit}" 2>/dev/null || MB=""
33 echo "sha=${MB:-$BASE_SHA}" >> "$GITHUB_OUTPUT"
34 - uses: actions/setup-python@v6
35 with:
36 python-version: "3.12"
37 - name: Check README edits
38 id: readme
39 continue-on-error: true
40 run: python lib/checks/check-readme-edits.py --base-ref ${{ steps.mb.outputs.sha }}
41 - name: Check PR metadata
42 id: meta
43 env:
44 PR_TITLE: ${{ github.event.pull_request.title }}
45 PR_BODY: ${{ github.event.pull_request.body }}
46 PR_DRAFT: ${{ github.event.pull_request.draft }}
47 BASE_REF: ${{ steps.mb.outputs.sha }}
48 README_FAILED: ${{ steps.readme.outcome == 'failure' && 'true' || 'false' }}
49 run: python lib/checks/check-pr-meta.py
50 - name: Upload findings
51 if: always()
52 uses: actions/upload-artifact@v6
53 with:
54 name: findings-compliance
55 path: /tmp/findings-compliance.json
56 if-no-files-found: ignore
57 - name: Fail if critical
58 if: steps.readme.outcome == 'failure' || steps.meta.outcome == 'failure'
59 run: exit 1
60
61 data-validation:
62 name: Data Validation
63 runs-on: ubuntu-latest
64 outputs:
65 yaml_changed: ${{ steps.changes.outputs.yaml_changed }}
66 steps:
67 - uses: actions/checkout@v5
68 with:
69 fetch-depth: 0
70 - name: Find merge base with ${{ github.event.pull_request.base.ref }}
71 id: mb
72 env:
73 BASE_SHA: ${{ github.event.pull_request.base.sha }}
74 BASE_REF: ${{ github.event.pull_request.base.ref }}
75 run: |
76 git fetch origin "$BASE_REF" || git fetch --depth=1 origin "$BASE_SHA" || true
77 MB=$(git merge-base "$BASE_SHA" HEAD 2>/dev/null || echo "")
78 git cat-file -e "${MB}^{commit}" 2>/dev/null || MB=""
79 echo "sha=${MB:-$BASE_SHA}" >> "$GITHUB_OUTPUT"
80 - uses: actions/setup-python@v6
81 with:
82 python-version: "3.12"
83 - name: Detect changes
84 id: changes
85 run: python lib/checks/detect-changes.py --base-ref ${{ steps.mb.outputs.sha }}
86 - name: Install dependencies
87 if: steps.changes.outputs.yaml_changed == 'true'
88 run: pip install -q -r lib/requirements.txt
89 - name: Schema validation
90 if: steps.changes.outputs.yaml_changed == 'true'
91 id: schema
92 continue-on-error: true
93 run: make validate
94 - name: YAML diff
95 if: steps.changes.outputs.yaml_changed == 'true'
96 id: diff
97 continue-on-error: true
98 run: python lib/checks/check-yaml-diff.py --base-ref ${{ steps.mb.outputs.sha }}
99 - name: Check additions
100 if: steps.changes.outputs.yaml_changed == 'true'
101 id: additions
102 continue-on-error: true
103 env:
104 SCHEMA_OUTCOME: ${{ steps.schema.outcome }}
105 run: python lib/checks/check-additions.py
106 - name: Upload diff data
107 if: always()
108 uses: actions/upload-artifact@v6
109 with:
110 name: pr-diff
111 path: |
112 /tmp/pr-diff.json
113 /tmp/pr-diff-summary.md
114 if-no-files-found: ignore
115 - name: Upload findings
116 if: always()
117 uses: actions/upload-artifact@v6
118 with:
119 name: findings-data
120 path: /tmp/findings-data.json
121 if-no-files-found: ignore
122 - name: Fail if critical
123 if: steps.changes.outputs.yaml_changed == 'true' && (steps.schema.outcome == 'failure' || steps.diff.outcome == 'failure' || steps.additions.outcome == 'failure')
124 run: exit 1
125
126 submission-eligibility:
127 name: Submission Eligibility
128 needs: data-validation
129 if: "!cancelled() && needs.data-validation.outputs.yaml_changed == 'true'"
130 runs-on: ubuntu-latest
131 outputs:
132 has_repo_stats: ${{ steps.repo-stats.outputs.exists }}
133 steps:
134 - uses: actions/checkout@v5
135 - uses: actions/setup-python@v6
136 with:
137 python-version: "3.12"
138 - run: pip install -q -r lib/requirements.txt
139 - name: Download diff data
140 uses: actions/download-artifact@v7
141 with:
142 name: pr-diff
143 path: /tmp
144 continue-on-error: true
145 - name: Check project health
146 env:
147 PR_USER: ${{ github.event.pull_request.user.login }}
148 PR_BODY: ${{ github.event.pull_request.body }}
149 GITHUB_TOKEN: ${{ github.token }}
150 run: python lib/checks/check-project.py
151 - name: Generate repo stats
152 continue-on-error: true
153 env:
154 GITHUB_TOKEN: ${{ github.token }}
155 run: python lib/checks/make-info-stats.py
156 - name: Check for repo stats
157 if: always()
158 id: repo-stats
159 run: test -f /tmp/repo-stats.md && echo "exists=true" >> "$GITHUB_OUTPUT" || echo "exists=false" >> "$GITHUB_OUTPUT"
160 - name: Upload repo stats
161 if: steps.repo-stats.outputs.exists == 'true'
162 uses: actions/upload-artifact@v6
163 with:
164 name: repo-stats
165 path: /tmp/repo-stats.md
166 - name: Upload findings
167 if: always()
168 uses: actions/upload-artifact@v6
169 with:
170 name: findings-project
171 path: /tmp/findings-project.json
172 if-no-files-found: ignore
173
174 summary:
175 name: Summary
176 if: always()
177 needs: [pr-compliance, data-validation, submission-eligibility]
178 runs-on: ubuntu-latest
179 steps:
180 - uses: actions/checkout@v5
181 - uses: actions/setup-python@v6
182 with:
183 python-version: "3.12"
184 - name: Download all findings
185 uses: actions/download-artifact@v7
186 with:
187 pattern: findings-*
188 path: /tmp/artifacts
189 merge-multiple: true
190 continue-on-error: true
191 - name: Download diff data
192 uses: actions/download-artifact@v7
193 with:
194 name: pr-diff
195 path: /tmp/artifacts
196 continue-on-error: true
197 - name: Download repo stats
198 if: needs.submission-eligibility.outputs.has_repo_stats == 'true'
199 uses: actions/download-artifact@v7
200 with:
201 name: repo-stats
202 path: /tmp/artifacts
203 continue-on-error: true
204 - name: Format comment
205 env:
206 PR_USER: ${{ github.event.pull_request.user.login }}
207 PR_NUMBER: ${{ github.event.pull_request.number }}
208 RUN_ID: ${{ github.run_id }}
209 run: python lib/checks/format-comment.py
210 - name: Upload PR metadata
211 if: always()
212 uses: actions/upload-artifact@v6
213 with:
214 name: pr-meta
215 path: /tmp/pr-meta/