Skip to content

Commit 1ac2500

Browse files
committed
build: guard against division by zero
1 parent 5200ce2 commit 1ac2500

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

.github/workflows/run_tests_coverage.yml

+11-12
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,19 @@ jobs:
244244
# Copy artifacts to the repository:
245245
- name: 'Copy artifacts to the repository'
246246
run: |
247-
cp -R ./artifacts/* ./www-test-code-coverage
247+
cp -R ./artifacts/* ./www-test-code-coverage
248248
249-
# Get commit SHA and timestamp:
250-
commit_sha=$(git rev-parse HEAD)
251-
commit_timestamp=$(git show -s --format=%ci $commit_sha)
249+
# Get commit SHA and timestamp:
250+
commit_sha=$(git rev-parse HEAD)
251+
commit_timestamp=$(git show -s --format=%ci $commit_sha)
252252
253-
# Append coverage to ndjson files:
254-
files=$(find ./artifacts -name 'index.html')
255-
for file in $files; do
256-
sed -i 's/\/artifacts\//\/www-test-code-coverage\//g' $file
257-
coverage=$(echo -n '['; grep -oP "(?<=class='fraction'>)[0-9]+/[0-9]+" $file | awk -F/ '{ print $1 "," $2 "," ($1/$2)*100 }' | tr '\n' ',' | sed 's/,$//'; echo -n ",\"$commit_sha\",\"$commit_timestamp\"]")
258-
echo $coverage >> $(dirname $file)/coverage.ndjson
259-
done
253+
# Append coverage to ndjson files:
254+
files=$(find ./artifacts -name 'index.html')
255+
for file in $files; do
256+
file=${file//artifacts/www-test-code-coverage}
257+
coverage=$(echo -n '['; grep -oP "(?<=class='fraction'>)[0-9]+/[0-9]+" $file | awk -F/ { if ($2 != 0) print $1 "," $2 "," ($1/$2)*100; else print $1 "," $2 ",100" }' | tr '\n' ',' | sed 's/,$//'; echo -n ",\"$commit_sha\",\"$commit_timestamp\"]")
258+
echo $coverage >> $(dirname $file)/coverage.ndjson
259+
done
260260
261261
# Commit and push changes:
262262
- name: 'Commit and push changes'
@@ -270,4 +270,3 @@ jobs:
270270
git add .
271271
git commit -m "Update artifacts"
272272
git push "https://$USER_NAME:$REPO_GITHUB_TOKEN@github.com/stdlib-js/www-test-code-coverage.git" $BRANCH_NAME
273-

0 commit comments

Comments
 (0)