.github/workflows/pr-check.yml
216 lines · 7507 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
15jobs:
16 pr-compliance:
17 name: PR Compliance
18 runs-on: ubuntu-latest
19 steps:
20 - uses: actions/checkout@v5
21 with:
22 fetch-depth: 0
23 - name: Find merge base with ${{ github.event.pull_request.base.ref }}
24 id: mb
25 env:
26 BASE_SHA: ${{ github.event.pull_request.base.sha }}
27 BASE_REF: ${{ github.event.pull_request.base.ref }}
28 run: |
29 git fetch origin "$BASE_REF" || git fetch --depth=1 origin "$BASE_SHA" || true
30 MB=$(git merge-base FETCH_HEAD HEAD 2>/dev/null || echo "")
31 git cat-file -e "${MB}^{commit}" 2>/dev/null || MB=""
32 echo "sha=${MB:-$BASE_SHA}" >> "$GITHUB_OUTPUT"
33 - uses: actions/setup-python@v6
34 with:
35 python-version: "3.12"
36 - name: Check README edits
37 id: readme
38 continue-on-error: true
39 run: python lib/checks/check-readme-edits.py --base-ref ${{ steps.mb.outputs.sha }}
40 - name: Check PR metadata
41 id: meta
42 env:
43 PR_TITLE: ${{ github.event.pull_request.title }}
44 PR_BODY: ${{ github.event.pull_request.body }}
45 PR_DRAFT: ${{ github.event.pull_request.draft }}
46 BASE_REF: ${{ steps.mb.outputs.sha }}
47 README_FAILED: ${{ steps.readme.outcome == 'failure' && 'true' || 'false' }}
48 run: python lib/checks/check-pr-meta.py
49 - name: Upload findings
50 if: always()
51 uses: actions/upload-artifact@v6
52 with:
53 name: findings-compliance
54 path: /tmp/findings-compliance.json
55 if-no-files-found: ignore
56 - name: Fail if critical
57 if: steps.readme.outcome == 'failure' || steps.meta.outcome == 'failure'
58 run: exit 1
59
60 data-validation:
61 name: Data Validation
62 runs-on: ubuntu-latest
63 outputs:
64 yaml_changed: ${{ steps.changes.outputs.yaml_changed }}
65 steps:
66 - uses: actions/checkout@v5
67 with:
68 fetch-depth: 0
69 - name: Find merge base with ${{ github.event.pull_request.base.ref }}
70 id: mb
71 env:
72 BASE_SHA: ${{ github.event.pull_request.base.sha }}
73 BASE_REF: ${{ github.event.pull_request.base.ref }}
74 run: |
75 git fetch origin "$BASE_REF" || git fetch --depth=1 origin "$BASE_SHA" || true
76 MB=$(git merge-base FETCH_HEAD HEAD 2>/dev/null || echo "")
77 git cat-file -e "${MB}^{commit}" 2>/dev/null || MB=""
78 echo "sha=${MB:-$BASE_SHA}" >> "$GITHUB_OUTPUT"
79 - uses: actions/setup-python@v6
80 with:
81 python-version: "3.12"
82 - name: Detect changes
83 id: changes
84 run: python lib/checks/detect-changes.py --base-ref ${{ steps.mb.outputs.sha }}
85 - name: Install dependencies
86 if: steps.changes.outputs.yaml_changed == 'true'
87 run: pip install -q -r lib/requirements.txt
88 - name: Schema validation
89 if: steps.changes.outputs.yaml_changed == 'true'
90 id: schema
91 continue-on-error: true
92 run: make validate
93 - name: YAML diff
94 if: steps.changes.outputs.yaml_changed == 'true'
95 id: diff
96 continue-on-error: true
97 run: python lib/checks/check-yaml-diff.py --base-ref ${{ steps.mb.outputs.sha }}
98 - name: Check additions
99 if: steps.changes.outputs.yaml_changed == 'true'
100 id: additions
101 continue-on-error: true
102 env:
103 SCHEMA_OUTCOME: ${{ steps.schema.outcome }}
104 run: python lib/checks/check-additions.py
105 - name: Upload diff data
106 if: always()
107 uses: actions/upload-artifact@v6
108 with:
109 name: pr-diff
110 path: |
111 /tmp/pr-diff.json
112 /tmp/pr-diff-summary.md
113 if-no-files-found: ignore
114 - name: Upload findings
115 if: always()
116 uses: actions/upload-artifact@v6
117 with:
118 name: findings-data
119 path: /tmp/findings-data.json
120 if-no-files-found: ignore
121 - name: Fail if critical
122 if: steps.changes.outputs.yaml_changed == 'true' && (steps.schema.outcome == 'failure' || steps.diff.outcome == 'failure' || steps.additions.outcome == 'failure')
123 run: exit 1
124
125 submission-eligibility:
126 name: Submission Eligibility
127 needs: data-validation
128 if: "!cancelled() && needs.data-validation.outputs.yaml_changed == 'true'"
129 runs-on: ubuntu-latest
130 outputs:
131 has_repo_stats: ${{ steps.repo-stats.outputs.exists }}
132 steps:
133 - uses: actions/checkout@v5
134 - uses: actions/setup-python@v6
135 with:
136 python-version: "3.12"
137 - run: pip install -q -r lib/requirements.txt
138 - name: Download diff data
139 uses: actions/download-artifact@v7
140 with:
141 name: pr-diff
142 path: /tmp
143 continue-on-error: true
144 - name: Check project health
145 env:
146 PR_USER: ${{ github.event.pull_request.user.login }}
147 PR_BODY: ${{ github.event.pull_request.body }}
148 GITHUB_TOKEN: ${{ github.token }}
149 API_TOKEN: ${{ secrets.API_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/