From a5675f909c9ee01bcf458f296096148cf05559f8 Mon Sep 17 00:00:00 2001 From: msj Date: Fri, 15 Mar 2024 14:47:57 -0400 Subject: [PATCH] Separate court call scrape into its own action --- .github/workflows/court_calls.yml | 116 ++++++++++++++++++++++++++++++ .github/workflows/nightly.yml | 4 -- 2 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/court_calls.yml diff --git a/.github/workflows/court_calls.yml b/.github/workflows/court_calls.yml new file mode 100644 index 0000000..adff019 --- /dev/null +++ b/.github/workflows/court_calls.yml @@ -0,0 +1,116 @@ +name: Court call scrape + +on: + workflow_dispatch: + schedule: + - cron: '15 10 * * *' + +jobs: + scrape: + name: Scrape court calls + runs-on: ubuntu-latest + + steps: + - name: Set current date as env variable + run: echo "BEGIN_COURTS_RUN=$(date +'%s')" >> $GITHUB_ENV + - uses: actions/checkout@v3 + - name: upgrade sqlite3 + run: | + sudo apt-get update + sudo apt-get install sqlite3 + + - name: Install requirements + run: | + pip install -U pyopenssl cryptography + pip install -r requirements.txt + + - name: Download latest database zip + uses: robinraju/release-downloader@v1.8 + with: + latest: true + tag: "nightly" + fileName: "*.db.zip" + + - name: Decrypt database + run: | + unzip -P '${{ secrets.CASE_DB_PW }}' cases.db.zip && rm cases.db.zip + + - name: Scrape court calls + run: | + make -f Makefile.courtcalls all + + - name: Setup database for upload + run: | + zip -P '${{ secrets.CASE_DB_PW }}' cases.db.zip cases.db + + - name: Upload new release + uses: WebFreak001/deploy-nightly@v3.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: https://uploads.github.com/repos/datamade/court-scrapers/releases/131985702/assets{?name,label} + release_id: 131985702 + asset_path: ./cases.db.zip + asset_name: cases.db.zip + asset_content_type: application/zip # required by GitHub API + max_releases: 7 + + - name: Keepalive + uses: gautamkrishnar/keepalive-workflow@v1 + + deploy: + name: Deploy to Heroku + needs: scrape + runs-on: ubuntu-latest + + env: + HEROKU_ORGANIZATION: ${{ secrets.HEROKU_ORG }} + + steps: + - uses: actions/checkout@v3 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Download latest database zip + uses: robinraju/release-downloader@v1.8 + with: + latest: true + tag: "nightly" + fileName: "*.db.zip" + + - name: Decrypt database + run: | + unzip -P '${{ secrets.CASE_DB_PW }}' cases.db.zip + + - name: Install heroku-builds plugin + run: | + heroku plugins:install heroku-builds + + - name: Login to Heroku CLI + uses: akhileshns/heroku-deploy@v3.12.14 + with: + heroku_api_key: ${{ secrets.HEROKU_API_KEY }} + heroku_app_name: "" + heroku_email: ${{ secrets.HEROKU_EMAIL }} + justlogin: true + + - name: Install Datasette plugins + run: | + datasette install datasette-auth-passwords datasette-auth-tokens + + - name: Get hashed Datasette password + run: | + # Store hash as an environment variable + hash=$(echo '${{ secrets.DATASETTE_INSTANCE_PW }}' \ + | datasette hash-password --no-confirm); \ + echo "hash=$hash" >> $GITHUB_ENV + + - name: Deploy Datasette instance to Heroku + run: | + datasette publish heroku cases.db \ + -n court-scraper \ + -m metadata.json \ + --setting sql_time_limit_ms 60000 \ + --install datasette-auth-passwords \ + --plugin-secret datasette-auth-passwords root_password_hash '${{ env.hash }}' diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 3176c12..e5a3130 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -40,10 +40,6 @@ jobs: echo $BEGIN_COURTS_RUN make get_new_records - - name: Scrape court calls - run: | - make -f Makefile.courtcalls all - - name: Setup database for upload run: | zip -P '${{ secrets.CASE_DB_PW }}' cases.db.zip cases.db