Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add script and action for monthly PR summary #87

Draft
wants to merge 65 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
94d182d
add script and action for monthly PR summary
adomani Aug 2, 2024
3115cff
explicit repo
adomani Aug 2, 2024
e2eb004
print path
adomani Aug 2, 2024
715323e
plant info
adomani Aug 2, 2024
225abee
show file
adomani Aug 2, 2024
05dc150
sed -i
adomani Aug 2, 2024
1af9102
chmod
adomani Aug 2, 2024
ff1b5f0
show command
adomani Aug 2, 2024
d5a114b
show other message
adomani Aug 2, 2024
d350525
explicit
adomani Aug 2, 2024
9166c8b
rename variable message --> mim
adomani Aug 2, 2024
800110e
line too long?
adomani Aug 2, 2024
9aaade6
shorter message
adomani Aug 2, 2024
055aa14
show data
adomani Aug 2, 2024
ccc8d23
no data
adomani Aug 2, 2024
97ec482
shorter text, shallow clone
adomani Aug 2, 2024
4a47cfc
no man jq
adomani Aug 2, 2024
420eaef
echos
adomani Aug 2, 2024
b546c2a
mathlib
adomani Aug 2, 2024
b8458c6
use hello
adomani Aug 2, 2024
df75f77
here or there
adomani Aug 2, 2024
5665367
copy paste comment action
adomani Aug 2, 2024
fdac0ca
add permissions
adomani Aug 2, 2024
3fa061c
different permissions
adomani Aug 2, 2024
498d245
add actionlint
adomani Aug 2, 2024
0843cec
update versions
adomani Aug 2, 2024
ac8175c
mim1
adomani Aug 2, 2024
f18d295
unassign
adomani Aug 2, 2024
2ede396
lint?
adomani Aug 2, 2024
f6ea183
escape
adomani Aug 2, 2024
68edcc8
add token to script
adomani Aug 2, 2024
bfeec91
summary
adomani Aug 2, 2024
967f996
remove last step
adomani Aug 2, 2024
8b80dc4
more summary
adomani Aug 2, 2024
605059b
full output
adomani Aug 2, 2024
880a87c
fetch all
adomani Aug 2, 2024
6fa92da
slash
adomani Aug 2, 2024
1ee940e
PR all and cleanup
adomani Aug 2, 2024
b26d4ce
PRs really and comment unused variable
adomani Aug 2, 2024
e03e571
cancel one save and print
adomani Aug 2, 2024
dbc24ee
small cleanup
adomani Aug 2, 2024
cfa7686
use `mim`
adomani Aug 2, 2024
6c489a8
reduce number of inputs
adomani Aug 2, 2024
bc2584f
fix
adomani Aug 2, 2024
b40beea
print dates
adomani Aug 2, 2024
70a83ae
limit to 1000
adomani Aug 2, 2024
169330e
show dates
adomani Aug 2, 2024
4b1b6c2
smaller limit
adomani Aug 2, 2024
7e806b1
ticks
adomani Aug 2, 2024
f602146
reduce one input in internal function
adomani Aug 2, 2024
6673741
restore limit
adomani Aug 2, 2024
e453c37
improve docs, remove one comment
adomani Aug 2, 2024
0bf5e48
better report
adomani Aug 2, 2024
bf25e81
raw formatting
adomani Aug 2, 2024
359ec80
url?
adomani Aug 2, 2024
7f66830
embed title
adomani Aug 2, 2024
957c8fc
shorten and correct date
adomani Aug 2, 2024
44af846
raw output with flag
adomani Aug 2, 2024
6e562ba
simplify raw
adomani Aug 2, 2024
dec3600
print raw
adomani Aug 2, 2024
dc8c755
pipe conditionally
adomani Aug 2, 2024
d5afe92
semicolon
adomani Aug 2, 2024
ce1f2ef
spread out
adomani Aug 2, 2024
e19142b
gate
adomani Aug 2, 2024
91e3d1c
docs
adomani Aug 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/actionlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
self-hosted-runner:
labels:
- bors
- pr
20 changes: 20 additions & 0 deletions .github/workflows/actionlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Actionlint
on:
push:
branches:
- 'master'
paths:
- '.github/**'
pull_request:
paths:
- '.github/**'
merge_group:

jobs:
actionlint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: actionlint
uses: raven-actions/actionlint@v1
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ jobs:
name: Build HTML
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: install Python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.12

- name: install Python dependencies
run: python -m pip install -r requirements.txt

- name: build site
run: ./deploy.sh
run: ./deploy.sh
env:
git_hash: ${{ github.sha }}
DEPLOY_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/monthly_pr_report.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
on:
pull_request

name: Blog report

jobs:

Monthly_PRs:
if: github.event.pull_request.draft == false
name: Blog draft
runs-on: ubuntu-latest

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: cleanup
run: |
find . -name . -o -prune -exec rm -rf -- {} +

- uses: actions/checkout@v4
with:
path: blog

- uses: actions/checkout@v4
with:
repository: leanprover-community/mathlib4
fetch-depth: 0
ref: master
path: mathlib

- name: blog report
run: |
yrMth=2024-07
cd mathlib;
./../blog/monthly_summary.sh "${yrMth}" raw
./../blog/monthly_summary.sh "${yrMth}" > "${GITHUB_STEP_SUMMARY}"
139 changes: 139 additions & 0 deletions monthly_summary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash

: <<'BASH_DOC_MODULE'

Running `monthly_summary.sh 2024-07` produces an md-formatted summary of all the PRs that were
merged into mathlib master in the month 2024-07.
A "raw" format can be obtained running `monthly_summary.sh 2024-07 raw`.

There is a slight discrepancy between the time when a PR is merged and when it passes CI.
The script looks at the time when CI was successful on the PR, not at the time when the
successful CI cycle started.
However, in the final `Reports` section, the script mentions the PRs at either end:
* the ones that starts CI in the previous month and finished it in the current month;
* the ones that starts CI in the current month and finished it in the following month.

BASH_DOC_MODULE

repository='leanprover-community/mathlib4'
baseUrl="https://github.com/${repository}/pull/"

# the year and month being processed
yr_mth="${1}" #"$(date +%Y-%m)"
yr_mth_day=${yr_mth}-01

mth="$(date -d "${yr_mth_day}" '+%B')"
title="### ${mth} in Mathlib summary"

printf '%s\n\n' "${title}"

{
# Check if required argument is provided
if [ "$#" -gt 2 ]; then
printf $'Usages:\n%s <YYYY-MM>\n%s <YYYY-MM> raw\n\nFor instance `%s 2024-07`\n\nThe `raw` input skips .md formatting\n' "${0}" "${0}" "${0}"
exit 1
fi

rm -rf found_by_gh.txt found_by_git.txt

findInRange () {

# Get the start and end dates
startDate="${1}"
endDate="${2}"

# find how many commits to master there have been in the given range -- note that there is a limit to how many commits `gh` returns
commits_in_range="$(git log --since="${startDate}" --until="${endDate}" --pretty=oneline | wc -l)"

# Retrieve merged (i.e. closed, due to bors) PRs from the given range
prs=$(gh pr list --repo "$repository" --state closed --base master --search "closed:${startDate}..${endDate}" --json number,labels,title,author --limit "$((commits_in_range * 2))")

# Store to file `found_by_gh.txt` the PR numbers, as found by `gh`
echo "$prs" | jq -r '.[] | select(.title | startswith("[Merged by Bors]")) | "(#\(.number))"' | sort >> found_by_gh.txt

# Store to file `found_by_git.txt` the PR numbers, as found by looking at the commits to `master`
git log --pretty=oneline --since="${startDate}" --until="${endDate}" |
sed -n 's=.*\((#[0-9]*)\)$=\1=p' | sort >> found_by_git.txt

echo "$prs"
}

start_date="${yr_mth_day}T00:00:00"
end_date="$(date -d "${yr_mth_day} + 1 month - 1 day" +%Y-%m-%d)T23:59:59"

mth="$(date -d "${yr_mth_day}" '+%B')"
prev_mth="$(date -d "${yr_mth_day} - 1 day" '+%B')"
next_mth="$(date -d "${yr_mth_day} + 1 month" '+%B')"

commits_in_range="$(git log --since="${start_date}" --until="${end_date}" --pretty=oneline | wc -l)"

printf $'\n\nBetween %s and %s there were\n' "${yr_mth_day}" "${end_date/%T*}"

printf $'* %s commits to `master` and\n' "${commits_in_range}"

(
findInRange "${start_date}" "${yr_mth}-15T23:59:59" | sed -z 's=]\n*$=,\n='
findInRange "${yr_mth}-16T00:00:00" "${end_date}" | sed -z 's=^\[=='
) | jq -S -r '.[] |
select(.title | startswith("[Merged by Bors]")) |
"\(.labels | map(.name | select(startswith("t-"))) ) PR #\(.number) \(if .author.name == "" then .author.login else .author.name end): \(.title)"' |
sort |
awk 'BEGIN{ labels=""; con=0; total=0 }
{ total++
if(!($1 in seen)) { con++; order[con]=$1; seen[$1]=0 }
seen[$1]++
gsub(/\[Merged by Bors\] - /, "")
rest=$2; for(i=3; i<=NF; i++){rest=rest" "$i};acc[$1]=acc[$1]"\n"rest }
END {
printf("* %s closed PRs\n", total)
for(i=1; i<=con; i++) {
tag=order[i]
gsub(/\[\]/, "Miscellaneous", tag)
gsub(/["\][]/, "", tag)
gsub(/,/, " ", tag)
noPR=seen[order[i]]
printf("\n%s, %s PR%s%s\n", tag, noPR, noPR == "1" ? "" : "s", acc[order[i]])
}
}
'

only_gh="$( comm -23 <(sort found_by_gh.txt) <(sort found_by_git.txt) | sed 's=^=PR =' | tr -d '()')"
only_git="$(comm -13 <(sort found_by_gh.txt) <(sort found_by_git.txt) | sed 's=^=PR =' | tr -d '()')"

printf $'\n---\nReports\n\n'

if [ -z "${only_gh}" ]
then
printf $'* All PRs are accounted for!\n'
else
printf $'* PRs not corresponding to a commit (CI started in %s and ended in %s?)\n%s\n' "${prev_mth}" "${mth}" "${only_gh}"
fi

if [ -z "${only_git}" ]
then
printf $'\n* All commits are accounted for!\n'
else
printf $'\n* PRs not found by `gh` (CI started in %s and ended in %s?)\n%s\n' "${mth}" "${next_mth}" "${only_git}"
fi

printf -- $'---\n'

rm -rf found_by_gh.txt found_by_git.txt
} | {
if (( $2 == "raw" ))
then
cat -
else # extra .md formatting
sed '
/ [0-9]* PRs$/{
s=^=</details><details><summary>\n=
s=$=\n</summary>\n=
}
s=^PR #\([0-9]*\)=* PR [#\1]('"${baseUrl}"'\1)=' |
sed -z '
s=</details><details><summary>=<details><summary>=
s=\n---\nReports\n\n=\n</details>\n\n---\n\n<details><summary>Reports</summary>\n\n=
s=\n---[\n]*$=\n\n</details>\n&=
'
fi
}
Loading