Repository navigation
75 lines (70 loc) · 2.48 KB
/
Copy pathcontribution-data.yml
File metadata and controls
75 lines (70 loc) · 2.48 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
# Publishes merged pull request contributors to the orphan `website-data`
# branch. The docs site fetches the deterministic JSONL at runtime.
name: Publish website contribution data
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: write
pull-requests: read
concurrency:
group: website-contribution-data
cancel-in-progress: false
jobs:
publish:
if: github.repository == 'microsoft/scope'
runs-on: ubuntu-latest
timeout-minutes: 10
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
DATA_BRANCH: website-data
steps:
- name: Collect contributors
run: |
set -euo pipefail
gh api graphql --paginate \
-F owner="${REPO%/*}" \
-F name="${REPO#*/}" \
-f query='
query($owner: String!, $name: String!, $endCursor: String) {
repository(owner: $owner, name: $name) {
pullRequests(states: MERGED, first: 100, after: $endCursor) {
pageInfo { hasNextPage endCursor }
nodes { author { __typename login } }
}
}
}' \
--jq '.data.repository.pullRequests.nodes[]' |
jq -cS -s '
map(select(
.author != null
and .author.__typename == "User"
and (.author.login | endswith("[bot]") | not)
))
| group_by(.author.login)
| map({login: .[0].author.login, prs: length})
| sort_by(.login | ascii_downcase)
| .[]' > contributors.jsonl
- name: Publish website data
run: |
set -euo pipefail
git init -q data
cd data
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git remote add origin "https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git"
if git fetch -q --depth 1 origin "$DATA_BRANCH" 2>/dev/null; then
git checkout -q -B "$DATA_BRANCH" FETCH_HEAD
else
git checkout -q --orphan "$DATA_BRANCH"
fi
cp ../contributors.jsonl .
git add contributors.jsonl
if git diff --cached --quiet; then
echo 'No website data changes.'
exit 0
fi
git commit -q -m 'Update website contribution data'
git push -q origin "HEAD:$DATA_BRANCH"