Skip to content

Commit 2490a81

Browse files
authored
add RAM/CPU PR comments w/ DCD tests for stats (#488)
1 parent 98bf0f4 commit 2490a81

File tree

6 files changed

+314
-0
lines changed

6 files changed

+314
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: PR Info (pre-comment)
2+
3+
on:
4+
# NOTE: high probability for security vulnerabilities if doing ANYTHING in
5+
# this file other than commenting something!
6+
pull_request_target:
7+
branches:
8+
- master
9+
10+
jobs:
11+
intro_comment:
12+
name: Make intro comment
13+
runs-on: ubuntu-20.04
14+
steps:
15+
- name: 'Prepare sticky comment'
16+
# commit of v2.5.0
17+
# same one used again at the bottom of the file to update the comment.
18+
uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd
19+
with:
20+
message: |
21+
Thanks for your Pull Request and making D better!
22+
23+
This comment will automatically be updated to summarize some statistics in a few minutes.
24+
only_create: true

.github/workflows/pr_info_post.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: PR Info (comment)
2+
3+
on:
4+
workflow_run:
5+
workflows: ["PR Info"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
comment:
11+
name: PR Info
12+
runs-on: ubuntu-20.04
13+
if: >
14+
github.event.workflow_run.event == 'pull_request' &&
15+
github.event.workflow_run.conclusion == 'success'
16+
steps:
17+
# from https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
18+
- name: 'Download artifact'
19+
uses: actions/[email protected]
20+
with:
21+
script: |
22+
var artifacts = await github.actions.listWorkflowRunArtifacts({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
run_id: ${{github.event.workflow_run.id }},
26+
});
27+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
28+
return artifact.name == "pr"
29+
})[0];
30+
var download = await github.actions.downloadArtifact({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
artifact_id: matchArtifact.id,
34+
archive_format: 'zip',
35+
});
36+
var fs = require('fs');
37+
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
38+
- run: unzip pr.zip
39+
40+
- name: Set variable
41+
run: |
42+
PR_ID=$(cat ./NR)
43+
echo "PR_ID=$PR_ID" >> $GITHUB_ENV
44+
45+
- name: Update GitHub comment
46+
uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd
47+
with:
48+
path: ./comment.txt
49+
number: ${{ env.PR_ID }}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: PR Info
2+
3+
# This workflow builds the whole project once and:
4+
# - comments build deprecations/warnings (highlighting new ones since last tested PR)
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
pr_info:
13+
name: PR Info
14+
runs-on: ubuntu-latest
15+
steps:
16+
# Compiler to test with
17+
- name: Prepare compiler
18+
uses: dlang-community/setup-dlang@v1
19+
with:
20+
compiler: dmd-latest
21+
22+
- name: Prepare compiler
23+
uses: dlang-community/setup-dlang@v1
24+
with:
25+
compiler: ldc-latest
26+
27+
- name: Checkout
28+
uses: actions/checkout@v3
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Checkout old stuff, with new comment script
33+
run: |
34+
git checkout ${{ github.base_ref }}
35+
git checkout ${{ github.sha }} -- ./ci/summary_comment.sh ./ci/summary_comment_diff.sh
36+
37+
# first dump old info
38+
39+
- name: Check pre-PR status
40+
run: ./ci/summary_comment.sh | tee ../OLD_OUTPUT.txt
41+
42+
- name: Checkout PR target
43+
run: |
44+
git checkout ${{ github.sha }}
45+
git clean -fd
46+
git reset --hard
47+
48+
- name: Evaluate PR
49+
run: ./ci/summary_comment.sh | tee ../NEW_OUTPUT.txt
50+
51+
- name: Generate comment
52+
run: ./ci/summary_comment_diff.sh ../OLD_OUTPUT.txt ../NEW_OUTPUT.txt | tee comment.txt
53+
54+
- name: Prepare comment for upload
55+
run: |
56+
mkdir -p ./pr
57+
mv comment.txt pr
58+
echo ${{ github.event.number }} > ./pr/NR
59+
60+
- name: upload comment to high-trust action making the comment
61+
uses: actions/upload-artifact@v2
62+
with:
63+
name: pr
64+
path: pr/

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,17 @@ test/tokens.txt
1212
test/unittests
1313
dub.selections.json
1414
*.lst
15+
16+
# Perf reports
17+
perf.data
18+
perf.data.old
19+
20+
# Valgrind reports
21+
callgrind.*
22+
massif.*
23+
24+
# D profiling tools
25+
profilegc.log
26+
27+
# GDB temp files
28+
.gdb_history

ci/summary_comment.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
set -u
4+
5+
# Output from this script is piped to a file by CI, being run from before a
6+
# change has been made and after a change has been made. Then both outputs are
7+
# compared using summary_comment_diff.sh
8+
9+
# cd to git folder, just in case this is manually run:
10+
ROOT_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd )"
11+
cd ${ROOT_DIR}
12+
13+
dub --version
14+
ldc2 --version
15+
16+
# fetch missing packages before timing
17+
dub upgrade --missing-only
18+
19+
start=`date +%s`
20+
dub build --build=release --force 2>&1 || echo "LIB BUILD FAILED"
21+
end=`date +%s`
22+
build_time=$( echo "$end - $start" | bc -l )
23+
24+
strip libdparse.a
25+
26+
echo "STAT:------ libdparse statistics ------"
27+
echo "STAT:"
28+
echo "STAT:statistics (-before, +after)"
29+
echo "STAT:library size=$(wc -c libdparse.a)"
30+
echo "STAT:rough build time=${build_time}s"
31+
echo "STAT:"
32+
33+
cleanup() {
34+
rm -rf "$ROOT_DIR/DCD"
35+
}
36+
trap cleanup EXIT
37+
38+
git clone https://github.com/dlang-community/DCD.git
39+
cd DCD
40+
echo "STAT:"
41+
echo "STAT:------ DCD statistics ------"
42+
echo "STAT:"
43+
44+
sed -E -i 's/"libdparse":\s*"[^"]+"/"libdparse": {"path":".."}/' dub.json
45+
cat dub.json
46+
sed -E -i 's/"libdparse":\s*"[^"]+"/"libdparse": {"path":".."}/' dub.selections.json
47+
cat dub.selections.json
48+
49+
./ci/summary_comment.sh 2>&1 | grep -E "^STAT:|DCD BUILD FAILED|unix:tc|\d+ tests passed and \d+ failed|No such file|[Ee]rror"

ci/summary_comment_diff.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env bash
2+
3+
set -u
4+
5+
EMPTY=1
6+
7+
ADDED=$(diff --new-line-format='%L' --old-line-format='' --unchanged-line-format='' "$1" "$2")
8+
REMOVED=$(diff --new-line-format='' --old-line-format='%L' --unchanged-line-format='' "$1" "$2")
9+
TOTAL=$(cat "$2")
10+
11+
STATS_OLD=$(grep -E '^STAT:' "$1" | sed -E 's/^STAT://')
12+
STATS_NEW=$(grep -E '^STAT:' "$2" | sed -E 's/^STAT://')
13+
14+
STATS_DIFFED=$(diff --new-line-format='+%L' --old-line-format='-%L' --unchanged-line-format=' %L' <(echo "$STATS_OLD") <(echo "$STATS_NEW"))
15+
16+
ADDED_DEPRECATIONS=$(grep -Pi '\b(deprecation|deprecated)\b' <<< "$ADDED")
17+
REMOVED_DEPRECATIONS=$(grep -Pi '\b(deprecation|deprecated)\b' <<< "$REMOVED")
18+
ADDED_WARNINGS=$(grep -Pi '\b(warn|warning)\b' <<< "$ADDED")
19+
REMOVED_WARNINGS=$(grep -Pi '\b(warn|warning)\b' <<< "$REMOVED")
20+
21+
DEPRECATION_COUNT=$(grep -Pi '\b(deprecation|deprecated)\b' <<< "$TOTAL" | wc -l)
22+
WARNING_COUNT=$(grep -Pi '\b(warn|warning)\b' <<< "$TOTAL" | wc -l)
23+
24+
if [ -z "$ADDED_DEPRECATIONS" ]; then
25+
# no new deprecations
26+
true
27+
else
28+
echo "⚠️ This PR introduces new deprecations:"
29+
echo
30+
echo '```'
31+
echo "$ADDED_DEPRECATIONS"
32+
echo '```'
33+
echo
34+
EMPTY=0
35+
fi
36+
37+
if [ -z "$ADDED_WARNINGS" ]; then
38+
# no new deprecations
39+
true
40+
else
41+
echo "⚠️ This PR introduces new warnings:"
42+
echo
43+
echo '```'
44+
echo "$ADDED_WARNINGS"
45+
echo '```'
46+
echo
47+
EMPTY=0
48+
fi
49+
50+
if grep "LIB BUILD FAILED" <<< "$TOTAL"; then
51+
echo '❌ Basic `dub build` failed! Please check your changes again.'
52+
echo
53+
elif grep "DCD BUILD FAILED" <<< "$TOTAL"; then
54+
echo '❌ `dub build` of DCD has failed with these changes! Please check your changes again.'
55+
echo
56+
else
57+
if [ -z "$REMOVED_DEPRECATIONS" ]; then
58+
# no removed deprecations
59+
true
60+
else
61+
echo "✅ This PR fixes following deprecations:"
62+
echo
63+
echo '```'
64+
echo "$REMOVED_DEPRECATIONS"
65+
echo '```'
66+
echo
67+
EMPTY=0
68+
fi
69+
70+
if [ -z "$REMOVED_WARNINGS" ]; then
71+
# no removed warnings
72+
true
73+
else
74+
echo "✅ This PR fixes following warnings:"
75+
echo
76+
echo '```'
77+
echo "$REMOVED_WARNINGS"
78+
echo '```'
79+
echo
80+
EMPTY=0
81+
fi
82+
83+
if [ $EMPTY == 1 ]; then
84+
echo "✅ PR OK, no changes in deprecations or warnings"
85+
echo
86+
fi
87+
88+
echo "Total deprecations: $DEPRECATION_COUNT"
89+
echo
90+
echo "Total warnings: $WARNING_COUNT"
91+
echo
92+
fi
93+
94+
if [ -z "$STATS_DIFFED" ]; then
95+
# no statistics?
96+
true
97+
else
98+
echo "Build statistics:"
99+
echo
100+
echo '```diff'
101+
echo "$STATS_DIFFED"
102+
echo '```'
103+
echo
104+
fi
105+
106+
echo '<details>'
107+
echo
108+
echo '<summary>Full build output</summary>'
109+
echo
110+
echo '```'
111+
echo "$TOTAL"
112+
echo '```'
113+
echo
114+
echo '</details>'

0 commit comments

Comments
 (0)