-
Notifications
You must be signed in to change notification settings - Fork 20
59 lines (56 loc) · 2.35 KB
/
tests-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
name: SQS Transport Cleanup
on:
schedule:
- cron: '0 0 * * *' # Runs daily at midnight UTC
workflow_dispatch:
jobs:
cleanup:
runs-on: ubuntu-20.04
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# CLI
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }}
# App
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
steps:
- name: Checkout
uses: actions/checkout@v4.2.2
- name: Output AWS CLI version
shell: pwsh
run: aws --version
- name: Clean up S3 Buckets
shell: pwsh
run: |
$dateFilter = ([System.DateTime]::UtcNow).AddHours(-24)
Write-Host "Current time $(([System.DateTime]::UtcNow).ToString()) UTC"
Write-Host "Looking for test buckets older than $($dateFilter.ToString()) UTC starting with 'cli-'"
$bucketList = aws s3api list-buckets | ConvertFrom-Json
$buckets = $bucketList.Buckets | Where-Object { $_.Name.StartsWith('cli-') } | Where-Object { $_.CreationDate -lt $dateFilter }
Write-Output "Found $($buckets.length) buckets"
$buckets | ForEach-Object -Parallel {
Write-Output "Deleting bucket '$($_.Name)'"
aws s3api delete-bucket --bucket $_.Name
}
- name: Clean up SQS queues
shell: pwsh
run: dotnet run --project cleanup/Cleanup.csproj --configuration Release
- name: Notify Slack on failure
if: ${{ failure() }}
shell: pwsh
run: |
$headers = @{
'Authorization' = "Bearer ${{ secrets.SLACK_TOKEN }}"
}
$body = @{
channel = 'aws'
text = "NServiceBus.AmazonSQS clean up has failed: https://github.com/Particular/NServiceBus.AmazonSQS/actions/workflows/tests-cleanup.yml"
username = 'Amazon SQS Transport Test Cleanup'
icon_emoji = 'github_actions'
unfurl_links = false
unfurl_media = false
} | ConvertTo-Json
$result = Invoke-RestMethod -Method POST -Uri https://slack.com/api/chat.postMessage -ContentType "application/json; charset=utf-8" -Headers $headers -Body $body
Write-Output $result
exit $(If ($result.ok) { 0 } Else { 1 })