Skip to content

Commit

Permalink
ci: promote snap to candidate on every release (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdcordeiro authored Jul 31, 2023
1 parent 731299e commit b073926
Showing 1 changed file with 58 additions and 3 deletions.
61 changes: 58 additions & 3 deletions .github/workflows/snap.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: Pebble snap

on: [pull_request]
on:
pull_request:
branches: [master]
release:
types: [published]

env:
SNAP_NAME: pebble

jobs:
build:
Expand All @@ -27,19 +34,67 @@ jobs:
test:
runs-on: ubuntu-latest
needs: [build]
outputs:
pebble-version: ${{ steps.install-pebble.outputs.version }}

steps:
- uses: actions/download-artifact@v3
with:
name: ${{ needs.build.outputs.pebble-snap }}

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

promote:
if: ${{ github.event_name == 'release' }}
runs-on: ubuntu-latest
needs: [test]
strategy:
fail-fast: false
matrix:
arch: [amd64, arm64, ppc64el, armhf, s390x]
env:
TRACK: latest
DEFAULT_RISK: edge
TO_RISK: candidate
steps:
- name: Install Snapcraft
run: sudo snap install snapcraft --classic

- name: Wait for ${{ needs.test.outputs.pebble-version }} to be released
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}
run: |
while ! `snapcraft status ${{ env.SNAP_NAME }} --track ${{ env.TRACK }} --arch ${{ matrix.arch }} \
| grep "${{ env.DEFAULT_RISK }}" \
| awk -F' ' '{print $2}' \
| grep -Fxq "${{ needs.test.outputs.pebble-version }}"`; do
echo "[${{ matrix.arch }}] Waiting for ${{ needs.test.outputs.pebble-version }} \
to be released to ${{ env.TRACK }}/${{ env.DEFAULT_RISK }}..."
sleep 10
done
# It would be easier to use `snapcraft promote`, but there's an error when trying
# to avoid the prompt with the "--yes" option:
# > 'latest/edge' is not a valid set value for --from-channel when using --yes.
- name: Promote ${{ needs.test.outputs.pebble-version }} (${{ matrix.arch }}) to ${{ env.TO_RISK }}
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}
run: |
revision="$(snapcraft status ${{ env.SNAP_NAME }} \
--track ${{ env.TRACK }} --arch ${{ matrix.arch }} \
| grep "${{ env.DEFAULT_RISK }}" | awk -F' ' '{print $3}')"
snapcraft release ${{ env.SNAP_NAME }} \
$revision \
${{ env.TRACK }}/${{ env.TO_RISK }}

0 comments on commit b073926

Please sign in to comment.