Skip to content

Cleanup Buckets

Cleanup Buckets #8884

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