Skip to content

Commit

Permalink
fix(snap): (fix canonical#300) remotely build snaps from GH
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdcordeiro committed Oct 12, 2023
1 parent bbf5139 commit 92c0b15
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 21 deletions.
90 changes: 70 additions & 20 deletions .github/workflows/snap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,112 @@ name: Pebble snap
on:
pull_request:
branches: [master]
push:
branches: [master]
release:
types: [published]

env:
SNAP_NAME: pebble
SNAP_NAME: pebble-cjdc
DEFAULT_TRACK: latest
DEFAULT_RISK: edge

jobs:
build:
runs-on: ubuntu-latest
outputs:
pebble-snap: ${{ steps.build-pebble-snap.outputs.snap }}

strategy:
fail-fast: false
matrix:
arch: [amd64, arm64, ppc64el, armhf, s390x]
steps:
- name: Checkout Pebble repo
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Build Pebble Snap
id: build-pebble-snap
uses: snapcore/action-build@v1
- name: Set LP credentials for remote build
id: set-local-paths
run: |
lp_creds_path="$HOME/.local/share/snapcraft/provider/launchpad"
mkdir -p $lp_creds_path
echo '${{ secrets.LP_CREDENTIALS }}' > ${lp_creds_path}/credentials
git config --global user.email "${{ secrets.PEBBLE_DEV_MAILING_LIST}}"
git config --global user.name "pebble-dev"
echo "home=$HOME" >> $GITHUB_OUTPUT
- name: Attach pebble snap to GH workflow execution
- name: Build ${{ env.SNAP_NAME }} Snap for ${{ matrix.arch }}
id: build-snap
uses: snapcore/[email protected]
with:
snapcraft-args: remote-build --build-for=${{ matrix.arch }} --launchpad-accept-public-upload

- uses: actions/upload-artifact@v3
if: failure()
with:
name: snapcraft-logs
path: |
${{ steps.set-local-paths.outputs.home }}/.cache/snapcraft/log/
${{ steps.set-local-paths.outputs.home }}/.local/state/snapcraft/log/
${{ env.SNAP_NAME }}_*.txt
- name: Attach ${{ matrix.arch }} snap to GH workflow execution
uses: actions/upload-artifact@v2
with:
name: ${{ steps.build-pebble-snap.outputs.snap }}
path: ${{ steps.build-pebble-snap.outputs.snap }}
name: ${{ steps.build-snap.outputs.snap }}
path: ${{ steps.build-snap.outputs.snap }}

test:
runs-on: ubuntu-latest
needs: [build]
outputs:
pebble-version: ${{ steps.install-pebble.outputs.version }}

strategy:
fail-fast: true
# NOTE: adjust this matrix if we ever start testing with multi-arch runners.
matrix:
arch: [amd64]
steps:
- uses: actions/download-artifact@v3
- name: Download ${{ env.SNAP_NAME }} snap for ${{ matrix.arch }}
id: download-artifact
uses: dawidd6/action-download-artifact@v2
with:
name: ${{ needs.build.outputs.pebble-snap }}
name: "${{ env.SNAP_NAME }}*${{ matrix.arch }}.snap"
name_is_regexp: true

- name: Install the Pebble snap
id: install-pebble
run: |
set -ex
ls
# Install the Pebble snap from the artifact built in the previous job
sudo snap install --dangerous --classic ${{ needs.build.outputs.pebble-snap }}
sudo snap install --dangerous --classic \
`ls ${{ env.SNAP_NAME }}*${{ matrix.arch }}.snap`
# Make sure Pebble is installed
echo "version=$(pebble version --client)" >> "$GITHUB_OUTPUT"
echo "version=$(pebble-cjdc.pebble version --client)" >> "$GITHUB_OUTPUT"
- name: Run smoke test
run: pebble enter --create-dirs exec echo Hello | grep Hello
run: pebble-cjdc.pebble enter --create-dirs exec echo Hello | grep Hello

# upload:
# if: ${{ github.event_name != 'pull_request' }}
# runs-on: ubuntu-latest
# needs: [test]
# steps:
# - uses: actions/download-artifact@v3
# with:
# name: snaps

# - name: Upload snaps to ${{ env.DEFAULT_TRACK }}/${{ env.DEFAULT_RISK }}
# run: |
# set -ex
# for snap in `ls ${{ env.SNAP_NAME }}*.snap`
# do
# snapcraft

promote:
if: ${{ github.event_name == 'release' }}
runs-on: ubuntu-latest
needs: [test]
needs: [upload]
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ parts:
plugin: nil
source: .
override-build: |
version="$(${CRAFT_PART_INSTALL}/bin/pebble version --client)"
version="$(${CRAFT_STAGE}/bin/pebble version --client)"
# Set snap version
craftctl set version="$version"
Expand Down

0 comments on commit 92c0b15

Please sign in to comment.