.github/workflows/pr-check.yml
216 lines · 7485 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 FETCH_HEAD 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 FETCH_HEAD 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 API_TOKEN: ${{ secrets.API_TOKEN }}
156 run: python lib/checks/make-info-stats.py
157 - name: Check for repo stats
158 if: always()
159 id: repo-stats
160 run: test -f /tmp/repo-stats.md && echo "exists=true" >> "$GITHUB_OUTPUT" || echo "exists=false" >> "$GITHUB_OUTPUT"
161 - name: Upload repo stats
162 if: steps.repo-stats.outputs.exists == 'true'
163 uses: actions/upload-artifact@v6
164 with:
165 name: repo-stats
166 path: /tmp/repo-stats.md
167 - name: Upload findings
168 if: always()
169 uses: actions/upload-artifact@v6
170 with:
171 name: findings-project
172 path: /tmp/findings-project.json
173 if-no-files-found: ignore
174
175 summary:
176 name: Summary
177 if: always()
178 needs: [pr-compliance, data-validation, submission-eligibility]
179 runs-on: ubuntu-latest
180 steps:
181 - uses: actions/checkout@v5
182 - uses: actions/setup-python@v6
183 with:
184 python-version: "3.12"
185 - name: Download all findings
186 uses: actions/download-artifact@v7
187 with:
188 pattern: findings-*
189 path: /tmp/artifacts
190 merge-multiple: true
191 continue-on-error: true
192 - name: Download diff data
193 uses: actions/download-artifact@v7
194 with:
195 name: pr-diff
196 path: /tmp/artifacts
197 continue-on-error: true
198 - name: Download repo stats
199 if: needs.submission-eligibility.outputs.has_repo_stats == 'true'
200 uses: actions/download-artifact@v7
201 with:
202 name: repo-stats
203 path: /tmp/artifacts
204 continue-on-error: true
205 - name: Format comment
206 env:
207 PR_USER: ${{ github.event.pull_request.user.login }}
208 PR_NUMBER: ${{ github.event.pull_request.number }}
209 RUN_ID: ${{ github.run_id }}
210 run: python lib/checks/format-comment.py
211 - name: Upload PR metadata
212 if: always()
213 uses: actions/upload-artifact@v6
214 with:
215 name: pr-meta
216 path: /tmp/pr-meta/