Backup Contentful #613
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: Backup Contentful | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * *' # This will run every day at midnight UTC | |
jobs: | |
backup: | |
name: 'Backup Contentful' | |
runs-on: ubuntu-latest | |
env: | |
ENVID: master | |
SPACE: ${{ secrets.TF_VAR_CPD_SPACE_ID }} | |
MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }} | |
steps: | |
- name: Run backup container | |
run: docker run --rm -e token=$MANAGEMENT_TOKEN -e space=$SPACE -e envid=$ENVID -v $PWD:/opt/backup ghcr.io/dfe-digital/contentful-space-export:master | |
- name: Checkout destination repository | |
uses: actions/checkout@v2 | |
with: | |
repository: DFE-Digital/childrens-social-care-cpd-contentful-backup | |
token: ${{ secrets.BACKUP_REPO_PAT }} | |
path: backup | |
- name: Copy output and commit | |
run: | | |
cp `find *.json` backup/prod-contentful-backup-output.json | |
cd backup | |
if git diff --exit-code --quiet; then | |
echo "No changes detected, skipping push" | |
else | |
git config user.name "DfE Robot" | |
git config user.email ${{ secrets.CONTENTFUL_BACKUP_EMAIL }} | |
git add prod-contentful-backup-output.json | |
git commit -m "Upload new backup" | |
git push | |
fi | |