Skip to content

Update DB weekly

Update DB weekly #134

Workflow file for this run

name: Update DB weekly
on: #push
workflow_dispatch:
schedule:
- cron: "2 5 * * THU"
# env:
# NAME: value
jobs:
modify-db:
name: Update json file via Python
runs-on: ubuntu-latest
# Expose step outputs as job outputs
outputs:
changes: ${{ steps.scrapestep.outputs.changes }}
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
steps:
- name: Check-out repo for use
uses: actions/checkout@v4
with:
# repository: universallyleo/ngzkHandshakeScrape
ref: main
# token: ${{ secrets.GITHUB_TOKEN }}
# path: ${{ env.DEVOPS_DIR }}
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.9" # install the python version needed
- name: Install python packages
run: pip install -r requirements.txt
- name: Get current date
id: date
run: echo "today=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Copy original json
run: cp ./src/lib/data/current.json ./src/lib/data/old/backup_at_${{ env.today }}.json
- name: Scrape with Python # run scrape.py, set output var "changes"
id: scrapestep
env:
COOKIES: ${{ secrets.FORTUNE_COOKIES }}
FIREBASE_KEY: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_KEY }}
run: python scrape.py old/backup_at_${{ env.today }}.json
- name: Prepare node if db changes
if: steps.scrapestep.outputs.changes == 'new'
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install npm dependencies if db changes
if: steps.scrapestep.outputs.changes == 'new'
run: npm install
- name: Build if db changes
if: steps.scrapestep.outputs.changes == 'new'
env:
BASE_PATH: "/${{ github.event.repository.name }}"
run: |
npm run build
- name: Upload artifacts from build if db changes
if: steps.scrapestep.outputs.changes == 'new'
uses: actions/upload-pages-artifact@v3
with:
# this should match the `pages` option in your adapter-static options
path: "build/"
- name: Auto commit if db changes
if: steps.scrapestep.outputs.changes == 'new'
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: main
commit_message: Auto DB update ${{ env.today }}
deploy-to-page:
needs: modify-db
# Run job only if there is changes to db
if: needs.modify-db.outputs.changes == 'new'
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
# Specify runner + deployment step
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4 # or specific "vX.X.X" version tag for this action
# commit-if-change: # to run action in own repo, need to use it as a job, not a step
# needs: modify-db
# if: needs.modify-db.outputs.changes == 'new'
# uses: ./.github/workflows/build.yml