Installation

snapcraft executable can be installed with the snap. Recent Ubuntu versions now have snap executable pre-installed.

sudo snap install snapcraft --classic

Login Token

A login token is used by snapcraft to interact with published snaps on Snapcraft Store. In this setup, it is used to push a new version of the snap to the store.

echo "$SNAP_TOKEN" | snapcraft login --with -

A login token can be generated by executing the below command in your local terminal where you are already logged in. It will generate a file named snap.login.

snapcraft export-login --snaps <snap_name> snap.login

Create a secret SNAP_TOKEN on Github with the contents of this file. Set below the environment variable to use the secret. Steps on creating a secret at docs.github.com.

env:
  SNAP_TOKEN: ${{secrets.SNAP_TOKEN}} 

Build Environment

By default, snapcraft uses a virtual machine driven by multipass to build the snap. But, there is no need to use a virtual machine on Github. Set below environment variable to build without a virtual machine. Details at snapcraft.io.

env:
  SNAPCRAFT_BUILD_ENVIRONMENT: host

Sample

name: Build
on:
  push:
    branches: [ master ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
        cd ..
    - name: Setup Snapcraft
      run: |
        sudo snap install snapcraft --classic
        echo "$SNAP_TOKEN" | snapcraft login --with -
        snapcraft
        snapcraft upload --release=stable *.snap        
      env:
        SNAP_TOKEN: ${{secrets.SNAP_TOKEN}} 
        SNAPCRAFT_BUILD_ENVIRONMENT: host