-
Notifications
You must be signed in to change notification settings - Fork 17
111 lines (99 loc) · 4.5 KB
/
orphan_vms.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
# 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}}"