diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..1f96a03 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,34 @@ + + +**Snap version** (use `snapctl -v`): + +**Environment**: +- **Cloud provider or hardware configuration**: +- **OS** (e.g. from /etc/os-release): +- **Kernel** (e.g. `uname -a`): +- **Relevant tools** (e.g. plugins used with Snap): +- **Others** (e.g. deploying with Ansible): + + +**What happened**: + + +**What you expected to happen**: + + +**Steps to reproduce it** (as minimally and precisely as possible): + +1. +2. +3. + + +**Anything else do we need to know** (e.g. issue happens only occasionally): diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..f7d30d0 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,21 @@ + +Fixes # + +Summary of changes: +- +- +- + +How to verify it: +- + +Testing done: +- + +A picture of a snapping turtle (not required but encouraged): +- diff --git a/.gitignore b/.gitignore index a946c69..acc50ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ +# File managed by pluginsync +# +# NOTE: please commit OS/Editor specific settings in your .gitignore_global +# .idea +# .DS_Store +# # Compiled Object files, Static and Dynamic libs (Shared Objects) *.o *.a @@ -21,17 +27,15 @@ _testmain.go *.exe *.test -.idea -tmp/ -*.tmp -scratch/ -build/ -*.swp +*.prof + +# Output of the go coverage tool +*.out profile.cov -gin-bin # we don't vendor godep _workspace **/Godeps/_workspace/** +vendor/ -# OSX stuff -.DS_Store +# ignore build artifacts +build/ diff --git a/.pluginsync.yml b/.pluginsync.yml new file mode 100644 index 0000000..139f660 --- /dev/null +++ b/.pluginsync.yml @@ -0,0 +1,17 @@ +pluginsync_config: '0.1.6' +managed_files: +- .github +- .github/ISSUE_TEMPLATE.md +- .github/PULL_REQUEST_TEMPLATE.md +- .gitignore +- .pluginsync.yml +- .travis.yml +- CONTRIBUTING.md +- LICENSE +- Makefile +- scripts +- scripts/build.sh +- scripts/common.sh +- scripts/deps.sh +- scripts/pre_deploy.sh +- scripts/test.sh diff --git a/.sync.yml b/.sync.yml new file mode 100644 index 0000000..4d13e1b --- /dev/null +++ b/.sync.yml @@ -0,0 +1,11 @@ +.travis.yml: + deploy: + access_key_id: AKIAINMB43VSSPFZISAA + secret_access_key: + secure: vtCgrZg4BIjtJb2S5Jqt4hsVXhqkgzxS/LD/bvLyid4RAB5Jd6rMWmTXd8Ttqr9dqRcPK7OGX6t4JU6AHJAZ1jSrPuhuaKrNmVSobXXVi2dXsUnuyjzAhK/p4+vecFYqWKy4/3CU+ZTaA9V0UZkbLLPu5G9n854ITEMTKZfU0zRUSblBos2woxxV7E/jbG9JO8Nwpy/pDaUg7CGOaKrBsAFI3tTSciNIXuOmQimWQH+Qdqv45gPihMYPpBTKm0g7g1QaZOWDfSApsmNK+3yIRfXHsjuJ1LeD/E6MWhRjz8HERtJySeTDq5CZgXIaXprFNKaIZiv0qIm6UZXiiJRgv5zEk642+VWfTO1zDuiJVIxYW1aPXf0ausC0tZSMut/1i7hAnr2Z3nBYP9icrKd7emnz07ZD7zsEopyByhvx+jHfxOJYvC57hKWc3PWtPvGUJ12ekM5TPLF3sXxwpuDgagCCXQ286ZmcK8N824TMjDIcfdJwnNd9USGTyf+Ut4MTeeeHWVCQPGFPNyuh+989IJxV49I6N+ZWnnx/rYBvjYdmxSSsT39p2pweICPwLBk5i2YRbzKljbnR5zeQnJ5Hz6WzUYmZp915GQ0XF6OY+havC3eBNKL5DvmwoKMHUD2fxfTEzIjPz9jR4dREGzk4InY6NNq/asUoZJ2E+KJWJf4= + api_key: + secure: wu8mS9ZTmcAh/65XcDsxXdXBPiVwmCiQF6a3RfnRP08E9Es3bYMRMLtSthZsSvq1ZTm0SHJUjiOajNNSvgN4DNE22wrjvi3SNuZcZwwV/Elh3ouTcrxe6hovSpG19y2NamSkrJ2d4XFWv+4RqApcEj6+jQtn5s3LdOCEbKfVWITz23ya5kUV5Mv2xjeFdexi0l9LntXNXYAOIns8aQACdvdDkU239cyKARSQHiU6r9AE7kJJmbMShfaC7XqifKr/qOK5zd7REDHQjI6mbHtWJhnENq14m/JeRASBMGx52+xZ0slOsS+VcC7l5D8iVmQb0ttyS7ctmrTKVZZHM91+++BRRrNnGVB1nu6T0RsOatunZwyL7Wq0HIkdw6J4aZgFbPJKrJbsqceIJTH2pp7Gri/5mJrLv1e+vAdbD5IiKTh0Unix3zcRLuEwAqP4vPKI+Iu6GHHbIf67sMoCMMqItZiSOXwyNTBHFXRdrlADklHVgU0mXdz2UPOMw2MKNQQT35WyZtxcndW93u7/nyGbHfGtE69p5z6urC6YWgct17v3hwzOyQhoIjgfJzeFOTeoPo7IYhDG9uAbCW3zKzhsGy45+lhaAq52XCbg+t1xSTXGwi8ga73W3xoLOyZdlU0iRW59kzES1GgC3XTARdRSFjlQoPLb40V6UW1wN06f9u8= +scripts/deps.sh: + packages: + - github.com/smartystreets/goconvey # NOTE: this should be moved to godep/glide + - github.com/stretchr/testify/mock diff --git a/.travis.yml b/.travis.yml index a01dde6..bae5ee1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,25 +1,69 @@ -sudo: required -services: -- docker +# File managed by pluginsync +sudo: false language: go go: -- 1.5.4 -- 1.6.2 -before_install: -- go get github.com/tools/godep -- if [ ! -d $SNAP_PLUGIN_SOURCE ]; then mkdir -p $HOME/gopath/src/github.com/intelsdi-x; ln -s $TRAVIS_BUILD_DIR $SNAP_PLUGIN_SOURCE; fi # CI for forks not from intelsdi-x +- 1.6.3 +- 1.7.1 env: global: - - SNAP_PLUGIN_SOURCE=/home/travis/gopath/src/github.com/intelsdi-x/snap-plugin-processor-movingaverage + - ORG_PATH=/home/travis/gopath/src/github.com/intelsdi-x + - SNAP_PLUGIN_SOURCE=/home/travis/gopath/src/github.com/${TRAVIS_REPO_SLUG} matrix: - - TEST=unit + - TEST_TYPE=small + - TEST_TYPE=build +matrix: + exclude: + - go: 1.6.3 + env: TEST_TYPE=build +before_install: +- "[[ -d $SNAP_PLUGIN_SOURCE ]] || mkdir -p $ORG_PATH && ln -s $TRAVIS_BUILD_DIR $SNAP_PLUGIN_SOURCE" install: -- export TMPDIR=$HOME/tmp -- mkdir -p $TMPDIR -- cd $SNAP_PLUGIN_SOURCE # change dir into source +- cd $SNAP_PLUGIN_SOURCE - make deps script: -- make check TEST=$TEST 2>&1 # Run test suite +- make check 2>&1 notifications: + email: false slack: secure: VkbZLIc2RH8yf3PtIAxUNPdAu3rQQ7yQx0GcK124JhbEnZGaHyK615V0rbG7HcVmYKGPdB0cXqZiLBDKGqGKb2zR1NepOe1nF03jxGSpPq8jIFeEXSJGEYGL34ScDzZZGuG6qwbjFcXiW5lqn6t8igzp7v2+URYBaZo5ktCS2xY= +before_deploy: +- "./scripts/pre_deploy.sh" +deploy: +- provider: s3 + access_key_id: AKIAINMB43VSSPFZISAA + secret_access_key: + secure: vtCgrZg4BIjtJb2S5Jqt4hsVXhqkgzxS/LD/bvLyid4RAB5Jd6rMWmTXd8Ttqr9dqRcPK7OGX6t4JU6AHJAZ1jSrPuhuaKrNmVSobXXVi2dXsUnuyjzAhK/p4+vecFYqWKy4/3CU+ZTaA9V0UZkbLLPu5G9n854ITEMTKZfU0zRUSblBos2woxxV7E/jbG9JO8Nwpy/pDaUg7CGOaKrBsAFI3tTSciNIXuOmQimWQH+Qdqv45gPihMYPpBTKm0g7g1QaZOWDfSApsmNK+3yIRfXHsjuJ1LeD/E6MWhRjz8HERtJySeTDq5CZgXIaXprFNKaIZiv0qIm6UZXiiJRgv5zEk642+VWfTO1zDuiJVIxYW1aPXf0ausC0tZSMut/1i7hAnr2Z3nBYP9icrKd7emnz07ZD7zsEopyByhvx+jHfxOJYvC57hKWc3PWtPvGUJ12ekM5TPLF3sXxwpuDgagCCXQ286ZmcK8N824TMjDIcfdJwnNd9USGTyf+Ut4MTeeeHWVCQPGFPNyuh+989IJxV49I6N+ZWnnx/rYBvjYdmxSSsT39p2pweICPwLBk5i2YRbzKljbnR5zeQnJ5Hz6WzUYmZp915GQ0XF6OY+havC3eBNKL5DvmwoKMHUD2fxfTEzIjPz9jR4dREGzk4InY6NNq/asUoZJ2E+KJWJf4= + bucket: snap.ci.snap-telemetry.io + region: us-west-2 + skip_cleanup: true + local-dir: s3 + upload-dir: plugins + acl: public_read + on: + repo: intelsdi-x/snap-plugin-processor-movingaverage + branch: master + condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.1" +- provider: s3 + access_key_id: AKIAINMB43VSSPFZISAA + secret_access_key: + secure: vtCgrZg4BIjtJb2S5Jqt4hsVXhqkgzxS/LD/bvLyid4RAB5Jd6rMWmTXd8Ttqr9dqRcPK7OGX6t4JU6AHJAZ1jSrPuhuaKrNmVSobXXVi2dXsUnuyjzAhK/p4+vecFYqWKy4/3CU+ZTaA9V0UZkbLLPu5G9n854ITEMTKZfU0zRUSblBos2woxxV7E/jbG9JO8Nwpy/pDaUg7CGOaKrBsAFI3tTSciNIXuOmQimWQH+Qdqv45gPihMYPpBTKm0g7g1QaZOWDfSApsmNK+3yIRfXHsjuJ1LeD/E6MWhRjz8HERtJySeTDq5CZgXIaXprFNKaIZiv0qIm6UZXiiJRgv5zEk642+VWfTO1zDuiJVIxYW1aPXf0ausC0tZSMut/1i7hAnr2Z3nBYP9icrKd7emnz07ZD7zsEopyByhvx+jHfxOJYvC57hKWc3PWtPvGUJ12ekM5TPLF3sXxwpuDgagCCXQ286ZmcK8N824TMjDIcfdJwnNd9USGTyf+Ut4MTeeeHWVCQPGFPNyuh+989IJxV49I6N+ZWnnx/rYBvjYdmxSSsT39p2pweICPwLBk5i2YRbzKljbnR5zeQnJ5Hz6WzUYmZp915GQ0XF6OY+havC3eBNKL5DvmwoKMHUD2fxfTEzIjPz9jR4dREGzk4InY6NNq/asUoZJ2E+KJWJf4= + bucket: snap.ci.snap-telemetry.io + region: us-west-2 + skip_cleanup: true + local-dir: s3 + upload-dir: plugins + acl: public_read + on: + repo: intelsdi-x/snap-plugin-processor-movingaverage + tags: true + condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.1" +- provider: releases + api_key: + secure: wu8mS9ZTmcAh/65XcDsxXdXBPiVwmCiQF6a3RfnRP08E9Es3bYMRMLtSthZsSvq1ZTm0SHJUjiOajNNSvgN4DNE22wrjvi3SNuZcZwwV/Elh3ouTcrxe6hovSpG19y2NamSkrJ2d4XFWv+4RqApcEj6+jQtn5s3LdOCEbKfVWITz23ya5kUV5Mv2xjeFdexi0l9LntXNXYAOIns8aQACdvdDkU239cyKARSQHiU6r9AE7kJJmbMShfaC7XqifKr/qOK5zd7REDHQjI6mbHtWJhnENq14m/JeRASBMGx52+xZ0slOsS+VcC7l5D8iVmQb0ttyS7ctmrTKVZZHM91+++BRRrNnGVB1nu6T0RsOatunZwyL7Wq0HIkdw6J4aZgFbPJKrJbsqceIJTH2pp7Gri/5mJrLv1e+vAdbD5IiKTh0Unix3zcRLuEwAqP4vPKI+Iu6GHHbIf67sMoCMMqItZiSOXwyNTBHFXRdrlADklHVgU0mXdz2UPOMw2MKNQQT35WyZtxcndW93u7/nyGbHfGtE69p5z6urC6YWgct17v3hwzOyQhoIjgfJzeFOTeoPo7IYhDG9uAbCW3zKzhsGy45+lhaAq52XCbg+t1xSTXGwi8ga73W3xoLOyZdlU0iRW59kzES1GgC3XTARdRSFjlQoPLb40V6UW1wN06f9u8= + file: + - release/snap-plugin-processor-movingaverage_linux_x86_64 + skip_cleanup: true + on: + repo: intelsdi-x/snap-plugin-processor-movingaverage + tags: true + condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.1" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2bce7d1..0d25f85 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,39 +1,46 @@ -# snap publisher plugin - movingaverage +# snap plugin processor movingaverage 1. [Contributing Code](#contributing-code) -2. [Contribute Elsewhere](#contribute-elsewhere) -3. [Thank You](#thank-you) +2. [Contributing Examples](#contributing-examples) +3. [Contribute Elsewhere](#contribute-elsewhere) +4. [Thank You](#thank-you) This repository has dedicated developers from Intel working on updates. The most helpful way to contribute is by reporting your experience through issues. Issues may not be updated while we review internally, but they're still incredibly appreciated. ## Contributing Code **_IMPORTANT_**: We encourage contributions to the project from the community. We ask that you keep the following guidelines in mind when planning your contribution. -* Whether your contribution is for a bug fix or a feature request, **create an [Issue](https://github.com/snap-plugin-processor-movingaverage/issues)** and let us know what you are thinking -* **For bugs**, if you have already found a fix, feel free to submit a Pull Request referencing the Issue you created -* **For feature requests**, we want to improve upon the library incrementally which means small changes at a time. In order ensure your PR can be reviewed in a timely manner, please keep PRs small, e.g. <10 files and <500 lines changed. If you think this is unrealistic, then mention that within the issue and we can discuss it +* Whether your contribution is for a bug fix or a feature request, **create an [Issue](https://github.com/intelsdi-x/snap-plugin-processor-movingaverage/issues)** and let us know what you are thinking. +* **For bugs**, if you have already found a fix, feel free to submit a Pull Request referencing the Issue you created. Include the `Fixes #` syntax to link it to the issue you're addressing. +* **For feature requests**, we want to improve upon the library incrementally which means small changes at a time. In order to ensure your PR can be reviewed in a timely manner, please keep PRs small, e.g. <10 files and <500 lines changed. If you think this is unrealistic, then mention that within the issue and we can discuss it. Once you're ready to contribute code back to this repo, start with these steps: -* Fork the appropriate sub-projects that are affected by your change -* Clone the fork to `$GOPATH/src/github.com/intelsdi-x/` - ``` - $ git clone https://github.com//.git - ``` -* Create a topic branch for your change and checkout that branch +* Fork the appropriate sub-projects that are affected by your change. +* Clone the fork to `$GOPATH/src/github.com/intelsdi-x/`: + + ``` +$ git clone https://github.com//.git + ``` +* Create a topic branch for your change and checkout that branch: + ``` $ git checkout -b some-topic-branch ``` -* Make your changes and run the test suite if one is provided (see below) -* Commit your changes and push them to your fork -* Open a pull request for the appropriate project -* Contributors will review your pull request, suggest changes, and merge it when it’s ready and/or offer feedback -* To report a bug or issue, please open a new issue against this repository +* Make your changes and run the test suite if one is provided. +* Commit your changes and push them to your fork. +* Open a pull request for the appropriate project. +* Contributors will review your pull request, suggest changes, and merge it when it’s ready and/or offer feedback. + +If you have questions feel free to contact the [maintainers](https://github.com/intelsdi-x/snap/blob/master/README.md#maintainers) by tagging them: @intelsdi-x/plugin-maintainers. + +## Contributing Examples +The most immediately helpful way you can benefit this project is by cloning the repository, adding some further examples and submitting a pull request. -If you have questions feel free to contact the [maintainers](README.md#maintainers). +Have you written a blog post about how you use [Snap](http://github.com/intelsdi-x/snap) and/or this plugin? Send it to us [on Slack](http://slack.snap-telemetry.io)! ## Contribute Elsewhere -This repository is one of **many** plugins in **snap**, a powerful telemetry framework. See the full project at http://github.com/intelsdi-x/snap +This repository is one of **many** plugins in **Snap**, a powerful telemetry framework. See the full project at http://snap-telemetry.io ## Thank You And **thank you!** Your contribution, through code and participation, is incredibly important to us. diff --git a/LICENSE b/LICENSE index 7a4a3ea..d645695 100644 --- a/LICENSE +++ b/LICENSE @@ -199,4 +199,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file + limitations under the License. diff --git a/Makefile b/Makefile index f70b452..e9ea9a7 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,36 @@ +# File managed by pluginsync +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2015 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + default: $(MAKE) deps $(MAKE) all deps: - bash -c "godep restore" + bash -c "./scripts/deps.sh" test: - bash -c "./scripts/test.sh $(TEST)" + bash -c "./scripts/test.sh $(TEST_TYPE)" +test-legacy: + bash -c "./scripts/test.sh legacy" +test-small: + bash -c "./scripts/test.sh small" +test-medium: + bash -c "./scripts/test.sh medium" +test-large: + bash -c "./scripts/test.sh large" check: $(MAKE) test all: diff --git a/main_test.go b/main_test.go index f2b60ea..fc78149 100644 --- a/main_test.go +++ b/main_test.go @@ -1,5 +1,5 @@ // -// +build unit +// +build small /* http://www.apache.org/licenses/LICENSE-2.0.txt diff --git a/movingaverage/movingaverage_test.go b/movingaverage/movingaverage_test.go index d1b0950..13c0b98 100644 --- a/movingaverage/movingaverage_test.go +++ b/movingaverage/movingaverage_test.go @@ -1,5 +1,5 @@ // -// +build unit +// +build small /* http://www.apache.org/licenses/LICENSE-2.0.txt diff --git a/scripts/build.sh b/scripts/build.sh index 2ee9b58..58b6d41 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,27 +1,48 @@ -#!/bin/bash -e +#!/bin/bash +# File managed by pluginsync -GITVERSION=`git describe --always` -SOURCEDIR=$1 -BUILDDIR=$SOURCEDIR/build -PLUGIN=`echo $SOURCEDIR | grep -oh "snap-.*"` -ROOTFS=$BUILDDIR/rootfs -BUILDCMD='go build -a -ldflags "-w"' +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2016 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. -echo -echo "**** Snap Plugin Build ****" -echo +set -e +set -u +set -o pipefail -# Disable CGO for builds -export CGO_ENABLED=0 +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" + +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" -# Clean build bin dir -rm -rf $ROOTFS/* +plugin_name=${__proj_dir##*/} +build_dir="${__proj_dir}/build" +go_build=(go build -ldflags "-w") -# Make dir -mkdir -p $ROOTFS +_info "project path: ${__proj_dir}" +_info "plugin name: ${plugin_name}" + +export CGO_ENABLED=0 -# Build plugin -echo "Source Dir = $SOURCEDIR" -echo "Building Snap Plugin: $PLUGIN" -$BUILDCMD -o $ROOTFS/$PLUGIN +# rebuild binaries: +_debug "removing: ${build_dir:?}/*" +rm -rf "${build_dir:?}/"* +_info "building plugin: ${plugin_name}" +export GOOS=linux +export GOARCH=amd64 +mkdir -p "${build_dir}/${GOOS}/x86_64" +"${go_build[@]}" -o "${build_dir}/${GOOS}/x86_64/${plugin_name}" . || exit 1 diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100644 index 0000000..b8e7413 --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,111 @@ +#!/bin/bash +# File managed by pluginsync + +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2016 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e +set -u +set -o pipefail + +LOG_LEVEL="${LOG_LEVEL:-6}" +NO_COLOR="${NO_COLOR:-}" + +trap_exitcode() { + exit $? +} + +trap trap_exitcode SIGINT + +_fmt () { + local color_debug="\x1b[35m" + local color_info="\x1b[32m" + local color_notice="\x1b[34m" + local color_warning="\x1b[33m" + local color_error="\x1b[31m" + local colorvar=color_$1 + + local color="${!colorvar:-$color_error}" + local color_reset="\x1b[0m" + if [ "${NO_COLOR}" = "true" ] || [[ "${TERM:-}" != "xterm"* ]] || [ -t 1 ]; then + # Don't use colors on pipes or non-recognized terminals + color=""; color_reset="" + fi + echo -e "$(date -u +"%Y-%m-%d %H:%M:%S UTC") ${color}$(printf "[%9s]" "${1}")${color_reset}"; +} + +_debug () { [ "${LOG_LEVEL}" -ge 7 ] && echo "$(_fmt debug) ${*}" 1>&2 || true; } +_info () { [ "${LOG_LEVEL}" -ge 6 ] && echo "$(_fmt info) ${*}" 1>&2 || true; } +_notice () { [ "${LOG_LEVEL}" -ge 5 ] && echo "$(_fmt notice) ${*}" 1>&2 || true; } +_warning () { [ "${LOG_LEVEL}" -ge 4 ] && echo "$(_fmt warning) ${*}" 1>&2 || true; } +_error () { [ "${LOG_LEVEL}" -ge 3 ] && echo "$(_fmt error) ${*}" 1>&2 || true; exit 1; } + +_test_dirs() { + local test_dirs=$(find . -type f -name '*.go' -not -path "./.*" -not -path "*/_*" -not -path "./Godeps/*" -not -path "./vendor/*" -print0 | xargs -0 -n1 dirname| sort -u) + _debug "go code directories ${test_dirs}" + echo "${test_dirs}" +} + +_go_get() { + local _url=$1 + local _util + + _util=$(basename "${_url}") + + type -p "${_util}" > /dev/null || go get "${_url}" && _debug "go get ${_util} ${_url}" +} + +_goimports() { + _go_get golang.org/x/tools/cmd/goimports + test -z "$(goimports -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") | tee /dev/stderr)" +} + +_golint() { + _go_get github.com/golang/lint/golint + golint ./... +} + +_go_vet() { + go vet $(_test_dirs) +} + +_go_race() { + go test -race ./... +} + +_go_test() { + _info "running test type: ${TEST_TYPE}" + # Standard go tooling behavior is to ignore dirs with leading underscors + for dir in $(_test_dirs); + do + if [[ -z ${go_cover+x} ]]; then + _debug "running go test with cover in ${dir}" + go test -v --tags="${TEST_TYPE}" -covermode=count -coverprofile="${dir}/profile.tmp" "${dir}" + if [ -f "${dir}/profile.tmp" ]; then + tail -n +2 "${dir}/profile.tmp" >> profile.cov + rm "${dir}/profile.tmp" + fi + else + _debug "running go test without cover in ${dir}" + go test -v --tags="${TEST_TYPE}" "${dir}" + fi + done +} + +_go_cover() { + go tool cover -func profile.cov +} diff --git a/scripts/deps.sh b/scripts/deps.sh new file mode 100755 index 0000000..6a55b26 --- /dev/null +++ b/scripts/deps.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# File managed by pluginsync + +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2016 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e +set -u +set -o pipefail + +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" + +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" + +detect_go_dep() { + [[ -f "${__proj_dir}/Godeps/Godeps.json" ]] && _dep='godep' + [[ -f "${__proj_dir}/glide.yaml" ]] && _dep='glide' + [[ -f "${__proj_dir}/vendor/vendor.json" ]] && _dep='govendor' + _info "golang dependency tool: ${_dep}" + echo "${_dep}" +} + +install_go_dep() { + local _dep=${_dep:=$(_detect_dep)} + _info "ensuring ${_dep} is available" + case $_dep in + godep) + _go_get github.com/tools/godep + ;; + glide) + _go_get github.com/Masterminds/glide + ;; + govendor) + _go_get github.com/kardianos/govendor + ;; + esac +} + +restore_go_dep() { + local _dep=${_dep:=$(_detect_dep)} + _info "restoring dependency with ${_dep}" + case $_dep in + godep) + (cd "${__proj_dir}" && godep restore) + ;; + glide) + (cd "${__proj_dir}" && glide install) + ;; + govendor) + (cd "${__proj_dir}" && govendor sync) + ;; + esac +} + +_dep=$(detect_go_dep) +install_go_dep +restore_go_dep +_go_get github.com/smartystreets/goconvey +_go_get github.com/stretchr/testify/mock diff --git a/scripts/pre_deploy.sh b/scripts/pre_deploy.sh new file mode 100755 index 0000000..9a57824 --- /dev/null +++ b/scripts/pre_deploy.sh @@ -0,0 +1,80 @@ +#!/bin/bash +# File managed by pluginsync + +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2016 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e +set -u +set -o pipefail + +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" + +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" + +build_path="${__proj_dir}/build" +_info "build_path: ${build_path}" +_debug "$(find "${build_path}")" + +plugin_name="${__proj_dir##*/}" +git_sha=$(git log --pretty=format:"%H" -1) +s3_path="${__proj_dir}/s3/${plugin_name}" + +set +u +if [ -z "$TRAVIS_TAG" ]; then + set -u + git_path="${s3_path}/${git_sha}" + latest_path="${s3_path}/latest_build" + mkdir -p "${git_path}" + mkdir -p "${latest_path}" + + _info "copying plugin binaries to ${git_path}" + cp -rp "${build_path}/"* "${git_path}" + _info "copying plugin binaries to ${latest_path}" + cp -rp "${build_path}/"* "${latest_path}" +else + set -u + tag_path="${s3_path}/${TRAVIS_TAG}" + latest_path="${s3_path}/latest" + mkdir -p "${tag_path}" + mkdir -p "${latest_path}" + + _info "copying plugin binaries to ${tag_path}" + cp -rp "${build_path}/"* "${tag_path}" + _info "copying plugin binaries to ${latest_path}" + cp -rp "${build_path}/"* "${latest_path}" +fi + +release_path="${SNAP_PATH:-"${__proj_dir}/release"}" +mkdir -p "${release_path}" + +_info "moving plugin binaries to ${release_path}" + +for file in "${build_path}"/**/*/snap-plugin-* ; do + filename="${file##*/}" + parent="${file%/*}" + arch="${parent##*/}" + parent="${parent%/*}" + os="${parent##*/}" + cp "${file}" "${release_path}/${filename}_${os}_${arch}" +done + +_debug "$(find "${build_path}")" +_debug "$(find "${s3_path}")" +_debug "$(find "${release_path}")" diff --git a/scripts/test.sh b/scripts/test.sh index 9ccc274..a63d7f0 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,83 +1,100 @@ -#!/bin/bash -e -# The script does automatic checking on a Go package and its sub-packages, including: -# 1. gofmt (http://golang.org/cmd/gofmt/) -# 2. goimports (https://github.com/bradfitz/goimports) -# 3. golint (https://github.com/golang/lint) -# 4. go vet (http://golang.org/cmd/vet) -# 5. race detector (http://blog.golang.org/race-detector) -# 6. test coverage (http://blog.golang.org/cover) +#!/bin/bash +# File managed by pluginsync -# Capture what test we should run -TEST_SUITE=$1 +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2016 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. -if [[ $TEST_SUITE == "unit" ]]; then - go get github.com/axw/gocov/gocov - go get github.com/mattn/goveralls - go get -u github.com/golang/lint/golint - go get golang.org/x/tools/cmd/goimports - go get github.com/smartystreets/goconvey/convey - go get golang.org/x/tools/cmd/cover - - COVERALLS_TOKEN=t47LG6BQsfLwb9WxB56hXUezvwpED6D11 - TEST_DIRS="main.go movingaverage/" - VET_DIRS=". ./movingaverage/..." +# Support travis.ci environment matrix: +TEST_TYPE="${TEST_TYPE:-$1}" +UNIT_TEST="${UNIT_TEST:-"gofmt goimports go_vet go_test go_cover"}" +TEST_K8S="${TEST_K8S:-0}" - set -e +set -e +set -u +set -o pipefail - # Automatic checks - echo "gofmt" - test -z "$(gofmt -l -d $TEST_DIRS | tee /dev/stderr)" +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" - echo "goimports" - test -z "$(goimports -l -d $TEST_DIRS | tee /dev/stderr)" +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" - # Useful but should not fail on link per: https://github.com/golang/lint - # "The suggestions made by golint are exactly that: suggestions. Golint is not perfect, - # and has both false positives and false negatives. Do not treat its output as a gold standard. - # We will not be adding pragmas or other knobs to suppress specific warnings, so do not expect - # or require code to be completely "lint-free". In short, this tool is not, and will never be, - # trustworthy enough for its suggestions to be enforced automatically, for example as part of - # a build process" - # echo "golint" - # golint ./... +_debug "script directory ${__dir}" +_debug "project directory ${__proj_dir}" - echo "go vet" - go vet $VET_DIRS - # go test -race ./... - Lets disable for now - - # Run test coverage on each subdirectories and merge the coverage profile. - echo "mode: count" > profile.cov - - # Standard go tooling behavior is to ignore dirs with leading underscors - for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -not -path './examples/*' -not -path './scripts/*' -not -path './build/*' -not -path './Godeps/*' -type d); - do - if ls $dir/*.go &> /dev/null; then - go test --tags=unit -covermode=count -coverprofile=$dir/profile.tmp $dir - if [ -f $dir/profile.tmp ] - then - cat $dir/profile.tmp | tail -n +2 >> profile.cov - rm $dir/profile.tmp - fi - fi - done - - go tool cover -func profile.cov - - # Disabled Coveralls.io for now - # To submit the test coverage result to coveralls.io, - # use goveralls (https://github.com/mattn/goveralls) - # goveralls -coverprofile=profile.cov -service=travis-ci -repotoken t47LG6BQsfLwb9WxB56hXUezvwpED6D11 - # - # If running inside Travis we update coveralls. We don't want his happening on Macs - # if [ "$TRAVIS" == "true" ] - # then - # n=1 - # until [ $n -ge 6 ] - # do - # echo "posting to coveralls attempt $n of 5" - # goveralls -v -coverprofile=profile.cov -service travis.ci -repotoken $COVERALLS_TOKEN && break - # n=$[$n+1] - # sleep 30 - # done - # fi +[[ "$TEST_TYPE" =~ ^(small|medium|large|legacy|build)$ ]] || _error "invalid TEST_TYPE (value must be 'small', 'medium', 'large', 'legacy', or 'build' recieved:${TEST_TYPE}" + +_gofmt() { + test -z "$(gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") | tee /dev/stderr)" +} + +test_unit() { + # The script does automatic checking on a Go package and its sub-packages, including: + # 1. gofmt (http://golang.org/cmd/gofmt/) + # 2. goimports (https://github.com/bradfitz/goimports) + # 3. golint (https://github.com/golang/lint) + # 4. go vet (http://golang.org/cmd/vet) + # 5. race detector (http://blog.golang.org/race-detector) + # 6. go test + # 7. test coverage (http://blog.golang.org/cover) + local go_tests + go_tests=(gofmt goimports golint go_vet go_race go_test go_cover) + + _debug "available unit tests: ${go_tests[*]}" + _debug "user specified tests: ${UNIT_TEST}" + + ((n_elements=${#go_tests[@]}, max=n_elements - 1)) + + for ((i = 0; i <= max; i++)); do + if [[ "${UNIT_TEST}" =~ (^| )"${go_tests[i]}"( |$) ]]; then + _info "running ${go_tests[i]}" + _"${go_tests[i]}" + else + _debug "skipping ${go_tests[i]}" + fi + done +} + +if [[ $TEST_TYPE == "legacy" ]]; then + echo "mode: count" > profile.cov + export TEST_TYPE="unit" + test_unit +elif [[ $TEST_TYPE == "small" ]]; then + if [[ -f "${__dir}/small.sh" ]]; then + . "${__dir}/small.sh" + else + echo "mode: count" > profile.cov + test_unit + fi +elif [[ $TEST_TYPE == "medium" ]]; then + if [[ -f "${__dir}/medium.sh" ]]; then + . "${__dir}/medium.sh" + else + UNIT_TEST="go_test" + test_unit + fi +elif [[ $TEST_TYPE == "large" ]]; then + if [[ "${TEST_K8S}" != "0" && -f "$__dir/large_k8s.sh" ]]; then + . "${__dir}/large_k8s.sh" + elif [[ -f "${__dir}/large_compose.sh" ]]; then + . "${__dir}/large_compose.sh" + else + _info "No large tests." + fi +elif [[ $TEST_TYPE == "build" ]]; then + "${__dir}/build.sh" fi