@@ -247,137 +247,3 @@ jobs:
247247 report="## Coverage Report\n\n${table}\n\n${compare_txt}"
248248 fi
249249 echo "report=$report" >> $GITHUB_OUTPUT
250-
251- # Post report as comment to PR:
252- - name : ' Post report as comment to PR'
253- if : github.event_name == 'pull_request_target' && steps.check-changed.outputs.skip == 'false'
254- # Pin action to full length commit SHA
255- uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
256- with :
257- github-token : ${{ secrets.STDLIB_BOT_PAT_REPO_WRITE }}
258- script : |
259- const { data: comments } = await github.rest.issues.listComments({
260- 'issue_number': context.issue.number,
261- 'owner': context.repo.owner,
262- 'repo': context.repo.repo,
263- });
264-
265- const botComment = comments.find( comment => comment.user.login === 'stdlib-bot' && comment.body.includes( '## Coverage Report' ) );
266- if ( botComment ) {
267- await github.rest.issues.updateComment({
268- 'owner': context.repo.owner,
269- 'repo': context.repo.repo,
270- 'comment_id': botComment.id,
271- 'body': `${{ steps.create-report.outputs.report }}`
272- });
273- } else {
274- await github.rest.issues.createComment({
275- 'issue_number': context.issue.number,
276- 'owner': context.repo.owner,
277- 'repo': context.repo.repo,
278- 'body': `${{ steps.create-report.outputs.report }}`
279- });
280- }
281-
282- # Post report as comment to commit:
283- - name : ' Post report as comment to commit'
284- if : github.event_name == 'push' && steps.check-changed.outputs.skip == 'false'
285- # Pin action to full length commit SHA
286- uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
287- with :
288- github-token : ${{ secrets.STDLIB_BOT_PAT_REPO_WRITE }}
289- script : |
290- github.rest.repos.createCommitComment({
291- 'commit_sha': context.sha,
292- 'owner': context.repo.owner,
293- 'repo': context.repo.repo,
294- 'body': '${{ steps.create-report.outputs.report }}'
295- })
296-
297- # Checkout coverage repository:
298- - name : ' Checkout coverage repository'
299- if : steps.check-changed.outputs.skip == 'false'
300- # Pin action to full length commit SHA
301- uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
302- with :
303- # Code coverage repository:
304- repository : ' stdlib-js/www-test-code-coverage'
305-
306- # File path to checkout to:
307- path : ' ./www-test-code-coverage'
308-
309- # Specify whether to remove untracked files before checking out the repository:
310- clean : false
311-
312- # Limit clone depth to the most recent commit:
313- fetch-depth : 1
314-
315- # Token for accessing the repository:
316- token : ${{ secrets.STDLIB_BOT_FGPAT_REPO_READ }}
317-
318- # Avoid storing GitHub token in local Git configuration:
319- persist-credentials : false
320-
321- # Checkout coverage repository branch:
322- - name : ' Checkout coverage repository branch'
323- if : steps.check-changed.outputs.skip == 'false'
324- run : |
325- cd ./www-test-code-coverage
326-
327- if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
328- BRANCH_NAME="pr-${{ github.event.pull_request.number }}"
329- git fetch origin $BRANCH_NAME || true
330- git checkout $BRANCH_NAME || git checkout -b $BRANCH_NAME
331-
332- # Remove all directories except .github and .git from branch:
333- find . -mindepth 1 -maxdepth 1 -type d -not -name '.github' -not -name '.git' -exec git rm -rf {} +
334- else
335- BRANCH_NAME="main"
336- fi
337-
338- # Copy artifacts to the repository:
339- - name : ' Copy artifacts to the repository'
340- if : steps.check-changed.outputs.skip == 'false'
341- run : |
342- if [ -d "./artifacts" ]; then
343- cp -R ./artifacts/* ./www-test-code-coverage
344-
345- # Get commit SHA and timestamp:
346- commit_sha=$(git rev-parse HEAD)
347- commit_timestamp=$(git show -s --format=%ci $commit_sha)
348-
349- # Append coverage to ndjson files:
350- files=$(find ./artifacts -name 'index.html')
351- for file in $files; do
352- file=${file//artifacts/www-test-code-coverage}
353- 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\"]")
354- echo $coverage >> $(dirname $file)/coverage.ndjson
355- done
356- else
357- echo "The artifacts directory does not exist."
358- fi
359-
360- # Import GPG key to sign commits:
361- - name : ' Import GPG key to sign commits'
362- if : steps.check-changed.outputs.skip == 'false'
363- # Pin action to full length commit SHA
364- uses : crazy-max/ghaction-import-gpg@cb9bde2e2525e640591a934b1fd28eef1dcaf5e5 # v6.2.0
365- with :
366- gpg_private_key : ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }}
367- passphrase : ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }}
368- git_user_signingkey : true
369- git_commit_gpgsign : true
370-
371- # Commit and push changes:
372- - name : ' Commit and push changes'
373- if : steps.check-changed.outputs.skip == 'false'
374- env :
375- REPO_GITHUB_TOKEN : ${{ secrets.STDLIB_BOT_PAT_REPO_WRITE }}
376- USER_NAME : stdlib-bot
377- run : |
378- cd ./www-test-code-coverage
379- git config --local user.email "[email protected] " 380- git config --local user.name "stdlib-bot"
381- git add .
382- git commit -m "Update artifacts" || exit 0
383- git push "https://$USER_NAME:[email protected] /stdlib-js/www-test-code-coverage.git" $BRANCH_NAME
0 commit comments