farmbot_os/.circleci/config.yml

317 lines
10 KiB
YAML
Raw Normal View History

2017-12-13 12:11:00 -07:00
version: 2.0
defaults: &defaults
docker:
2018-08-22 16:39:19 -06:00
- image: nervesproject/nerves_system_br:1.4.2
2017-12-11 20:28:35 -07:00
2017-12-13 12:11:00 -07:00
install_elixir: &install_elixir
run:
name: Install Elixir
command: |
wget https://github.com/elixir-lang/elixir/releases/download/v1.7.3/Precompiled.zip
2017-12-13 12:11:00 -07:00
unzip -d /usr/local/elixir Precompiled.zip
echo 'export PATH=/usr/local/elixir/bin:$PATH' >> $BASH_ENV
2017-12-11 20:28:35 -07:00
2018-01-03 17:09:13 -07:00
install_hex_archives: &install_hex_archives
run:
name: Install archives
2018-01-03 17:10:34 -07:00
command: |
2018-01-26 10:23:56 -07:00
cd /tmp
2018-01-03 17:10:34 -07:00
mix local.hex --force
mix local.rebar --force
mix archive.install hex nerves_bootstrap "~> 1.2" --force
2018-01-03 17:09:13 -07:00
fetch_and_compile_deps: &fetch_and_compile_deps
run:
name: Fetch and compile Elixir dependencies
2018-01-03 17:10:34 -07:00
command: |
mix deps.get
mix compile
2018-01-03 17:09:13 -07:00
2018-01-05 11:46:58 -07:00
install_arduino: &install_arduino
2018-01-05 11:48:19 -07:00
run:
name: Run setup script
command: bash .circleci/setup-arduino.sh
2018-01-05 11:46:58 -07:00
install_slack_helpers: &install_slack_helpers
run:
name: Install Slack Helpers
command: |
wget https://gist.githubusercontent.com/ConnorRigby/03e722be4be70f8588f5ed74420e4eaa/raw/28a51d8f52ec7d569e8f7f20b83349816ddf63cf/slack_message.ex
2017-12-13 12:11:00 -07:00
jobs:
test:
<<: *defaults
2017-12-31 18:42:26 -07:00
environment:
MIX_ENV: test
2018-01-03 16:48:16 -07:00
MIX_TARGET: host
2018-04-25 17:05:28 -06:00
NERVES_LOG_DISABLE_PROGRESS_BAR: "yes"
2017-12-11 20:28:35 -07:00
steps:
2018-01-05 12:35:47 -07:00
- checkout
2018-01-05 12:27:12 -07:00
- run: git submodule update --init --recursive
2017-12-11 20:43:47 -07:00
- <<: *install_elixir
2018-01-05 12:11:12 -07:00
- restore_cache:
keys:
- v6-arduino-cache-{{ checksum ".circleci/setup-arduino.sh" }}
2018-01-05 12:27:12 -07:00
- <<: *install_arduino
2018-01-03 17:09:13 -07:00
- <<: *install_hex_archives
- restore_cache:
keys:
- v6-dep-cache-{{ checksum "mix.lock.host" }}
2018-01-03 17:09:13 -07:00
- <<: *fetch_and_compile_deps
- save_cache:
key: v6-dep-cache-{{ checksum "mix.lock.host" }}
paths:
- _build/host
2018-01-30 11:59:06 -07:00
- _build/arduino
- deps/host
2018-01-05 12:11:12 -07:00
- save_cache:
key: v6-arduino-cache-{{ checksum ".circleci/setup-arduino.sh" }}
2018-01-05 12:11:12 -07:00
paths:
- ~/arduino-1.8.5
2018-04-18 12:56:08 -06:00
- run:
2018-05-17 11:25:42 -06:00
name: "Credo code static code analysis"
2018-04-18 12:56:08 -06:00
command: mix credo
2018-05-17 11:25:42 -06:00
- run:
name: "Elixir Code formatter"
command: mix format --check-formatted
2017-12-13 12:11:00 -07:00
- run:
2018-01-03 21:58:14 -07:00
command: mix coveralls.circle --exclude farmbot_firmware
2017-12-11 20:28:35 -07:00
2018-01-03 16:48:16 -07:00
firmware_dev:
2017-12-13 12:11:00 -07:00
<<: *defaults
2017-12-13 11:51:27 -07:00
environment:
MIX_TARGET: rpi3
2018-01-03 16:48:16 -07:00
MIX_ENV: dev
2017-12-13 12:22:30 -07:00
ENV: CI
2018-04-25 17:05:28 -06:00
NERVES_LOG_DISABLE_PROGRESS_BAR: "yes"
2017-12-13 11:51:27 -07:00
steps:
2018-01-05 12:35:47 -07:00
- checkout
2018-01-05 12:27:12 -07:00
- run: git submodule update --init --recursive
2018-01-03 16:54:27 -07:00
- <<: *install_elixir
2018-01-05 12:11:12 -07:00
- restore_cache:
keys:
- v6-arduino-cache-{{ checksum ".circleci/setup-arduino.sh" }}
2018-01-05 11:46:58 -07:00
- <<: *install_arduino
2018-01-03 16:54:27 -07:00
- restore_cache:
keys:
- v6-dependency-cache-{{ checksum "mix.lock.rpi3" }}
2018-01-03 17:09:13 -07:00
- <<: *install_hex_archives
- <<: *fetch_and_compile_deps
2018-01-03 16:54:27 -07:00
- run: mix firmware
- save_cache:
key: v6-dependency-cache-{{ checksum "mix.lock.rpi3" }}
2018-01-03 16:54:27 -07:00
paths:
- _build/rpi3
2018-01-30 12:14:48 -07:00
- _build/host
- _build/arduino
- deps/rpi3
2018-01-30 12:14:48 -07:00
- deps/host
2018-01-03 16:54:27 -07:00
- ~/.nerves
2018-01-03 16:48:16 -07:00
- run: mkdir -p artifacts
- run:
name: Decode fwup priv key
command: echo $FWUP_KEY_BASE64 | base64 --decode --ignore-garbage > $NERVES_FW_PRIV_KEY
2017-12-31 18:58:49 -07:00
- run:
2018-01-03 16:48:16 -07:00
name: Sign firmware
command: fwup -S -s $NERVES_FW_PRIV_KEY -i _build/${MIX_TARGET}/${MIX_ENV}/nerves/images/farmbot.fw -o artifacts/farmbot-${MIX_TARGET}-$(cat VERSION)-beta.fw
2017-12-31 18:31:37 -07:00
- save_cache:
2018-05-08 15:19:18 -06:00
key: v6-firmware-{{ .Revision }}-{{ .Environment.CIRCLE_SHA1 }}
2017-12-31 18:31:37 -07:00
paths:
2018-01-03 16:48:16 -07:00
- ./artifacts
firmware_beta:
2018-01-03 16:48:16 -07:00
<<: *defaults
environment:
MIX_TARGET: rpi3
MIX_ENV: prod
ENV: CI
2018-04-25 17:05:28 -06:00
NERVES_LOG_DISABLE_PROGRESS_BAR: "yes"
2018-01-03 16:48:16 -07:00
steps:
2018-01-05 12:35:47 -07:00
- checkout
2018-01-05 12:27:12 -07:00
- run: git submodule update --init --recursive
2018-01-03 16:54:27 -07:00
- <<: *install_elixir
2018-01-05 12:11:12 -07:00
- restore_cache:
keys:
- v6-arduino-cache-{{ checksum ".circleci/setup-arduino.sh" }}
2018-01-05 11:46:58 -07:00
- <<: *install_arduino
2018-01-05 12:27:12 -07:00
- <<: *install_hex_archives
2018-01-03 16:54:27 -07:00
- restore_cache:
keys:
- v6-dependency-cache-{{ checksum "mix.lock.rpi3" }}
2018-03-15 14:23:00 -06:00
- run: MIX_ENV=prod MIX_TARGET=rpi3 mix deps.get
- run: MIX_ENV=prod MIX_TARGET=rpi3 mix compile
- run: MIX_ENV=prod MIX_TARGET=rpi3 mix firmware
2018-01-03 16:54:27 -07:00
- save_cache:
key: v6-dependency-cache-{{ checksum "mix.lock.rpi3" }}
2018-01-03 16:54:27 -07:00
paths:
2018-01-30 12:14:48 -07:00
- _build/rpi3
- _build/host
- _build/arduino
- deps/rpi3
- deps/host
2018-01-03 16:54:27 -07:00
- ~/.nerves
2018-01-03 16:48:16 -07:00
- run: mkdir -p artifacts
2018-01-03 12:09:05 -07:00
- run:
name: Decode fwup priv key
command: echo $FWUP_KEY_BASE64 | base64 --decode --ignore-garbage > $NERVES_FW_PRIV_KEY
- run:
name: Sign firmware
2018-03-15 14:23:00 -06:00
command: MIX_ENV=prod MIX_TARGET=rpi3 fwup -S -s $NERVES_FW_PRIV_KEY -i _build/${MIX_TARGET}/${MIX_ENV}/nerves/images/farmbot.fw -o artifacts/farmbot-${MIX_TARGET}-$(cat VERSION)-beta.fw
2018-01-03 11:56:52 -07:00
- save_cache:
2018-05-08 15:19:18 -06:00
key: v6-firmware-{{ .Revision }}-{{ .Environment.CIRCLE_SHA1 }}
2018-01-03 11:56:52 -07:00
paths:
2018-01-03 12:42:26 -07:00
- ./artifacts
2018-01-03 11:56:52 -07:00
deploy_beta_firmware:
2018-01-03 11:56:52 -07:00
<<: *defaults
steps:
2018-01-03 12:00:03 -07:00
- checkout
2018-05-09 15:25:41 -06:00
- <<: *install_elixir
- <<: *install_slack_helpers
2018-01-04 10:18:46 -07:00
- run:
name: Run setup script
command: bash .circleci/setup-heroku.sh
- add_ssh_keys:
fingerprints:
- "97:92:32:5d:d7:96:e1:fa:f3:6b:f3:bd:d6:aa:84:c6"
2018-01-03 11:56:52 -07:00
- run:
2018-01-03 11:57:59 -07:00
name: Install dependencies
command: |
wget https://github.com/tcnksm/ghr/releases/download/v0.5.4/ghr_v0.5.4_linux_amd64.zip
unzip ghr_v0.5.4_linux_amd64.zip
2018-01-04 10:37:06 -07:00
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
chmod +x ./jq-linux64
2018-01-03 11:56:52 -07:00
- run:
2018-01-03 12:35:30 -07:00
command: grep -Pazo "(?s)(?<=# $(cat VERSION))[^#]+" CHANGELOG.md > RELEASE_NOTES
2018-01-03 11:56:52 -07:00
- restore_cache:
2018-05-08 15:19:18 -06:00
key: v6-firmware-{{ .Revision }}-{{ .Environment.CIRCLE_SHA1 }}
2018-01-03 11:56:52 -07:00
- run:
2018-01-03 15:47:43 -07:00
command: ./ghr -t $GITHUB_TOKEN -u farmbot -r farmbot_os -recreate -prerelease -b "$(cat RELEASE_NOTES)" -c $(git rev-parse --verify HEAD) "v$(cat VERSION)-beta" $PWD/artifacts
2018-01-04 10:19:38 -07:00
- run:
2018-01-04 10:18:46 -07:00
name: Update heroku env
command: |
2018-01-21 15:10:45 -07:00
export OTA_URL=$(wget https://api.github.com/repos/farmbot/farmbot_os/releases -qO- | ./jq-linux64 '.[0].url' | sed -e 's/^"//' -e 's/"$//')
2018-05-09 15:35:54 -06:00
export SLACK_MESSAGE="New Farmbot Beta: $OTA_URL"
2018-01-04 10:54:33 -07:00
heroku config:set BETA_OTA_URL=$OTA_URL --app=farmbot-production
heroku config:set BETA_OTA_URL=$OTA_URL --app=farmbot-staging
elixir slack_message.ex $SLACK_MESSAGE
2017-12-13 11:51:27 -07:00
firmware_prod:
<<: *defaults
environment:
MIX_TARGET: rpi3
MIX_ENV: prod
ENV: CI
2018-04-25 17:05:28 -06:00
NERVES_LOG_DISABLE_PROGRESS_BAR: "yes"
steps:
- checkout
- run: git submodule update --init --recursive
- <<: *install_elixir
- restore_cache:
keys:
- v6-arduino-cache-{{ checksum ".circleci/setup-arduino.sh" }}
- <<: *install_arduino
- <<: *install_hex_archives
- restore_cache:
keys:
- v6-dependency-cache-{{ checksum "mix.lock.rpi3" }}
- run: mix deps.get
- run: mix compile
- run: mix firmware
- save_cache:
key: v6-dependency-cache-{{ checksum "mix.lock.rpi3" }}
paths:
2018-01-30 12:14:48 -07:00
- _build/rpi3
- _build/host
- _build/arduino
- deps/rpi3
- deps/host
- ~/.nerves
- run: mkdir -p artifacts
- run:
name: Decode fwup priv key
command: echo $FWUP_KEY_BASE64 | base64 --decode --ignore-garbage > $NERVES_FW_PRIV_KEY
- run:
name: Sign firmware
command: fwup -S -s $NERVES_FW_PRIV_KEY -i _build/${MIX_TARGET}/${MIX_ENV}/nerves/images/farmbot.fw -o artifacts/farmbot-${MIX_TARGET}-$(cat VERSION).fw
2018-01-08 12:39:32 -07:00
- run:
name: Create img
command: mix firmware.image artifacts/farmbot-${MIX_TARGET}-$(cat VERSION).img
- save_cache:
2018-05-08 15:19:18 -06:00
key: v6-firmware-{{ .Revision }}-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ./artifacts
deploy_prod_firmware:
<<: *defaults
steps:
- checkout
- run:
name: Install dependencies
command: |
wget https://github.com/tcnksm/ghr/releases/download/v0.5.4/ghr_v0.5.4_linux_amd64.zip
unzip ghr_v0.5.4_linux_amd64.zip
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
chmod +x ./jq-linux64
- run:
command: grep -Pazo "(?s)(?<=# $(cat VERSION))[^#]+" CHANGELOG.md > RELEASE_NOTES
- restore_cache:
2018-05-08 15:19:18 -06:00
key: v6-firmware-{{ .Revision }}-{{ .Environment.CIRCLE_SHA1 }}
- run:
2018-01-10 14:12:36 -07:00
command: ./ghr -t $GITHUB_TOKEN -u farmbot -r farmbot_os -recreate -prerelease -draft -delete -b "$(cat RELEASE_NOTES)" -c $(git rev-parse --verify HEAD) "v$(cat VERSION)" $PWD/artifacts
2017-12-13 11:51:27 -07:00
workflows:
version: 2
2017-12-13 12:11:00 -07:00
test_firmware_upload:
2017-12-13 11:51:27 -07:00
jobs:
- test:
2017-12-13 12:11:00 -07:00
context: org-global
2018-01-03 10:28:48 -07:00
filters:
branches:
ignore:
- beta
- master
2018-01-03 16:48:16 -07:00
- firmware_dev:
2017-12-13 12:11:00 -07:00
context: org-global
2018-01-03 16:48:16 -07:00
requires:
- test
2018-01-03 10:28:48 -07:00
filters:
2018-01-03 10:32:04 -07:00
branches:
ignore:
- beta
- master
2018-01-03 10:32:04 -07:00
2018-01-03 14:14:35 -07:00
deploy_beta:
2018-01-03 14:16:35 -07:00
jobs:
- firmware_beta:
2018-01-03 14:16:35 -07:00
context: org-global
2018-01-03 14:03:44 -07:00
filters:
branches:
only:
2018-01-03 14:14:35 -07:00
- beta
- deploy_beta_firmware:
2018-01-03 11:56:52 -07:00
context: org-global
2018-01-03 14:16:35 -07:00
filters:
branches:
only:
- beta
requires:
- firmware_beta
deploy_prod:
jobs:
- firmware_prod:
context: org-global
filters:
branches:
only:
- master
- deploy_prod_firmware:
context: org-global
filters:
branches:
only:
- master
2018-01-03 12:00:03 -07:00
requires:
2018-01-03 16:48:16 -07:00
- firmware_prod