diff --git a/.circleci/config.yml b/.circleci/config.yml index d20c7526ed..b4eacac4a9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,15 +7,14 @@ executors: commands: ditto-transform: - description: Run Ditto in order to transform the base URL to https://pokeapi.co instead of localhost + description: Run Ditto in order to transform the BASE_URL instead of http://localhost steps: - - run: pip install --user -r requirements.txt - - run: - command: | - ~/.local/bin/ditto transform \ - --base-url='https://pokeapi.co' \ - --src-dir=data \ - --dest-dir=_gen + - run: + name: Install requirements.txt + command: pip install --user -r requirements.txt + - run: + name: Transform api-data's JSON files to have the correct BASE_URL instead of http://localhost + command: bash -x scripts/transform.sh jobs: test: @@ -28,10 +27,15 @@ jobs: steps: - checkout - ditto-transform - - run: tar czf _gen.tar.gz _gen/* + - run: + name: Pack the transformed data in a .tar.gz + command: tar czf _gen.tar.gz _gen/* - store_artifacts: path: _gen.tar.gz - - run: "curl -X POST --header \"Content-Type: application/json\" https://circleci.com/api/v1.1/project/github/PokeAPI/deploy/build?circle-token=$CIRCLECI_API_TOKEN" + # Trigger a new build of the deploy job of the deploy project + - run: + name: Trigger a deploy of the deploy project passing the desired environment/location to deploy to + command: 'curl --header "Content-Type: application/json" --data "{\"build_parameters\": {\"deploy_location\": \"$CIRCLE_BRANCH\", \"CIRCLE_JOB\": \"deploy\"}}" --request POST "https://circleci.com/api/v1.1/project/github/PokeAPI/deploy/tree/master?circle-token=$CIRCLECI_API_TOKEN"' workflows: version: 2 @@ -43,4 +47,6 @@ workflows: - test filters: branches: - only: master + only: + - master + - staging diff --git a/scripts/transform.sh b/scripts/transform.sh new file mode 100644 index 0000000000..e59387e6a9 --- /dev/null +++ b/scripts/transform.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# Runs in CircleCI +# Replaces all the http://localhost links of api-data to match the corresponding deployment location. + +if [ "${CIRCLE_BRANCH}" = 'master' ]; then # https://stackoverflow.com/a/2013589/3482533 + ~/.local/bin/ditto transform --base-url='https://pokeapi.co' --src-dir=data --dest-dir=_gen +elif [ "${CIRCLE_BRANCH}" = 'staging' ]; then + ~/.local/bin/ditto transform --base-url='https://pokeapi-test-b6137.firebaseapp.com' --src-dir=data --dest-dir=_gen +fi