Repository navigation
130 lines (118 loc) · 4.57 KB
/
Copy pathci.yml
File metadata and controls
130 lines (118 loc) · 4.57 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: CI
on:
pull_request:
push:
branches: [main]
# dispatched by auto-merge after a robot merge: GITHUB_TOKEN pushes do
# not fire `push` events (recursion guard), but workflow_dispatch does.
workflow_dispatch:
permissions:
contents: read
env:
# logins that skip the strict per-PR profile rules (maintainers with
# maintain/admin permission are skipped automatically, too)
PROFILE_BYPASS: hnrobert
jobs:
check-profiles:
name: Check profiles/
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- uses: actions/setup-python@v7
with:
python-version: "3.12"
- name: Collect the PR's changed files
if: github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api "repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" \
--paginate --jq '.[] | [.status, .filename] | @tsv' > pr-files.tsv
cat pr-files.tsv
# Strict rules (exactly one file, named after the PR author) apply
# only to PRs from docs/* (first-time add) or fix/* (update your
# own profile) branches, never to bypassed logins or maintain/admin
# collaborators.
- name: Decide whether the strict profile rules apply
id: scope
if: github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
run: |
branch="${{ github.event.pull_request.head.ref }}"
bypass=no
for user in $PROFILE_BYPASS; do
[ "$user" = "$PR_AUTHOR" ] && bypass=yes
done
if [ "$bypass" = no ]; then
perm=$(gh api "repos/${{ github.repository }}/collaborators/$PR_AUTHOR/permission" \
--jq .permission 2>/dev/null || echo none)
case "$perm" in maintain|admin) bypass=yes ;; esac
fi
strict=no; mode=""
if [ "$bypass" = no ]; then
case "$branch" in
docs/*) strict=yes; mode=added ;;
fix/*) strict=yes; mode=modified ;;
esac
fi
echo "strict=$strict" >> "$GITHUB_OUTPUT"
echo "mode=$mode" >> "$GITHUB_OUTPUT"
echo "branch=$branch author=$PR_AUTHOR bypass=$bypass strict=$strict mode=$mode"
- name: Run the profiles check
env:
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
run: |
if [ "${{ steps.scope.outputs.strict }}" = yes ] && [ -f pr-files.tsv ]; then
python scripts/check_profiles.py \
--author "${PR_AUTHOR}" \
--pr-files pr-files.tsv \
--expect "${{ steps.scope.outputs.mode }}"
else
python scripts/check_profiles.py
fi
publish-site:
name: Build and deploy the roster site
needs: check-profiles
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
actions: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.12"
- name: Generate the roster page
run: python scripts/build_site.py
# Re-runs keep artifacts from earlier attempts, and deploy-pages
# refuses when it finds more than one "github-pages" artifact in a
# run — so drop any leftovers before uploading a fresh one.
- name: Drop stale github-pages artifacts from this run
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api "repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts" \
--jq '.artifacts[] | select(.name == "github-pages") | .id' \
| while read -r id; do
echo "deleting stale artifact $id"
gh api -X DELETE "repos/${{ github.repository }}/actions/artifacts/$id"
done || true
# Deploy https://comppsyunion.github.io/github-playground/ straight
# from the workflow (Pages source: GitHub Actions). The freshly
# built docs/ directory is uploaded as the artifact — nothing is
# ever committed back to the repository.
- uses: actions/configure-pages@v6
- uses: actions/upload-pages-artifact@v5
with:
path: docs
- id: deployment
uses: actions/deploy-pages@v5