canonical / action-build

A Github action for building Snapcraft projects
MIT License
42 stars 22 forks source link

feature: Action should upload the log of a failed build as an asset #80

Open popey opened 3 months ago

popey commented 3 months ago

When a build fails there's no way to get at the log produced by snapcraft. This is especially frustrating when snapcraft itself doesn't produce a useful error in the summary.

Example: https://github.com/popey/twinejs-snap/actions/runs/10046772545/job/27766984335

2024-07-22T19:05:40.7885945Z Generated snap manifest
2024-07-22T19:05:40.7890511Z Reading snap metadata...
2024-07-22T19:05:40.7945791Z Running linters...
2024-07-22T19:05:40.7946938Z Running linter: classic
2024-07-22T19:05:40.7953093Z Running linter: library
2024-07-22T19:05:42.4555335Z Lint warnings:
2024-07-22T19:05:42.4559849Z - library: libXss.so.1: unused library 'usr/lib/x86_64-linux-gnu/libXss.so.1.0.0'. (https://snapcraft.io/docs/linters-library)
2024-07-22T19:05:42.4561141Z - library: libssl3.so: unused library 'usr/lib/x86_64-linux-gnu/libssl3.so'. (https://snapcraft.io/docs/linters-library)
2024-07-22T19:05:42.4662413Z Creating snap package...
2024-07-22T19:05:42.4770096Z Command '['snap', 'pack', '--filename', 'twinejs_2.9.1_amd64.snap', '--compression', 'lzo', PosixPath('/root/prime'), PosixPath('/root/project')]' returned non-zero exit status 1.
2024-07-22T19:05:47.7376191Z Failed to execute pack in instance.
2024-07-22T19:05:47.7418060Z Recommended resolution: Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
2024-07-22T19:05:47.7420054Z Full execution log: '/home/runner/.local/state/snapcraft/log/snapcraft-20240722-190027.468199.log'
2024-07-22T19:05:47.8567833Z ##[error]The process '/usr/bin/sudo' failed with exit code 1
2024-07-22T19:05:47.8677012Z Post job cleanup.
2024-07-22T19:05:47.9553444Z [command]/usr/bin/git version
2024-07-22T19:05:47.9588997Z git version 2.45.2

In the above example, there's no detail about why the final step of creating the package has failed (that's a snapcraft bug, granted), but when this happens, it would be useful to have access to the full log, as I can't login to the runner to get to it manually.

Thanks!

jhenstridge commented 3 months ago

I'm not sure how easy it'd be to integrate this into the action directly. I'm not sure how stable they treat the API for creating artifacts.

It is fairly easy to do this in your own workflow by adding a step like the following:

  - if: failure()
    uses: action/upload-artifact@v4
    with:
      name: snapcraft-logs
      path: ~/.local/state/snapcraft/log/*.log

This will trigger if any previous step in the job has failed. You could leave out the if: failure() predicate if you always want to create a logs artifact rather than only in the case of failures.

It seems worthwhile updating the example workflow to include something like this.