Datasette - database dump and Heroku deployment #31
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: Datasette - database dump and Heroku deployment | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
schedule: | |
# * is a special character in YAML so you have to quote this string | |
# Run every Thursday at 8:30 | |
- cron: '30 8 * * 4' | |
permissions: | |
contents: write | |
jobs: | |
scheduled: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: main # Ensures we check out the main branch | |
- name: Remove old database file to avoid the new one being appended | |
run: rm psephology.db | |
- name: Set up Python for Datasette | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.12.4 | |
# Need to do this else sometimes db-to-sqlite conks out | |
# complaining about the psycopg2 missing | |
- name: Install python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install db-to-sqlite psycopg2-binary datasette | |
- name: Get SQLite dump from Heroku DB using db-to-sqlite | |
env: | |
DATABASE_URL: ${{ secrets.PRODUCTION_DATABASE_URL }} | |
run: > | |
db-to-sqlite "$DATABASE_URL" psephology.db | |
--all | |
--skip=ar_internal_metadata | |
--skip=schema_migrations | |
- name: Commit updated DB to this repo | |
run: | | |
touch deploys/`date +"%Y-%m-%dT%H:%M:%S%z"` | |
git config --global user.name 'GitHub Action' | |
git config --global user.email 'psephology-datasette-action@users.noreply.github.com' | |
git remote add heroku https://git.heroku.com/psephology-datasette.git | |
git add psephology.db | |
git add deploys | |
git commit -m "Updated database" | |
git push --force | |
# Ubuntu image used to include heroku CLI, but not in 24.04 | |
# https://github.com/actions/runner-images/issues/10786#issuecomment-2416287770 | |
# https://devcenter.heroku.com/articles/heroku-cli#standalone-installation-with-a-tarball | |
- name: Install Heroku CLI | |
run: | | |
curl https://cli-assets.heroku.com/install.sh | sh | |
- name: Login to Heroku | |
env: | |
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} | |
run: heroku container:login | |
- name: Install heroku builds | |
env: | |
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} | |
run: heroku plugins:install heroku-builds | |
- uses: akhileshns/heroku-deploy@v3.13.15 # This is the action | |
with: | |
heroku_api_key: ${{secrets.HEROKU_API_KEY}} | |
heroku_app_name: "psephology-datasette" #Must be unique in Heroku | |
heroku_email: ${{secrets.HEROKU_EMAIL}} |