Backup database #232
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 database | |
on: | |
schedule: | |
- cron: '0 1 * * *' | |
workflow_dispatch: | |
jobs: | |
run-heroku-cli-commands: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install Heroku CLI | |
run: curl https://cli-assets.heroku.com/install.sh | sh | |
- name: Authenticate with Heroku | |
env: | |
HEROKU_OAUTH_TOKEN: ${{ secrets.HEROKU_OAUTH_TOKEN }} | |
run: | | |
echo "machine api.heroku.com" > ~/.netrc | |
echo " login ${{ secrets.HEROKU_OAUTH_TOKEN }}" >> ~/.netrc | |
echo " password ${{ secrets.HEROKU_OAUTH_TOKEN }}" >> ~/.netrc | |
echo "machine git.heroku.com" >> ~/.netrc | |
echo " login ${{ secrets.HEROKU_OAUTH_TOKEN }}" >> ~/.netrc | |
echo " password ${{ secrets.HEROKU_OAUTH_TOKEN }}" >> ~/.netrc | |
- name: Run Heroku pg:backups:download | |
run: heroku pg:backups:download --app dluhc-planning-considerations --output data/latest_backup.dump | |
- name: Set up git | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
- name: Commit and push changes | |
run: | | |
git add data/latest_backup.dump | |
if ! git diff-index --quiet HEAD --; then | |
git commit -m "Add latest database backup" | |
git push | |
else | |
echo "No changes to commit" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |