check_orphan_vms #901
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# Format Ref: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions | |
# Required to un-FUBAR default ${{github.workflow}} value | |
name: check_orphan_vms | |
on: | |
# Note: This only applies to the default branch. | |
schedule: | |
# Nobody is around to respond to weekend e-mails | |
- cron: '59 23 * * 0-4' | |
# Debug: Allow triggering job manually in github-actions WebUI | |
workflow_dispatch: {} | |
env: | |
# Debug-mode can reveal secrets, only enable by a secret value. | |
# Ref: https://docs.github.com/en/actions/managing-workflow-runs/enabling-debug-logging#enabling-runner-diagnostic-logging | |
ACTIONS_STEP_DEBUG: '${{ secrets.ACTIONS_STEP_DEBUG }}' | |
ACTIONS_RUNNER_DEBUG: '${{ secrets.ACTIONS_RUNNER_DEBUG }}' | |
# CSV listing of e-mail addresses for delivery failure or error notices | |
RCPTCSV: [email protected],[email protected] | |
jobs: | |
orphan_vms: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
# Avoid duplicating cron-fail_addrs.csv | |
- uses: actions/checkout@v4 | |
with: | |
repository: containers/podman | |
path: '_podman' | |
persist-credentials: false | |
- name: Collect listing of orphaned VMs | |
env: | |
GCPNAME: ${{ secrets.GCPNAME }} | |
GCPJSON: ${{ secrets.GCPJSON }} | |
AWSINI: ${{ secrets.AWSINI }} | |
GCPPROJECT: 'libpod-218412' | |
run: | | |
export GCPNAME GCPJSON AWSINI GCPPROJECT | |
export GCPPROJECTS=$(grep -E -vx '^#+.*$' $GITHUB_WORKSPACE/gcpprojects.txt | tr -s '[:space:]' ' ') | |
podman run --rm \ | |
-e GCPNAME -e GCPJSON -e AWSINI -e GCPPROJECT -e GCPPROJECTS \ | |
quay.io/libpod/orphanvms:latest \ | |
> /tmp/orphanvms_output.txt | |
- if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: orphanvms_output | |
path: /tmp/orphanvms_output.txt | |
- name: Count number of orphaned VMs | |
id: orphans | |
run: | | |
count=$(grep -E -x '\* VM .+' /tmp/orphanvms_output.txt | wc -l) | |
# Assist with debugging job (step-outputs are otherwise hidden) | |
printf "Orphan VMs count:%d\n" $count | |
if [[ "$count" =~ ^[0-9]+$ ]]; then | |
printf "count=%d\n" $count >> $GITHUB_OUTPUT | |
else | |
printf "count=0\n" >> $GITHUB_OUTPUT | |
fi | |
- if: steps.orphans.outputs.count > 0 | |
shell: bash | |
run: | | |
set -eo pipefail | |
( | |
echo "Detected ${{ steps.orphans.outputs.count }} Orphan VM(s):" | |
echo "" | |
cat /tmp/orphanvms_output.txt | |
echo "" | |
echo "# Source: ${{ github.workflow }} workflow on ${{ github.repository }}." | |
# Separate content from sendgrid.com automatic footer. | |
echo "" | |
echo "" | |
) > /tmp/email_body.txt | |
- if: steps.orphans.outputs.count > 0 | |
name: Send orphan notification e-mail | |
# Ref: https://github.com/dawidd6/action-send-mail | |
uses: dawidd6/[email protected] | |
with: | |
server_address: ${{ secrets.ACTION_MAIL_SERVER }} | |
server_port: 465 | |
username: ${{ secrets.ACTION_MAIL_USERNAME }} | |
password: ${{ secrets.ACTION_MAIL_PASSWORD }} | |
subject: Orphaned CI VMs detected | |
to: ${{env.RCPTCSV}} | |
from: ${{ secrets.ACTION_MAIL_SENDER }} | |
body: file:///tmp/email_body.txt | |
- if: failure() | |
name: Send error notification e-mail | |
uses: dawidd6/[email protected] | |
with: | |
server_address: ${{secrets.ACTION_MAIL_SERVER}} | |
server_port: 465 | |
username: ${{secrets.ACTION_MAIL_USERNAME}} | |
password: ${{secrets.ACTION_MAIL_PASSWORD}} | |
subject: Github workflow error on ${{github.repository}} | |
to: ${{env.RCPTCSV}} | |
from: ${{secrets.ACTION_MAIL_SENDER}} | |
body: "Job failed: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" |