.github/workflows/aligulac-import.yaml #26
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
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 20 * * 5' | |
#permissions: | |
# contents: write | |
jobs: | |
import_aligulac: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:16-alpine | |
ports: | |
- 5432:5432 | |
env: | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_INITDB_ARGS: "--no-clean --no-sync --set wal_level=minimal" | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- name: Install postgres client | |
run: sudo apt-get install -y postgresql-client | |
- name: Postgres client version | |
run: psql --version | |
- name: Install yq | |
run: sudo snap install yq --channel=v4/stable | |
- name: Check out repository code | |
uses: actions/checkout@v4 | |
- name: Download Aligulac dump | |
run: wget -qO- http://static.aligulac.com/aligulac.sql.gz | gzip -d > aligulac.sql | |
- name: Modify dump for faster import | |
run: sed -i -e '/^CREATE TABLE/ s//CREATE UNLOGGED TABLE/g' aligulac.sql | |
- name: grep changes | |
run: grep UNLOGGED aligulac.sql | |
- name: DB Settings for faster import | |
run: PGPASSWORD=postgres psql -h localhost -p 5432 -d postgres -U postgres -c "ALTER SYSTEM SET wal_level = minimal;" -c "ALTER SYSTEM SET fsync = off;" -c "ALTER SYSTEM SET full_page_writes = off;" -c "ALTER SYSTEM SET synchronous_commit = off;" -c "SELECT pg_reload_conf();" -c "SET max_parallel_maintenance_workers TO 2;" -c "SET maintenance_work_mem TO '1 GB';" -c "SHOW wal_level;" | |
- name: Import Aligulac DB | |
run: PGPASSWORD=postgres psql -h localhost -p 5432 -d postgres -U postgres -f aligulac.sql | |
- name: Import GuessTheSC2Pro Fixes | |
run: PGPASSWORD=postgres psql -h localhost -p 5432 -d postgres -U postgres -f db_import/data-fixup.sql | |
- name: Export player data | |
run: PGPASSWORD=postgres psql -h localhost -p 5432 -d postgres -U postgres --csv -f db_import/top500-earnings.sql > result.csv | |
- name: Display CSV | |
run: cat result.csv | |
- name: Convert to JSON | |
run: yq result.csv -p=csv -o=json > players.json | |
- name: Display JSON | |
run: cat players.json | |
- name: Truncated 400 Player Json | |
run: yq '.[0:400]' players.json -o=json > players400.json && yq 'length' players400.json | |
- name: Truncated 250 Player Json | |
run: yq '.[0:250]' players.json -o=json > players250.json && yq 'length' players250.json | |
- name: Turn Json files into JS | |
run: sed -i -e '1s/^/var players = /' -e '$a;' players400.json && sed -i -e '1s/^/var players = /' -e '$a;' players250.json | |
- name: Rename to js | |
run: mv players400.json players400.js && mv players250.json players250.js | |
- name: Print players250 | |
run: cat players250.js | |
- name: Move to correct location | |
run: mv players400.js assets/js/players400.js && mv players250.js assets/js/players250.js | |
- name: Git Status | |
run: git config --global diff.algorithm patience && git status && git diff assets/js/players250.js | |
#- name: Commit changes | |
# run: | | |
# git config --global user.name 'GH Action Bot' | |
# git config --global user.email '[email protected]' | |
# git add TODO | |
# git commit -m "Automated Player Update" | |
# git push |