Skip to content

Commit

Permalink
Add --version option
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanScherer committed Jun 2, 2018
1 parent 17040af commit d6ce719
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
56 changes: 56 additions & 0 deletions .circleci/config.yml
Expand Up @@ -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: /.*/
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -8,3 +8,5 @@ image*
*.gz
loo
*.dmg
wifi.yml
flash-wifi.sh
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -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:
Expand Down
11 changes: 9 additions & 2 deletions flash
Expand Up @@ -13,6 +13,12 @@ error()
exit "$2"
}

version()
{
echo "dirty"
exit 0
}

usage()
{
cat << EOF
Expand Down Expand Up @@ -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 ";;
Expand All @@ -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 ;;
Expand Down
12 changes: 12 additions & 0 deletions 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
}

0 comments on commit d6ce719

Please sign in to comment.