S3 backup #1472
This file contains hidden or 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: S3 backup | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 6 * * *" | |
| permissions: | |
| id-token: write | |
| contents: read | |
| jobs: | |
| s3-backup: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| fetch-depth: 0 # retrieve all history | |
| persist-credentials: false | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8 # v5.1.0 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_S3_BACKUP_IAM_ROLE_ARN }} | |
| role-session-name: S3Backup | |
| aws-region: ca-central-1 | |
| - name: Upload zip to S3 bucket | |
| run: | | |
| ZIP_FILE=`basename ${{ github.repository }}`-`date '+%Y-%m-%d'`.zip | |
| zip -rq "${ZIP_FILE}" . | |
| aws s3 cp "${ZIP_FILE}" s3://${{ secrets.AWS_S3_BACKUP_BUCKET }}/${{ github.repository }}/"${ZIP_FILE}" | |
| - name: Notify Slack channel if this job failed | |
| if: ${{ failure() }} | |
| run: | | |
| json='{"text":"S3 backup failed in <https://github.com/${{ github.repository }}>!"}' | |
| curl -X POST -H 'Content-type: application/json' --data "$json" ${{ secrets.SLACK_NOTIFY_WEBHOOK }} |