From 504c0e2704d2c3cb63c15a52319597bd0d7ba5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Fri, 1 May 2020 22:58:22 +0200 Subject: [PATCH 1/5] play: staging deployment --- .circleci/config.yml | 14 ++++++-------- scripts/transform.sh | 9 +++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 scripts/transform.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index d20c7526ed..144d8d21f7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,12 +10,7 @@ commands: description: Run Ditto in order to transform the base URL to https://pokeapi.co instead of 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: bash scripts/transform.sh jobs: test: @@ -31,7 +26,8 @@ jobs: - run: 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: 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/test-staging?circle-token=$CIRCLECI_API_TOKEN" workflows: version: 2 @@ -43,4 +39,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..fd13e895fc --- /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}" = 'test-staging' ]; then # Change to `staging` + ~/.local/bin/ditto transform --base-url='https://pokeapi-test-b6137.firebaseapp.com' --src-dir=data --dest-dir=_gen +fi From 20b5e6f5ab7ee562926b3ed5ab5d5de194987cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Fri, 1 May 2020 23:00:52 +0200 Subject: [PATCH 2/5] play: add quotes --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 144d8d21f7..91b5e1d4fe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,7 +27,7 @@ jobs: - store_artifacts: path: _gen.tar.gz # Trigger a new build of the deploy job of the deploy project - - run: 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/test-staging?circle-token=$CIRCLECI_API_TOKEN" + - run: '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/test-staging?circle-token=$CIRCLECI_API_TOKEN"' workflows: version: 2 From 1b219772910cd296203919ba04b0ff71d3e55744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Fri, 1 May 2020 23:09:25 +0200 Subject: [PATCH 3/5] refactor: change branch/debug --- .circleci/config.yml | 2 +- scripts/transform.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 91b5e1d4fe..8bf8fd5d37 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,7 +10,7 @@ commands: description: Run Ditto in order to transform the base URL to https://pokeapi.co instead of localhost steps: - run: pip install --user -r requirements.txt - - run: bash scripts/transform.sh + - run: bash -x scripts/transform.sh jobs: test: diff --git a/scripts/transform.sh b/scripts/transform.sh index fd13e895fc..e59387e6a9 100644 --- a/scripts/transform.sh +++ b/scripts/transform.sh @@ -4,6 +4,6 @@ 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}" = 'test-staging' ]; then # Change to `staging` +elif [ "${CIRCLE_BRANCH}" = 'staging' ]; then ~/.local/bin/ditto transform --base-url='https://pokeapi-test-b6137.firebaseapp.com' --src-dir=data --dest-dir=_gen fi From cffc0fd6831d6fbc48e15ee5bd156caf49992a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Sat, 2 May 2020 15:54:16 +0200 Subject: [PATCH 4/5] docs: document steps --- .circleci/config.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8bf8fd5d37..345f8b6100 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,10 +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: bash -x scripts/transform.sh + - 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: @@ -23,11 +27,15 @@ jobs: steps: - checkout - ditto-transform - - run: tar czf _gen.tar.gz _gen/* + - run: + name: Pack the transofrmed data in a .tar.gz + command: tar czf _gen.tar.gz _gen/* - store_artifacts: path: _gen.tar.gz # Trigger a new build of the deploy job of the deploy project - - run: '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/test-staging?circle-token=$CIRCLECI_API_TOKEN"' + - 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/test-staging?circle-token=$CIRCLECI_API_TOKEN"' workflows: version: 2 From aec54bd9c024d75525417524c287ee9168c76eab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Sat, 2 May 2020 16:02:03 +0200 Subject: [PATCH 5/5] fix: typo --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 345f8b6100..ec6b912630 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,7 +28,7 @@ jobs: - checkout - ditto-transform - run: - name: Pack the transofrmed data in a .tar.gz + name: Pack the transformed data in a .tar.gz command: tar czf _gen.tar.gz _gen/* - store_artifacts: path: _gen.tar.gz