Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 2.41 KB

job-summaries.md

File metadata and controls

48 lines (36 loc) · 2.41 KB

GitHub Actions job summaries

New feature announced here. Here's the full documentation.

These are incredibly easy to use. GitHub creates a file in your workspace and puts the filename in $GITHUB_STEP_SUMMARY, so you can build the summary markdown over multiple steps like this:

echo "{markdown content}" >> $GITHUB_STEP_SUMMARY

I decided to try this out in my simonw/pypi-datasette-packages repo, which runs a daily Git scraper that records a copy of the PyPI JSON for packages within the Datasette ecosystem.

I ended up mixing it with the Git commit code, so the step now looks like this:

    - name: Commit and push
      run: |-
        git config user.name "Automated"
        git config user.email "[email protected]"
        git add -A
        timestamp=$(date -u)
        git commit -m "${timestamp}" || exit 0
        echo '### Changed files' >> $GITHUB_STEP_SUMMARY
        echo '```' >> $GITHUB_STEP_SUMMARY
        git show --name-only --format=tformat: >> $GITHUB_STEP_SUMMARY
        echo '```' >> $GITHUB_STEP_SUMMARY
        git pull --rebase
        git push

This produces a summary that looks like this:

Screenshot of the summary

Two things I had to figure out here. First, the backtick needs escaping if used in double quotes but does not in single quotes:

echo '```' >> $GITHUB_STEP_SUMMARY

I wanted to show just the list of affected filenames from the most recent Git commit. That's what this does:

git show --name-only --format=tformat:

Without the --format=tformat bit this shows the full commit message and header in addition to the list of files.

I'm running this in the same block as the other git commands so that this line will terminate the step early without writing to the summary file if there are no changes to be committed:

git commit -m "${timestamp}" || exit 0