1
0
Fork 0
mirror of https://github.com/canonical/action-build.git synced 2025-12-14 02:38:12 +00:00
A Github action for building Snapcraft projects
Find a file
James Henstridge 3bdaa03e1b
Merge pull request #78 from jhenstridge/update-deps
Update package dependencies
2024-07-15 16:16:17 +08:00
.github/workflows ci: upgrade to actions/upload-artifact@v4 2024-07-15 15:34:38 +08:00
__tests__ src: run snapcraft under "sudo -u $user -E" rather than using "sg" 2024-07-15 15:34:38 +08:00
dist package.json: upgrade dependencies 2024-07-15 16:06:18 +08:00
src src: run snapcraft under "sudo -u $user -E" rather than using "sg" 2024-07-15 15:34:38 +08:00
test-projects test-projects: add a core24 test project 2024-07-15 15:34:15 +08:00
.eslintignore Initial commit 2019-12-27 11:04:22 +08:00
.eslintrc.json package.json, src: upgrade dependencies, and fix lint warnings 2022-03-18 15:06:02 +08:00
.gitattributes Add .gitattributes file 2021-05-03 14:04:50 +08:00
.gitignore test-project: ship a test Snapcraft project to use in the integration test 2020-04-09 17:44:18 +08:00
.prettierignore Initial commit 2019-12-27 11:04:22 +08:00
.prettierrc.json Initial commit 2019-12-27 11:04:22 +08:00
action.yml action.yml: switch to node20 2023-10-23 18:24:41 +08:00
CONTRIBUTING.md package.json: Increment version number 2020-04-09 19:24:28 +08:00
jest.config.js Initial commit 2019-12-27 11:04:22 +08:00
LICENSE build: fold output from installing Snapcraft and dependencies 2020-01-14 20:08:38 +08:00
package-lock.json Bump version number 2024-07-15 16:08:25 +08:00
package.json Bump version number 2024-07-15 16:08:25 +08:00
README.md ci: bump version of actions/checkout in workflow 2023-10-27 19:01:50 +08:00
tsconfig.json tsconfig: upgrade target ECMAScript version 2022-03-18 15:10:11 +08:00

snapcraft-build-action status

Snapcraft Build Action

This is a Github Action that can be used to build a Snapcraft project. For most projects, the following workflow should be sufficient:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: snapcore/action-build@v1

This will install and configure LXD and Snapcraft, then invoke snapcraft to build the project.

On success, the action will set the snap output parameter to the path of the built snap. This can be used to save it as an artifact of the workflow:

...
    - uses: snapcore/action-build@v1
      id: snapcraft
    - uses: actions/upload-artifact@v3
      with:
        name: snap
        path: ${{ steps.snapcraft.outputs.snap }}

Alternatively, it could be used to perform further testing on the built snap:

    - run: |
        sudo snap install --dangerous ${{ steps.snapcraft.outputs.snap }}
        # do something with the snap

The action can also be chained with snapcore/action-publish@v1 to automatically publish builds to the Snap Store.

Action inputs

path

If your Snapcraft project is not located in the root of the workspace, you can specify an alternative location via the path input parameter:

...
    - uses: snapcore/action-build@v1
      with:
        path: path-to-snapcraft-project

build-info

By default, the action will tell Snapcraft to include information about the build in the resulting snap, in the form of the snap/snapcraft.yaml and snap/manifest.yaml files. Among other things, these are used by the Snap Store's automatic security vulnerability scanner to check whether your snap includes files from vulnerable versions of Ubuntu packages.

This can be turned off by setting the build-info parameter to false.

snapcraft-channel

By default, the action will install Snapcraft from the stable channel. If your project relies on a feature not found in the stable version of Snapcraft, then the snapcraft-channel parameter can be used to select a different channel.

snapcraft-args

The snapcraft-args parameter can be used to pass additional arguments to Snapcraft. This is primarily intended to allow the use of experimental features by passing --enable-experimental-* arguments to Snapcraft.

ua-token

The ua-token parameter can be used to tell Snapcraft to attach an Ubuntu Advantage (UA) token inside the build environment. Snapcraft will ensure the token is detached before exiting, but be warned that it is possible some failures may prevent detaching (e.g. aborted jobs).

In order to make the UA token available to the workflow, it should be stored as a repository secret:

  1. choose the "Settings" tab.
  2. choose "Secrets" from the menu on the left.
  3. click "Add a new secret".
  4. set the name to UA_TOKEN (or whatever is referenced in the workflow), and paste the UA token as the value.

Note that repository secrets are not available to workflows triggered by pull requests to public repositories.

An example workflow with UA token stored as secret UA_TOKEN:

...
    - uses: snapcore/action-build@v1
      with:
        ua-token: ${{ secrets.UA_TOKEN }}