Skip to content

Commit

Permalink
add a workflow to publish db
Browse files Browse the repository at this point in the history
  • Loading branch information
cldellow committed Jan 16, 2024
1 parent 951e3b5 commit d71fa48
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Create DB
run: ./create-qrank-db
# - name: Create DB
# run: ./create-qrank-db

# TODO: overwrite the existing release's binary with the new file
- name: Publish DB
run: ./publish-qrank-db
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ They publish the dataset as a gzipped CSV file, [qrank.csv.gz](https://qrank.wmc
This repository republishes the data as a SQLite database with an index, so that random-access queries are fast.

You can download [qrank.db here](https://github.com/hikeratlas/qrank/releases/download/latest/qrank.db).

4 changes: 2 additions & 2 deletions create-qrank-db
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ vacuum;
EOF
}

ensure_qrank_csv
time ensure_qrank_csv

rm -f qrank.db
do_the_thing | sqlite3 qrank.db
time ( do_the_thing | sqlite3 qrank.db )
39 changes: 39 additions & 0 deletions publish-qrank-db
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -euo pipefail

RELEASE_ID=137136562

list_existing() {
curl --silent --fail -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/hikeratlas/qrank/releases/${RELEASE_ID}/assets" |
jq .[].id
}

delete_existing() {
while read -r asset_id; do
echo "deleting ${asset_id}"
curl --silent --fail -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/hikeratlas/qrank/releases/assets/${asset_id}"
done < <(list_existing)
}

publish() {
curl --silent --fail -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"https://uploads.github.com/repos/hikeratlas/qrank/releases/${RELEASE_ID}/assets?name=qrank.db" \
--data-binary "@README.md"
}

delete_existing
publish

0 comments on commit d71fa48

Please sign in to comment.