Skip to content

Commit ba3bc8b

Browse files
committed
#2465: Use github provided values for SHA and date
1 parent be00e2c commit ba3bc8b

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

.github/workflows/build-docker-images.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
- name: Test
8888
run: |
8989
job_id=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id}}/attempts/${{ github.run_attempt }}/jobs | jq -r '.jobs | .[0].id')
90-
matrix_job_html_url=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id}}/attempts/${{ github.run_attempt }}/jobs | jq -r '.jobs | map(select(.name | contains("${{ matrix.region }}"))) | .[0].html_url')
90+
matrix_job_html_url=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id}}/attempts/${{ github.run_attempt }}/jobs | jq -r '.jobs | map(select(.name | contains("${{ matrix.target }}"))) | .[0].html_url')
9191
matrix_id=$( sed 's/.*\jobs\///' <<<$matrix_job_html_url)
9292
echo "matrix job html url: $matrix_job_html_url"
9393
echo "matrix id: $matrix_id" # i doubt this is of any use. in the github response this id is only present as part of the html_url
@@ -114,13 +114,15 @@ jobs:
114114
./scripts/report_logs_in_comment.sh \
115115
"build/vt/compilation_errors_warnings.out" \
116116
"build/vt/cmake-output.log" \
117-
"${{ github.run_number }}" \
117+
"${{ matrix.target }}" \
118118
"${{ github.event.pull_request.number }}" \
119119
"${{ github.repository }}" \
120120
"${{ secrets.GITHUB_TOKEN }}" \
121121
"${{ github.run_id }}" \
122122
"${{ github.job }}" \
123-
"${{ steps.build-image.outcome }}"
123+
"${{ steps.build-image.outcome }}" \
124+
"${{ github.sha }} " \
125+
"${{ github.event.head_commit.timestamp }}" \
124126
125127
- name: Upload coverage
126128
if: ${{ matrix.target == 'vt-build-amd64-ubuntu-22-04-gcc-11-cpp' }}

scripts/report_logs_in_comment.sh

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@
4444

4545
compilation_errors_warnings_out="$1"
4646
cmake_output_log="$2"
47-
build_number="$3"
47+
comment_title="$3"
4848
pull_request_number="$4"
4949
repository_name="$5"
5050
github_token="$6"
5151
build_id="$7"
5252
job_name="$8"
5353
job_status="$9"
54+
commit_sha="${10}"
55+
commit_date="${11}"
5456

5557
echo "job_status: $job_status"
5658
if [[ "$job_status" == "success" || "$job_status" == "failure" ]]; then
@@ -63,31 +65,40 @@ warnings_errors=$(cat "$compilation_errors_warnings_out")
6365

6466
delimiter="-=-=-=-"
6567
tests_failures=""
66-
if [[ -f "$cmake_output_log" ]]; then
68+
if test -f "$cmake_output_log"
69+
then
6770
tests_failures=$(< "$cmake_output_log" sed -n -e '/The following tests FAILED:/,$p')
6871
tests_failures=${tests_failures//$'\n'/$delimiter}
6972
tabulation=" "
7073
tests_failures=${tests_failures//$'\t'/$tabulation}
7174
fi
7275

73-
if [[ "$succeeded" -eq 1 ]]; then
74-
[[ -z "$warnings_errors" ]] && warnings_errors='Compilation - successful'
75-
[[ -z "$tests_failures" ]] && tests_failures='Testing - passed'
76+
if test "$succeeded" -eq 1
77+
then
78+
if test -z "$warnings_errors"
79+
then
80+
warnings_errors='Compilation - successful'
81+
fi
82+
83+
if test -z "$tests_failures"
84+
then
85+
tests_failures='Testing - passed'
86+
fi
7687
else
77-
if [[ -z "$warnings_errors" && -z "$tests_failures" ]]; then
88+
if test -z "$warnings_errors" && test -z "$tests_failures"
89+
then
7890
warnings_errors='Build failed for unknown reason. Check build logs'
7991
fi
8092
fi
8193

94+
# Concatenate both reports into one
8295
val="$warnings_errors""$delimiter""$delimiter""$tests_failures"
8396
max_comment_size=3000
84-
if [[ ${#val} -gt "$max_comment_size" ]]; then
97+
if test ${#val} -gt "$max_comment_size"
98+
then
8599
val="${val:0:max_comment_size}%0D%0A%0D%0A%0D%0A ==> And there is more. Read log. <=="
86100
fi
87101

88-
commit_sha="$(git log --skip=1 -1 --pretty=format:%H)"
89-
commit_date="$(TZ=UTC0 git show -s --format=%cd --date=format-local:'%Y-%m-%d %H:%M:%S' "$commit_sha")"
90-
91102
# Fetch numeric job ID from GitHub API
92103
job_id=$(curl -s -H "Authorization: token $github_token" \
93104
"https://api.github.com/repos/${repository_name}/actions/runs/${build_id}/jobs" | \
@@ -100,17 +111,26 @@ else
100111
build_link="[Build log](https://github.com/${repository_name}/actions/runs/${build_id})"
101112
fi
102113

114+
# Build comment
115+
commit_sha="$(git log --skip=1 -1 --pretty=format:%H)"
116+
commit_date="$(TZ=UTC0 git show -s --format=%cd --date=format-local:'%Y-%m-%d %H:%M:%S' "$commit_sha")"
117+
build_link='[Build log](https://dev.azure.com/DARMA-tasking/DARMA/_build/results?buildId='"$build_id"'&view=logs&j='"$job_id"'&t='"$task_id)"
103118
comment_body="Build for $commit_sha ($commit_date UTC)\n\n"'```'"\n$val\n"'```'"\n\n$build_link"
104-
comment_body=${comment_body//$delimiter/$'\n'}
105-
comment_body=${comment_body//\"/\\\"}
119+
120+
# Fix new lines
121+
new_line="\n"
122+
comment_body=${comment_body//$delimiter/$new_line}
123+
quotation_mark="\""
124+
new_quotation_mark="\\\""
125+
comment_body=${comment_body//$quotation_mark/$new_quotation_mark}
106126

107127
rm -f data.json
108128

109129
{
110130
echo "{"
111131
echo ' "event_type": "comment-pr",'
112132
echo ' "client_payload": {'
113-
echo ' "comment_title": "'"$build_number"'",'
133+
echo ' "comment_title": "'"$comment_title"'",'
114134
echo ' "comment_content": "'"$comment_body"'",'
115135
echo ' "pr_number": "'"$pull_request_number"'"'
116136
echo " }"

0 commit comments

Comments
 (0)