-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from StaticRocket/master
Add the first PR checker
- Loading branch information
Showing
3 changed files
with
227 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
name: "rstcheck" | ||
|
||
on: | ||
pull_request: | ||
branches: [master] | ||
paths: | ||
- source | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
container: | ||
image: ghcr.io/texasinstruments/processor-sdk-doc:latest | ||
options: --entrypoint /bin/bash | ||
permissions: | ||
contents: read | ||
issues: write | ||
pull-requests: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Update refs and settings | ||
run: | | ||
git config --global --add safe.directory "$PWD" | ||
git switch -C pr | ||
git fetch --no-tags --depth=1 origin master | ||
git switch master | ||
- name: Run rstcheck | ||
id: rstcheck | ||
run: | | ||
bin/delta.sh -a master -b pr \ | ||
-- rstcheck -r source/ | ||
if [ "$(wc -l < _new-warn.log)" -gt "0" ]; then | ||
{ | ||
echo "New warnings found with rstcheck:"; | ||
echo '```text'; | ||
cat _new-warn.log; | ||
echo '```'; | ||
} >> "$GITHUB_STEP_SUMMARY" | ||
{ | ||
echo 'NEW_WARNINGS<<EOF' | ||
echo "$(< "$GITHUB_STEP_SUMMARY")" | ||
echo 'EOF' | ||
} >> "$GITHUB_OUTPUT" | ||
exit 1 | ||
fi | ||
echo "No new warnings found with rstcheck" >> "$GITHUB_STEP_SUMMARY" | ||
- name: Update pr with info | ||
uses: actions/github-script@v7 | ||
if: ${{ failure() && steps.rstcheck.outputs.NEW_WARNINGS != '' }} | ||
env: | ||
NEW_WARNINGS: ${{ steps.rstcheck.outputs.NEW_WARNINGS }} | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
issue_number: context.issue.number, | ||
repo: context.repo.repo, | ||
body: process.env.NEW_WARNINGS | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
#!/bin/bash | ||
|
||
# SPDX-License-Identifier: MIT | ||
# Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com | ||
|
||
### Wrapper to calculate deltas between two commits | ||
|
||
HELP_STRING=" | ||
Check if git branch or commit <NEW> generates any new build output running | ||
<COMMAND> based on git branch or commit <OLD>. | ||
check-warn.sh [OPTIONS] | ||
DIFF OPTIONS: | ||
-a OLD git branch or commit ID OLD as the base, 'HEAD' is | ||
acceptable | ||
-b NEW git branch or commit ID NEW for checking WARNING(s), 'HEAD' | ||
is acceptable | ||
-m, --merge automatically pick the merge-base for the given commits | ||
-- everything after this is the COMMAND to be executed | ||
OTHER OPTIONS: | ||
-h, --help this message | ||
" | ||
|
||
A_FILE= | ||
B_FILE= | ||
|
||
trap clean 1 2 3 6 15 | ||
|
||
usage() | ||
{ | ||
echo "${HELP_STRING}" | ||
exit "$1" | ||
} | ||
|
||
save_branch() | ||
{ | ||
# get current branch name or commit ID | ||
_cbr=$(git branch | sed -n '/\* /s///p') | ||
if [[ "$_cbr" == "(HEAD detached"* ]]; then | ||
_cbr=$(git rev-parse HEAD) | ||
fi | ||
} | ||
|
||
restore_branch() | ||
{ | ||
[ -z "$_cbr" ] || git checkout "$_cbr" | ||
} | ||
|
||
clean_files() | ||
{ | ||
rm -f "${A_FILE}" "${B_FILE}" | ||
} | ||
|
||
clean() | ||
{ | ||
clean_files | ||
restore_branch | ||
} | ||
|
||
summary() | ||
{ | ||
rm -f _new-warn.log | ||
diff --changed-group-format="%>" --unchanged-group-format="" \ | ||
"${A_FILE}" "${B_FILE}" > _new-warn.log | ||
|
||
_num=$(wc -l < _new-warn.log) | ||
|
||
echo | ||
echo "Found $_num new build WARNING(s)." | ||
echo | ||
|
||
if [ "$_num" != "0" ]; then | ||
cat _new-warn.log | ||
fi | ||
} | ||
|
||
generate_log() | ||
{ | ||
local git_hash log_path | ||
|
||
git_hash=$1 | ||
log_path=$2 | ||
|
||
git checkout "${git_hash}" || exit 10 | ||
|
||
mkdir -p build | ||
|
||
"${_cmd[@]}" 2>&1 | tee -a "${log_path}" | ||
} | ||
|
||
rev-parse() | ||
{ | ||
local rev | ||
if ! rev=$(git rev-parse "$1"); then | ||
printf '%s\n' 'Unable to parse given revisions:' | ||
printf ' %s\n' "$1" | ||
exit 2 | ||
fi | ||
echo "$rev" | ||
} | ||
|
||
main() | ||
{ | ||
# do nothing if current workspace is not clean | ||
if [ -n "$(git status --porcelain --untracked-files=no)" ] | ||
then | ||
echo "Error: Current workspace has uncommitted changes" | ||
exit 4 | ||
fi | ||
|
||
save_branch | ||
|
||
_old=$(rev-parse "${_old}") | ||
_new=$(rev-parse "${_new}") | ||
|
||
if [ -n "${_merge}" ] && ! _old=$(git merge-base "${_old}" "${_new}") | ||
then | ||
echo "Error: Unable to find merge-base for the given commits" | ||
exit 5 | ||
fi | ||
|
||
if ! A_FILE=$(mktemp) || ! B_FILE=$(mktemp); then | ||
echo "Could not make temp files!" | ||
exit 1 | ||
fi | ||
|
||
generate_log "${_old}" "${A_FILE}" | ||
generate_log "${_new}" "${B_FILE}" | ||
|
||
restore_branch | ||
summary | ||
#clean_files | ||
} | ||
|
||
while [ "$#" -gt 0 ]; do | ||
case $1 in | ||
-h | --help) usage 0;; | ||
-d | --device) shift; _dev=$1; shift;; | ||
-o | --os) shift; _os=$1; shift;; | ||
-a) shift; _old=$1; shift;; | ||
-b) shift; _new=$1; shift;; | ||
-m | --merge) shift; _merge=1;; | ||
--) shift; break;; | ||
*) shift;; | ||
esac | ||
done | ||
_cmd=("$@") | ||
|
||
if [ -z "${_new}" ] || [ -z "${_old}" ] || [ -z "${_cmd[*]}" ]; then | ||
usage 2 | ||
fi | ||
|
||
main |