hrgui
7/4/2022

What I use `$GITHUB_STEP_SUMMARY` for

In 05/09/2022, Github Actions released $GITHUB_STEP_SUMMARY.

I use it for reporting code coverage. Writing it in a comment will always fail as comments cannot be greater than 65536 characters. I always exceed that.

Add this step to your Github Actions file, if you use vitest:

- name: 🧪 Test
  run: |
    yarn test --silent --coverage
    echo "### Test Results 🧪 "  >> $GITHUB_STEP_SUMMARY
    echo "\`\`\`"  >> $GITHUB_STEP_SUMMARY
    yarn c8 report >> $GITHUB_STEP_SUMMARY
    echo "\`\`\`"  >> $GITHUB_STEP_SUMMARY

Here’s a sample result.

If you use jest, just replace yarn c8 report with the output of yarn test --silent --coverage, like so:

- name: 🧪 Test
  run: |
    echo "### Test Results 🧪 "  >> $GITHUB_STEP_SUMMARY
    echo "\`\`\`"  >> $GITHUB_STEP_SUMMARY
    yarn test --silent --coverage >> $GITHUB_STEP_SUMMARY
    echo "\`\`\`"  >> $GITHUB_STEP_SUMMARY

However, you won’t be able to see your tests run in Github Actions as they will be piped to the ENV variable. 🤔

hrgui

Harman Goei (hrgui) is a developer that loves to make cool and awesome web applications. His strength is in HTML, CSS, JavaScript, but he is willing to code anywhere in the stack to make the web be awesome.

© 2023 Harman Goei