Skip to content

.github/workflows/fetch_snaps.yaml #15

.github/workflows/fetch_snaps.yaml

.github/workflows/fetch_snaps.yaml #15

Workflow file for this run

# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
on:
workflow_dispatch:
jobs:
test-deploy-bundle:
name: Test deploy bundle
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Free up disk space
timeout-minutes: 1
run: |
printf '\nDisk usage before cleanup\n'
df --human-readable
# Based on https://github.com/actions/runner-images/issues/2840#issuecomment-790492173
rm -r /usr/share/dotnet
rm -r /opt/hostedtoolcache/
printf '\nDisk usage after cleanup\n'
df --human-readable
- name: Set up environment
timeout-minutes: 60
run: |
# `--classic` applies to juju 2 snap; ignored for juju 3 snap
sudo snap install juju --classic --channel='3.4/stable'
sudo snap refresh lxd --channel='latest/stable'
sudo adduser "$USER" 'lxd'
# `newgrp` does not work in GitHub Actions; use `sg` instead
sg 'lxd' -c "lxd waitready"
sg 'lxd' -c "lxd init --auto"
sg 'lxd' -c "lxc network set lxdbr0 ipv6.address none"
sudo iptables -F FORWARD
sudo iptables -P FORWARD ACCEPT
# shellcheck disable=SC2193
# (shellcheck sees it as constant, but GitHub Actions expression is not constant between workflow runs)
sg 'lxd' -c "lxc image copy ubuntu:82b997ec581b local: --alias 'juju/[email protected]/amd64'"
mkdir -p ~/.local/share/juju # Workaround for juju 3 strict snap
sg 'lxd' -c "juju bootstrap 'lxd' --config model-logs-size=10G '--agent-version=3.4.5'"
juju model-defaults logging-config='<root>=INFO; unit=DEBUG'
juju add-model test
juju set-model-constraints arch='amd64'
sg 'lxd' -c "lxc image list"
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
- name: Deploy bundle and fetch snaps
id: update-file
timeout-minutes: 60
run: |
juju deploy ./releases/latest/postgresql-bundle.yaml
sleep 600 # time to allow the bundle to settle
juju status
juju exec --all --output snaps.txt -- snap list
cat ./snaps.txt
output_table=$(cat ./snaps.txt | awk '! /^[0-9]/ && $1 != "Name" { print $1, $3, $4 }' | sort | uniq)
canonical_livepatch=$(snap info canonical-livepatch | awk '/^channels:/ {found=1; next} found && $1 != "" {print $1, $4; exit}')
python ./src/generate_snaps_yaml.py "$output_table" "$canonical_livepatch" "./releases/latest/snaps.yaml"
cat ./releases/latest/snaps.yaml
- name: Push `update-snaps` branch
if: ${{ fromJSON(steps.update-file.outputs.updates_available) }}
run: |
git checkout -b update-snaps
git add ./releases/latest/snaps.yaml
git config user.name "GitHub Actions"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -m "Update bundle snaps"
# Uses token set in checkout step
git push origin update-snaps -f
- name: Create pull request
if: ${{ fromJSON(steps.update-file.outputs.updates_available) }}
run: |
# Capture output in variable so that step fails if `gh pr list` exits with non-zero code
prs=$(gh pr list --head update-snaps --state open --json number)
if [[ $prs != "[]" ]]
then
echo Open pull request already exists
exit 0
fi
gh pr create --head update-snaps --title "Update bundle snaps" --body "Update snap revisions in snap YAML file"
env:
GH_TOKEN: ${{ secrets.PAT }}