This repository has been archived by the owner on May 12, 2024. It is now read-only.
Fetch build and deploy #1052
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: Fetch build and deploy | |
on: | |
schedule: | |
- cron: '7 2 * * *' | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v2 | |
- name: Configure pip caching | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Configure scrapedxml caching | |
id: cache-scrapedxml | |
uses: actions/cache@v2 | |
with: | |
path: scrapedxml | |
key: ${{ runner.os }}-scrapedxml | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: pip install -r requirements.txt | |
- name: rsync latest XML | |
run: source rsync-latest.sh | |
- name: build database | |
run: source create-db.sh | |
- name: Record last ran timestamp | |
run: | | |
date -u > last-ran.txt | |
git config user.name "Automated" | |
git config user.email "actions@users.noreply.github.com" | |
git add last-ran.txt | |
timestamp=$(date -u) | |
git commit -m "Last ran at: ${timestamp}" || exit 0 | |
git pull --rebase | |
git push | |
- name: Set variables to decide if we should deploy | |
id: decide_variables | |
run: |- | |
echo "##[set-output name=latest;]$(datasette inspect regmem.db | jq '.regmem.hash' -r)" | |
echo "##[set-output name=deployed;]$(curl -s https://register-of-members-interests.datasettes.com/-/databases.json | jq '.[0].hash' -r)" | |
- name: Set up Cloud Run | |
if: github.event_name == 'workflow_dispatch' || steps.decide_variables.outputs.latest != steps.decide_variables.outputs.deployed | |
uses: google-github-actions/setup-gcloud@v0 | |
with: | |
version: '275.0.0' | |
service_account_email: ${{ secrets.GCP_SA_EMAIL }} | |
service_account_key: ${{ secrets.GCP_SA_KEY }} | |
- name: Deploy to Cloud Run | |
if: github.event_name == 'workflow_dispatch' || steps.decide_variables.outputs.latest != steps.decide_variables.outputs.deployed | |
run: |- | |
gcloud config set run/region us-central1 | |
gcloud config set project datasette-222320 | |
datasette publish cloudrun regmem.db \ | |
--service regmem \ | |
--install "datasette-graphql>=0.12" \ | |
--install datasette-atom \ | |
--install datasette-pretty-json \ | |
--template-dir regmem-deploy/templates \ | |
-m regmem-deploy/metadata.yml \ | |
--memory 2Gi \ | |
--extra-options="--config facet_time_limit_ms:1000" |