🪣 Empty Develop S3 bucket #20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "🪣 Empty Develop S3 bucket" | |
on: | |
workflow_dispatch: | |
env: | |
AWS_REGION: "${{ secrets.AWS_REGION }}" | |
AWS_ACCOUNT_ID: "${{ secrets.AWS_ACCOUNT_ID }}" | |
AWS_BUCKET_NAME: "${{ secrets.AWS_BUCKET_NAME }}" | |
jobs: | |
empty: | |
name: Empty objects in bucket | |
runs-on: ubuntu-latest | |
# These permissions are needed to interact with GitHub's OIDC Token endpoint. | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: read # This is required for actions/checkout | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Configure AWS credentials from Develop account | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github/AWSGitHubAction | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Remove all objects in bucket | |
run: | | |
aws s3 rm s3://${{ env.AWS_BUCKET_NAME }} --recursive | |
delete-versions: | |
name: Delete all version(s) of objects | |
runs-on: ubuntu-latest | |
needs: [empty] | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Configure AWS credentials from Develop account | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github/AWSGitHubAction | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Delete all versions in bucket | |
run: | | |
aws s3api delete-objects \ | |
--bucket ${{ env.AWS_BUCKET_NAME }} \ | |
--delete "$(aws s3api list-object-versions \ | |
--bucket "${{ env.AWS_BUCKET_NAME }}" \ | |
--output=json \ | |
--query='{Objects: Versions[].{Key:Key,VersionId:VersionId}}')" | |
delete-markers: | |
name: Delete all DeleteMarker(s) of objects | |
runs-on: ubuntu-latest | |
needs: [empty] | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Configure AWS credentials from Develop account | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github/AWSGitHubAction | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Delete DeleteMarkers in bucket | |
run: | | |
aws s3api delete-objects \ | |
--bucket ${{ env.AWS_BUCKET_NAME }} \ | |
--delete "$(aws s3api list-object-versions \ | |
--bucket "${{ env.AWS_BUCKET_NAME }}" \ | |
--output=json \ | |
--query='{Objects: DeleteMarkers[].{Key:Key,VersionId:VersionId}}')" |