Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/test-snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,44 @@ jobs:
name: test-snap-${{ matrix.os }}-${{ steps.snapcraft.outputs.snapcraft-revision }}
path: test-repo/tests/spread/core22/clean/snaps/clean/*.snap
overwrite: true
test:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- ubuntu-24.04
- ubuntu-22.04-arm
- ubuntu-24.04-arm
- self-hosted-linux-amd64-focal-medium
- self-hosted-linux-ppc64el-noble-edge
- self-hosted-linux-s390x-noble-edge
channel: [latest/candidate, latest/edge, 8.x/candidate]
parameters: ['', '--help']
include:
- os: ubuntu-24.04
channel: ''
revision: 16570 # 8.13.2, but really here to test the revision field.
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v5
with:
repository: lengau/astral-ty
path: test-repo
ref: main
- name: Test snap
id: snapcraft
uses: ./snapcraft/test
with:
path: test-repo
channel: ${{ matrix.channel }}
revision: ${{ matrix.revision }}
- name: Upload snap
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: test-snap-${{ matrix.os }}-${{ steps.snapcraft.outputs.snapcraft-revision }}
path: test-repo/*.snap
overwrite: true

117 changes: 117 additions & 0 deletions snapcraft/test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: 'Test a snap'
description: 'Test a snap with Snapcraft 8 or higher'
author: Canonical

inputs:
path:
description: >
The location of the Snapcraft project.

Defaults to the root of the repository.
default: '.'
verbosity:
description: >
The build verbosity level, which can be set to "quiet", "brief", "verbose", "debug",
or "trace".

The default is "trace".
default: 'trace'
parameters:
description: >
Additional parameters to pass to snapcraft test.
default: ''
channel:
description: >
The channel to install Snapcraft from.

Defaults to the latest stable release.
default: 'latest/stable'
revision:
description: >
The revision of Snapcraft to install.

Defaults to the latest stable revision.

Overrides the `channel` option.
default: ''
lxd-channel:
description: >
The channel to install LXD from.

Defaults to the recommended channel for Snapcraft.
default: '5.21/stable'

outputs:
lxd-revision:
description: The LXD revision used.
value: ${{ steps.setup.outputs.lxd-revision }}
snapcraft-revision:
description: The Snapcraft revision used.
value: ${{ steps.setup.outputs.snapcraft-revision }}
snap:
description: The packed snap artifact.
value: ${{ steps.test.outputs.snap }}
components:
description: The packed components.
value: ${{ steps.test.outputs.components }}

runs:
using: 'composite'
steps:
# This action is necessary as a workaround for https://github.com/actions/runner/issues/895.
# Since contexts cannot be used in the `uses:` key, we can't guarantee that this action will
# use the same branch of craft-actions to call other craft-actions workflows without just
# making our own local copy of the repository. See https://github.com/canonical/craft-actions/pull/45#discussion_r2586507869
# for a full explanation.
- uses: actions/checkout@v6
env:
GITHUB_REF: ${{ github.action_ref }}
with:
repository: 'canonical/craft-actions'
ref: ${{ env.GITHUB_REF }}
path: _tmp_craft-actions
sparse-checkout: |
snapcraft/

- uses: ./_tmp_craft-actions/snapcraft/setup
id: setup
with:
channel: ${{ inputs.channel }}
revision: ${{ inputs.revision }}
lxd-channel: ${{ inputs.lxd-channel }}

- shell: bash
run: |
rm -rf ./_tmp_craft-actions

- shell: bash
id: test
env:
CRAFT_VERBOSITY_LEVEL: ${{ inputs.verbosity }}
working-directory: ${{ inputs.path }}
run: |
# Snapcraft < 8 doesn't support `snapcraft test`.
# Examples of running `snapcraft --version`:
# snapcraft 8.14.0.post57+dirty
# snapcraft 8.14.2
# snapcraft 7.5.9
# snapcraft, version 6.1
SNAPCRAFT_VERSION=$(snapcraft --version | awk '{print $NF}')
MAJOR_VERSION=$(echo "$SNAPCRAFT_VERSION" | cut -d'.' -f1)
if [[ "$MAJOR_VERSION" =~ ^[0-9]+$ ]] && [ "$MAJOR_VERSION" -lt 8 ]; then
echo "Snapcraft 8 needed for the test command" >> /dev/stderr
exit 1
else
snapcraft test ${{ inputs.parameters }}
fi
echo "snap=$(ls *.snap)" >> "$GITHUB_OUTPUT"
components=( *.comp )
if [ -e "${components[0]}" ]; then
echo "components=${components[*]}" >> "$GITHUB_OUTPUT"
else
echo "components=" >> "$GITHUB_OUTPUT"
fi

branding:
icon: package
color: orange
Loading