-
Notifications
You must be signed in to change notification settings - Fork 130
48 lines (48 loc) · 1.73 KB
/
cleanup_buckets.yaml
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
name: Cleanup Buckets
on:
push:
branches:
- 'hm/fix-cleanup-buckets-job'
schedule:
- cron: "0 * * * *"
jobs:
cleanup-buckets:
permissions:
contents: read
id-token: write
runs-on:
- ubuntu-latest
env:
AWS_DEFAULT_REGION: "us-west-2"
steps:
- name: Login to docker
uses: docker/login-action@v2
with:
username: ${{ secrets.NEXUS_USERNAME }}
password: ${{ secrets.NEXUS_PASSWORD }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: ${{ secrets.AWS_DOCS_SITE_ROLE }}
aws-region: us-west-2
- name: Cleanup Buckets
run: |
set -euxo pipefail
sudo apt-get update && sudo apt-get install jq
bucket_list=$(docker run -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN amazon/aws-cli s3api list-buckets | jq '.Buckets | .[].Name' -r)
if echo $bucket_list | grep -q "docs-d2iq-com-pr-"; then
buckets=$(echo $bucket_list | grep "docs-d2iq-com-pr-")
for bucket in $buckets; do
found=false
for pr in $bucket; do
if [[ $bucket == *"$pr"* ]]; then
found=true
break
fi
done
if [ "$found" = false ] ; then
docker run -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN amazon/aws-cli s3 rb s3://$bucket --force
fi
done
fi
shell: bash