diff --git a/.circleci/config.yml b/.circleci/config.yml index 2e62d34..eee65de 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,6 +11,62 @@ jobs: name: Run shellcheck command: make shellcheck + - run: + name: Insert version + command: | + if [ ! -z "$CIRCLE_TAG" ]; then + sed -i "s/dirty/$CIRCLE_TAG/g" flash + fi + + - run: + name: Show version + command: ./flash --version + - run: name: Run BATS tests command: make test + + deploy: + machine: true + + steps: + - checkout + + - run: + name: Insert version + command: sed -i "s/dirty/$CIRCLE_TAG/g" flash + + - run: + name: Show version + command: ./flash --version + + - run: + name: Run BATS tests with version + command: make test + + - run: + name: Deploy + command: | + curl -sSL https://github.com/tcnksm/ghr/releases/download/v0.5.4/ghr_v0.5.4_linux_amd64.zip -o ghr.zip + unzip ghr.zip + mkdir output + sha256sum flash > flash.sha256 + cp flash* output + ./ghr -u hypriot $CIRCLE_TAG output/ + +workflows: + version: 2 + build-n-deploy: + jobs: + - build: + filters: + tags: + only: /.*/ + - deploy: + requires: + - build + filters: + tags: + only: /^.*/ + branches: + ignore: /.*/ diff --git a/.gitignore b/.gitignore index 8ebd5ea..eccdaba 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ image* *.gz loo *.dmg +wifi.yml +flash-wifi.sh diff --git a/Makefile b/Makefile index 3449d17..b80ae7f 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ TMP_DIR ?= "/tmp/hypriot-flash" test: build mkdir -p $(TMP_DIR) - docker run --privileged -ti -v $(shell pwd):/code -v $(TMP_DIR):/tmp flash npm test + docker run --privileged -ti -v $(shell pwd):/code -v $(TMP_DIR):/tmp -e CIRCLE_TAG flash npm test rm -rf $(TMP_DIR) shellcheck: diff --git a/flash b/flash index 6186114..9a6d367 100755 --- a/flash +++ b/flash @@ -13,6 +13,12 @@ error() exit "$2" } +version() +{ + echo "dirty" + exit 0 +} + usage() { cat << EOF @@ -62,7 +68,7 @@ do delim="" case "${arg}" in --help) args="${args}-h ";; - --verbose) args="${args}-v ";; + --version) args="${args}-v ";; --config) args="${args}-c ";; --hostname) args="${args}-n ";; --ssid) args="${args}-s ";; @@ -81,9 +87,10 @@ done # reset the translated args eval set -- "$args" # now we can process with getopt -while getopts ":hc:n:s:p:C:l:d:fu:m:" opt; do +while getopts ":h:vc:n:s:p:C:l:d:fu:m:" opt; do case $opt in h) usage ;; + v) version ;; c) CONFIG_FILE=$OPTARG ;; C) BOOT_CONF=$OPTARG ;; n) SD_HOSTNAME=$OPTARG ;; diff --git a/test/version.bats b/test/version.bats new file mode 100644 index 0000000..4919d0c --- /dev/null +++ b/test/version.bats @@ -0,0 +1,12 @@ +load test_helper + +expected=$CIRCLE_TAG +if [ -z "$CIRCLE_TAG" ]; then + expected=dirty +fi + +@test "flash --version shows version $expected" { + run ./flash --version + [ "$status" -eq 0 ] + assert_output_contains $expected +}