Skip to content

Commit

Permalink
ci: improve PR comments to include before value and avoid spamming re…
Browse files Browse the repository at this point in the history
…peat comments
  • Loading branch information
Michad committed Nov 29, 2024
1 parent ba73dcb commit cfa1941
Showing 1 changed file with 82 additions and 10 deletions.
92 changes: 82 additions & 10 deletions .github/workflows/metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,56 @@ jobs:
id: test
run: |
make clean cover
tail -1 coveragef.out | sed -E "s/[^0-9]*([0-9]+\.[0-9]*)%/VAL=\1/" >> $GITHUB_OUTPUT
VAL=$(tail -1 coveragef.out | sed -E "s/[^0-9]*([0-9]+\.[0-9]*)%/\1/")
OLD_VAL=$(curl "https://gist.githubusercontent.com/michad/d1b9e082f6608635494188d0f52bae69/raw/coverage.json" | jq '.message | rtrimstr("%") | tonumber')
MSG="Code coverage"
if [ "$VAL" -eq "$OLD_VAL" ]; then
MSG="$MSG is unchanged at $VAL%"
elif [ "$VAL" -lt "$OLD_VAL"]; then
MSG="$MSG decreased from $OLD_VAL% to $VAL%"
else
MSG="$MSG increased from $OLD_VAL% to $VAL%"
fi
echo "VAL=$VAL" >> $GITHUB_OUTPUT
echo "MSG=$MSG" >> $GITHUB_OUTPUT
- name: Comment on PR
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: github.event_name == 'pull_request'
env:
VAL: ${{ steps.test.outputs.VAL }}
MSG: ${{ steps.test.outputs.MSG }}
with:
script: |
github.rest.issues.createComment({
let comments = github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Code coverage is ' + process.env.VAL + '%'
})
});
let id = null;
for(let i in comments) {
if(comments[i].user?.login == 'github-actions' && comments[i].body.startsWith("Code coverage ")){
id=comments[i].id;
break;
}
}
if(id !== null){
github.rest.issues.updateComment({
comment_id: id,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.MSG
});
console.log("update comment " + id);
} else{
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.MSG
});
}
- name: Create the Badge
uses: schneegans/dynamic-badges-action@e9a478b16159b4d31420099ba146cdc50f134483 # v1.7.0
if: github.event_name != 'pull_request'
Expand Down Expand Up @@ -72,20 +108,56 @@ jobs:
- name: Run Test
id: test
run: |
make libyears | /usr/bin/jq '.libyear | .*100 | round/100' | xargs -I{} echo VAL={} >> $GITHUB_OUTPUT
VAL=$(make libyears | /usr/bin/jq '.libyear | .*100 | round/100')
tail -1 coveragef.out | sed -E "s/[^0-9]*([0-9]+\.[0-9]*)%/VAL=\1/" >> $GITHUB_OUTPUT
OLD_VAL=$(curl "https://gist.githubusercontent.com/michad/d1b9e082f6608635494188d0f52bae69/raw/libyears.json" | jq '.message | rtrimstr(" years") | tonumber')
MSG="Libyears"
if [ "$VAL" -eq "$OLD_VAL" ]; then
MSG="$MSG is unchanged at $VAL"
elif [ "$VAL" -lt "$OLD_VAL"]; then
MSG="$MSG decreased from $OLD_VAL to $VAL"
else
MSG="$MSG increased from $OLD_VAL to $VAL"
fi
echo "VAL=$VAL" >> $GITHUB_OUTPUT
echo "MSG=$MSG" >> $GITHUB_OUTPUT
- name: Comment on PR
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: github.event_name == 'pull_request'
env:
VAL: ${{ steps.test.outputs.VAL }}
MSG: ${{ steps.test.outputs.MSG }}
with:
script: |
github.rest.issues.createComment({
let comments = github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Libyears is ' + process.env.VAL
})
});
let id = null;
for(let i in comments) {
if(comments[i].user?.login == 'github-actions' && comments[i].body.startsWith("Libyears ")){
id=comments[i].id;
break;
}
}
if(id !== null){
github.rest.issues.updateComment({
comment_id: id,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.MSG
});
} else{
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.MSG
})
}
- name: Create the Badge
uses: schneegans/dynamic-badges-action@e9a478b16159b4d31420099ba146cdc50f134483 # v1.7.0
if: github.event_name != 'pull_request'
Expand Down

0 comments on commit cfa1941

Please sign in to comment.