Skip to content

Add a github action to test the PR in a complete MC cluster with incus #31

Add a github action to test the PR in a complete MC cluster with incus

Add a github action to test the PR in a complete MC cluster with incus #31

Workflow file for this run

name: Test complete puppet environment
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.5.7"
- name: Install incus
run: |
curl https://pkgs.zabbly.com/get/incus-stable | sudo sh -x
- name: Reset the firewall and disable apparmor
run: |
sudo nft flush ruleset
sudo aa-teardown &> /dev/null || true
sudo systemctl disable --now apparmor.service
- name: Init incus
run: |
sudo incus admin init --auto
- name: Download Magic Castle Incus
run: |
curl -L -O https://raw.githubusercontent.com/ComputeCanada/magic_castle/refs/heads/main/examples/incus/main.tf
curl -L -O https://raw.githubusercontent.com/ComputeCanada/magic_castle/refs/heads/main/examples/incus/data.yaml
- name: Init and apply
run: |
sed -i "s;\"main\";\"${GITHUB_REF}\";" main.tf
sudo chgrp runner /var/lib/incus/unix.socket
terraform init
terraform apply -auto-approve
- name: Wait for puppet catalog to be applied
continue-on-error: true
timeout-minutes: 15
run: |
incus project switch $(incus project list -c n --format csv | grep -v 'default' | cut -f1 -d' ')
for nodename in $(incus list -c n -f csv); do
echo -n $nodename
until incus exec $nodename -- journalctl -u puppet | grep "Applied catalog"; do
echo -n .
sleep 10
done
echo
done
- name: Setup upterm session
uses: owenthereal/action-upterm@v1
with:
limit-access-to-actor: true
- name: Verify Puppet catalog for errors
run: |
SUCCESSFUL=0
incus project switch $(incus project list -c n --format csv | grep -v 'default' | cut -f1 -d' ')
for nodename in $(incus list -c n -f csv); do
echo -n "### ${nodename}" >> $GITHUB_STEP_SUMMARY
if incus exec $nodename -- journalctl -u puppet | grep "failed dependencies" &> /dev/null; then
echo " FAILED" >> $GITHUB_STEP_SUMMARY
echo '#### failures' >> $GITHUB_STEP_SUMMARY
echo -e '\n<details>\n' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
incus exec $nodename -- journalctl -u puppet -p3..4 >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo -e '\n</details>\n' >> $GITHUB_STEP_SUMMARY
SUCCESSFUL=1
else
echo
fi
echo #### successes >> $GITHUB_STEP_SUMMARY
echo -e '\n<details>\n' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
incus exec $nodename -- journalctl -u puppet -p5..5 >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo -e '\n</details>\n' >> $GITHUB_STEP_SUMMARY
done
exit $SUCCESSFUL