article

Upload Artifacts in GitHub Actions

Most workflows you'll write will have a result you'd like to archive as artifact.

If you write a workflow for Android this could be for example:

  • apk
  • aab
  • unit test result
  • static code analysis results

actions/upload-artifact@v2

GitHub Actions comes with a standard action which will store and upload the artifacts are archive to the build.

- name: Archive Artifacts
  uses: actions/upload-artifact@v2
  with:
     name: "App-Artifacts"
     path: artifacts/*

The above example will upload all files found in the artifacts folder as App-Artifacts.zip, which will show up in the build result. Every build allows multiple artifacts to be uploaded, but please note that the name has to be unique, and will result in equally named artifacts being overwritten.

GitHub Actions Build Artifacts
GitHub Actions Build Artifacts

While this is great for PR builds, or similar situations, it is not the best suited for release builds which should be linked to the release / tag in GitHub.

It would be possible to use the GitHub REST API for this, but I found it much cleaner to use an action for this.

softprops/action-gh-release

For more details about this action checkout its GitHub page.

Using the above action it becomes very easy to upload artifacts to the release. It even comes with additional functionalities like associating release notes, ...

For my projects I usually define it, to only run for tags, and have it's artifacts already prepared within an artifacts folder.

- name: Release
  uses: softprops/action-gh-release@91409e712cf565ce9eff10c87a8d1b11b81757ae
  if: startsWith(github.ref, 'refs/tags/')
  with:
    # Identify if this is a pre release by checking if the tag name contains -rc, -b, -a
    prerelease: ${{ contains(github.ref, '-rc') || contains(github.ref, '-b') || contains(github.ref, '-a') }}
    files: artifacts/*
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Test results

GitHub actions does currently not offer any UI to visualize reports (like test results) on a result page. Instead it embraces the checks API which allows to annotate tests and source code with result data.

One way to do so is with yet another action.

scacap/action-surefire-report

For more details about this action checkout its GitHub page.

First execute the unit tests / instrumented tests which result in a unit test xml.

After this provide the test-results to the action which will use the GITHUB_TOKEN to mark the test results on the PR.

- name: Run Unit Tests
  run: ./gradlew testDebug

- name: Publish Test Report
  uses: scacap/action-surefire-report@bc71e9d0f892826ec4cd14db336bd115ddfcb1c8
  with:
    report_paths: '**/test-results/**/TEST-*.xml'
    github_token: ${{ secrets.GITHUB_TOKEN }}
GitHub Actions Test Result Report
GitHub Actions Test Result Report

Feedback

Got thoughts, feedback, improvements, suggestions, or comments?

Let me know @mike_penz