-
Notifications
You must be signed in to change notification settings - Fork 21
98 lines (90 loc) · 3.76 KB
/
stackhpc-ci-cleanup.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
---
name: Clean up stale CI resources
on:
schedule:
# Every 2 hours at quarter past
- cron: '15 0/2 * * *'
jobs:
ci-cleanup:
name: Clean up stale CI resources
if: github.repository == 'stackhpc/stackhpc-kayobe-config'
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: src/kayobe-config
- name: Setup Python
uses: actions/setup-python@v5
- name: Generate clouds.yaml
run: |
cat << EOF > clouds.yaml
${{ secrets.CLOUDS_YAML }}
EOF
- name: Determine OpenStack release
id: openstack_release
run: |
BRANCH=$(awk -F'=' '/defaultbranch/ {print $2}' src/kayobe-config/.gitreview)
echo "openstack_release=${BRANCH}" | sed -E "s,(stable|unmaintained)/,," >> $GITHUB_OUTPUT
- name: Install OpenStack client
run: |
pip install python-openstackclient -c https://releases.openstack.org/constraints/upper/${{ steps.openstack_release.outputs.openstack_release }}
- name: Clean up aio instances over 3 hours old
run: |
result=0
changes_before=$(date -Imin -d -3hours)
for status in ACTIVE BUILD ERROR SHUTOFF; do
for instance in $(openstack server list --tags skc-ci-aio --os-compute-api-version 2.66 --format value --column ID --changes-before $changes_before --status $status); do
echo "Cleaning up $status instance $instance"
openstack server show $instance
if ! openstack server delete $instance; then
echo "Failed to delete $status instance $instance"
result=1
fi
done
done
exit $result
env:
OS_CLOUD: openstack
OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }}
OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}
- name: Clean up host image builder instances over 5 hours old
run: |
result=0
changes_before=$(date -Imin -d -5hours)
for status in ACTIVE BUILD ERROR SHUTOFF; do
for instance in $(openstack server list --tags skc-host-image-build --os-compute-api-version 2.66 --format value --column ID --changes-before $changes_before --status $status); do
echo "Cleaning up $status instance $instance"
openstack server show $instance
if ! openstack server delete $instance; then
echo "Failed to delete $status instance $instance"
result=1
fi
done
done
exit $result
env:
OS_CLOUD: openstack
OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }}
OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}
- name: Send message to Slack via Workflow Builder
uses: slackapi/[email protected]
with:
payload: |
{
"channel-id": "${{ env.SLACK_CHANNEL_ID }}",
"inputs": "${{ env.INPUTS }}",
"message": "${{ env.MESSAGE }}",
"results-url": "${{ env.RESULTS_URL }}",
"workflow-url": "${{ env.WORKFLOW_URL }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# #release-train-alerts
SLACK_CHANNEL_ID: C03B28HRP53
INPUTS: "N/A"
MESSAGE: "SKC CI Cleanup workflow failed :sob:"
RESULTS_URL: "N/A"
WORKFLOW_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
if: failure()