pokeapi-api-data/updater/cmd.bash

60 lines
2.3 KiB
Bash
Raw Permalink Normal View History

2018-09-15 10:45:12 +02:00
#!/usr/bin/env bash
[ -z "${REPO_POKEAPI}" ] && { echo "Need to set REPO_POKEAPI"; exit 1; }
[ -z "${REPO_DATA}" ] && { echo "Need to set REPO_DATA"; exit 1; }
[ -z "${BRANCH_NAME}" ] && { echo "Need to set BRANCH_NAME"; exit 1; }
2020-07-11 13:31:00 +02:00
[ -z "${REPO_POKEAPI_CHECKOUT_OBJECT:=master}" ] && { echo "REPO_POKEAPI_CHECKOUT_OBJECT not set, defaulting to \`master\`"; }
[ -z "${REPO_APIDATA_CHECKOUT_OBJECT:=master}" ] && { echo "REPO_APIDATA_CHECKOUT_OBJECT not set, defaulting to \`master\`"; }
[ -z "${TEST:=true}" ]
declare -r COMMIT_AND_PUSH="${COMMIT_AND_PUSH:-false}"
2018-09-15 10:45:12 +02:00
set -e
set -o pipefail
set -x
2020-04-25 12:32:01 +02:00
dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2375 &> /dev/null &
2018-09-15 10:45:12 +02:00
2020-07-11 13:31:00 +02:00
git clone "$REPO_POKEAPI" pokeapi
git clone "$REPO_DATA" api-data
2018-09-15 10:45:12 +02:00
# set up the pokeapi side
cd pokeapi
2020-07-11 13:31:00 +02:00
git checkout "$REPO_POKEAPI_CHECKOUT_OBJECT"
git submodule init
git submodule update --remote
2018-09-15 10:45:12 +02:00
docker compose -f docker-compose.yml -f docker-compose-dev.yml up -d
docker compose exec -T app python manage.py migrate --settings=config.docker-compose
docker compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker-compose'
2018-09-15 10:45:12 +02:00
# set up the data side
cd ../api-data
git checkout "$REPO_APIDATA_CHECKOUT_OBJECT"
git branch -D "$BRANCH_NAME" || true
git branch "$BRANCH_NAME"
git checkout "$BRANCH_NAME"
2024-10-16 03:47:14 +02:00
python -m venv .venv
source .venv/bin/activate
2024-05-07 21:40:29 +02:00
pip install 'pokeapi-ditto==1.0.3'
rm -rf ./data
2018-09-15 10:45:12 +02:00
ditto clone --src-url http://localhost/ --dest-dir ./data
2018-09-17 08:40:24 +02:00
# (╯°□°)╯ *always* assume magikarp failed and grab it again #clowntown
ditto clone --src-url http://localhost/ --dest-dir ./data --select pokemon/129
2018-09-17 08:40:24 +02:00
ditto analyze --data-dir ./data
2024-06-18 07:12:52 +02:00
echo "$(tree data/api/v2 | tail -n 1) generated"
2018-09-15 10:45:12 +02:00
# commit and push
if [ "$COMMIT_AND_PUSH" = 'true' ]; then
[ -z "${COMMIT_NAME}" ] && { echo "Need to set COMMIT_NAME"; exit 1; }
[ -z "${COMMIT_EMAIL}" ] && { echo "Need to set COMMIT_EMAIL"; exit 1; }
[ -z "${COMMIT_MESSAGE}" ] && { echo "Need to set COMMIT_MESSAGE"; exit 1; }
git add data
git config user.name "$COMMIT_NAME"
git config user.email "$COMMIT_EMAIL"
if ! git commit -m "$COMMIT_MESSAGE"; then
echo "The generated data doesn't bring any updates"
exit 2
fi
git push -fu origin "$BRANCH_NAME"
fi