From b239694d34abc9f4fbfd04b68b7cca91585e8811 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Mon, 9 May 2016 10:18:38 +0100 Subject: [PATCH 1/9] Move circle commands into shell scripts --- bin/circle-dependencies-post | 15 ++++++++++ bin/circle-deploy-issues | 12 ++++++++ bin/circle-deploy-master | 17 ++++++++++++ bin/circle-deploy-release | 12 ++++++++ bin/circle-teardown-pre | 9 ++++++ bin/circle-test-override | 8 ++++++ bin/circle-test-post | 7 +++++ bin/circle-test-pre | 12 ++++++++ circle.yml | 54 ++++++++++-------------------------- 9 files changed, 107 insertions(+), 39 deletions(-) create mode 100755 bin/circle-dependencies-post create mode 100755 bin/circle-deploy-issues create mode 100755 bin/circle-deploy-master create mode 100755 bin/circle-deploy-release create mode 100755 bin/circle-teardown-pre create mode 100755 bin/circle-test-override create mode 100755 bin/circle-test-post create mode 100755 bin/circle-test-pre diff --git a/bin/circle-dependencies-post b/bin/circle-dependencies-post new file mode 100755 index 00000000..eded9ed8 --- /dev/null +++ b/bin/circle-dependencies-post @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +sudo apt-get -q update && sudo apt-get -q install bc jq +bin/setup-circleci-secrets "$SECRET_PASSWORD" +mkdir -p $(dirname $SRCDIR) && cp -r $(pwd)/ $SRCDIR +cd $SRCDIR; git submodule update --init +if [ "$CIRCLE_NODE_INDEX" = "0" ] ; then + cd $SRCDIR/test; ./gce.sh make_template +fi +cd $SRCDIR/build +../tools/rebuild-image weaveworks/weavebuild . Dockerfile build.sh +touch $SRCDIR/.build.uptodate +sudo chown -R ubuntu /usr/local/go diff --git a/bin/circle-deploy-issues b/bin/circle-deploy-issues new file mode 100755 index 00000000..018d8925 --- /dev/null +++ b/bin/circle-deploy-issues @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +go get github.com/weaveworks/wordepress +cd /home/ubuntu/src/github.com/weaveworks/wordepress +git checkout v1.0.0 +cd cmd/wordepress +go get + +cd $SRCDIR +bin/publish-site "$WP_DEV_URL" "$WP_DEV_USER" "$WP_DEV_PASSWORD" diff --git a/bin/circle-deploy-master b/bin/circle-deploy-master new file mode 100755 index 00000000..403cd72e --- /dev/null +++ b/bin/circle-deploy-master @@ -0,0 +1,17 @@ +#!/bin/bash + +set -e + +docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS +cd $SRCDIR +make clean-bin +make publish + +go get github.com/weaveworks/wordepress +cd /home/ubuntu/src/github.com/weaveworks/wordepress +git checkout v1.0.0 +cd cmd/wordepress +go get + +cd $SRCDIR +bin/publish-site "$WP_DEV_URL" "$WP_DEV_USER" "$WP_DEV_PASSWORD" diff --git a/bin/circle-deploy-release b/bin/circle-deploy-release new file mode 100755 index 00000000..fed3d35e --- /dev/null +++ b/bin/circle-deploy-release @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +go get github.com/weaveworks/wordepress +cd /home/ubuntu/src/github.com/weaveworks/wordepress +git checkout v1.0.0 +cd cmd/wordepress +go get + +cd $SRCDIR +bin/publish-site "$WP_LIVE_URL" "$WP_LIVE_USER" "$WP_LIVE_PASSWORD" diff --git a/bin/circle-teardown-pre b/bin/circle-teardown-pre new file mode 100755 index 00000000..d4ac8e3c --- /dev/null +++ b/bin/circle-teardown-pre @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +if [ "$CIRCLE_NODE_INDEX" = "0" ] ; then + go get github.com/mattn/goveralls + goveralls -repotoken $COVERALLS_REPO_TOKEN -coverprofile=$SRCDIR/test/profile.cov -service=circleci + cd $SRCDIR/test; cp coverage.* $CIRCLE_ARTIFACTS +fi diff --git a/bin/circle-test-override b/bin/circle-test-override new file mode 100755 index 00000000..e8910b82 --- /dev/null +++ b/bin/circle-test-override @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e + +cd $SRCDIR/test +eval $(./gce.sh hosts) +export COVERAGE=true +./run_all.sh diff --git a/bin/circle-test-post b/bin/circle-test-post new file mode 100755 index 00000000..5d362b59 --- /dev/null +++ b/bin/circle-test-post @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +cd $SRCDIR/test +./gce.sh destroy +test "$CIRCLE_NODE_INDEX" != "0" || (cd $SRCDIR/test; ./gen_coverage_reports.sh) diff --git a/bin/circle-test-pre b/bin/circle-test-pre new file mode 100755 index 00000000..2521d975 --- /dev/null +++ b/bin/circle-test-pre @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +cd $SRCDIR +make lint +COVERDIR=test/coverage make RM= tests +make COVERAGE=true RM= all +make testrunner + +cd $SRCDIR/test +./gce.sh setup && eval $(./gce.sh hosts) && ./setup.sh diff --git a/circle.yml b/circle.yml index 1879b488..0f700619 100644 --- a/circle.yml +++ b/circle.yml @@ -17,41 +17,23 @@ dependencies: cache_directories: - "~/docker" post: - - "sudo apt-get update && sudo apt-get install bc jq" - - bin/setup-circleci-secrets "$SECRET_PASSWORD" - - "mkdir -p $(dirname $SRCDIR) && cp -r $(pwd)/ $SRCDIR" - - "cd $SRCDIR; git submodule update --init" - - cd $SRCDIR/test; ./gce.sh make_template: - parallel: false - - "cd $SRCDIR/build; ../tools/rebuild-image weaveworks/weavebuild . Dockerfile build.sh && touch $SRCDIR/.build.uptodate" - - "sudo chown -R ubuntu /usr/local/go" + - bin/circle-dependencies-post test: + pre: + - "$SRCDIR/bin/circle-test-pre": + parallel: true override: - - cd $SRCDIR; make lint: - parallel: true - - cd $SRCDIR; COVERDIR=test/coverage make RM= tests: - parallel: true - - cd $SRCDIR; make COVERAGE=true RM= exes all: - parallel: true - - cd $SRCDIR; make testrunner: - parallel: true - - cd $SRCDIR/test; ./gce.sh setup && eval $(./gce.sh hosts) && ./setup.sh: - parallel: true - - cd $SRCDIR/test; eval $(./gce.sh hosts); export COVERAGE=true; ./run_all.sh: + - "$SRCDIR/bin/circle-test-override": parallel: true timeout: 300 post: - - cd $SRCDIR/test; ./gce.sh destroy: - parallel: true - - test "$CIRCLE_NODE_INDEX" != "0" || (cd $SRCDIR/test; ./gen_coverage_reports.sh): + - "$SRCDIR/bin/circle-test-post": parallel: true teardown: pre: - - test "$CIRCLE_NODE_INDEX" != "0" || (go get github.com/mattn/goveralls && goveralls -repotoken $COVERALLS_REPO_TOKEN -coverprofile=$SRCDIR/test/profile.cov -service=circleci || true): - parallel: true - - test "$CIRCLE_NODE_INDEX" != "0" || (cd $SRCDIR/test; cp coverage.* $CIRCLE_ARTIFACTS): + - "$SRCDIR/bin/circle-teardown-pre": parallel: true deployment: @@ -59,20 +41,14 @@ deployment: branch: /[0-9]+\.[0-9]+/ owner: weaveworks commands: - - go get github.com/weaveworks/wordepress && cd /home/ubuntu/src/github.com/weaveworks/wordepress && git checkout v1.0.0 && cd cmd/wordepress && go get - - cd $SRCDIR; bin/publish-site "$WP_LIVE_URL" "$WP_LIVE_USER" "$WP_LIVE_PASSWORD" - hub: + - "$SRCDIR/bin/circle-deploy-release" + master: branch: master owner: weaveworks commands: - - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS - - cd $SRCDIR; make clean-bin - - cd $SRCDIR; make exes publish -# - go get github.com/weaveworks/wordepress && cd /home/ubuntu/src/github.com/weaveworks/wordepress && git checkout v1.0.0 && cd cmd/wordepress && go get -# - cd $SRCDIR; bin/publish-site "$WP_DEV_URL" "$WP_DEV_USER" "$WP_DEV_PASSWORD" -# issues: -# branch: /.*/ -# owner: weaveworks -# commands: -# - go get github.com/weaveworks/wordepress && cd /home/ubuntu/src/github.com/weaveworks/wordepress && git checkout v1.0.0 && cd cmd/wordepress && go get -# - cd $SRCDIR; bin/publish-site "$WP_DEV_URL" "$WP_DEV_USER" "$WP_DEV_PASSWORD" + - "$SRCDIR/bin/circle-deploy-master" + issues: + branch: /.*/ + owner: weaveworks + commands: + - "$SRCDIR/bin/circle-deploy-issues" From b45f138ff12c3a595949e0777f002f4a56e33c24 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 10 May 2016 11:17:39 +0100 Subject: [PATCH 2/9] Propagate state between scripts --- bin/circle-dependencies-post | 2 ++ bin/circle-deploy-issues | 2 ++ bin/circle-deploy-master | 2 ++ bin/circle-deploy-release | 2 ++ bin/circle-teardown-pre | 2 ++ bin/circle-test-override | 2 ++ bin/circle-test-post | 2 ++ bin/circle-test-pre | 2 ++ circle.yml | 1 + 9 files changed, 17 insertions(+) diff --git a/bin/circle-dependencies-post b/bin/circle-dependencies-post index eded9ed8..945a9dd7 100755 --- a/bin/circle-dependencies-post +++ b/bin/circle-dependencies-post @@ -2,6 +2,8 @@ set -e +source "$STATE" + sudo apt-get -q update && sudo apt-get -q install bc jq bin/setup-circleci-secrets "$SECRET_PASSWORD" mkdir -p $(dirname $SRCDIR) && cp -r $(pwd)/ $SRCDIR diff --git a/bin/circle-deploy-issues b/bin/circle-deploy-issues index 018d8925..ce3788a5 100755 --- a/bin/circle-deploy-issues +++ b/bin/circle-deploy-issues @@ -2,6 +2,8 @@ set -e +source "$STATE" + go get github.com/weaveworks/wordepress cd /home/ubuntu/src/github.com/weaveworks/wordepress git checkout v1.0.0 diff --git a/bin/circle-deploy-master b/bin/circle-deploy-master index 403cd72e..44ad699f 100755 --- a/bin/circle-deploy-master +++ b/bin/circle-deploy-master @@ -2,6 +2,8 @@ set -e +source "$STATE" + docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS cd $SRCDIR make clean-bin diff --git a/bin/circle-deploy-release b/bin/circle-deploy-release index fed3d35e..ce2e9eb5 100755 --- a/bin/circle-deploy-release +++ b/bin/circle-deploy-release @@ -2,6 +2,8 @@ set -e +source "$STATE" + go get github.com/weaveworks/wordepress cd /home/ubuntu/src/github.com/weaveworks/wordepress git checkout v1.0.0 diff --git a/bin/circle-teardown-pre b/bin/circle-teardown-pre index d4ac8e3c..f5d7a529 100755 --- a/bin/circle-teardown-pre +++ b/bin/circle-teardown-pre @@ -2,6 +2,8 @@ set -e +source "$STATE" + if [ "$CIRCLE_NODE_INDEX" = "0" ] ; then go get github.com/mattn/goveralls goveralls -repotoken $COVERALLS_REPO_TOKEN -coverprofile=$SRCDIR/test/profile.cov -service=circleci diff --git a/bin/circle-test-override b/bin/circle-test-override index e8910b82..4d25df4e 100755 --- a/bin/circle-test-override +++ b/bin/circle-test-override @@ -2,6 +2,8 @@ set -e +source "$STATE" + cd $SRCDIR/test eval $(./gce.sh hosts) export COVERAGE=true diff --git a/bin/circle-test-post b/bin/circle-test-post index 5d362b59..38e14faf 100755 --- a/bin/circle-test-post +++ b/bin/circle-test-post @@ -2,6 +2,8 @@ set -e +source "$STATE" + cd $SRCDIR/test ./gce.sh destroy test "$CIRCLE_NODE_INDEX" != "0" || (cd $SRCDIR/test; ./gen_coverage_reports.sh) diff --git a/bin/circle-test-pre b/bin/circle-test-pre index 2521d975..3256fbdf 100755 --- a/bin/circle-test-pre +++ b/bin/circle-test-pre @@ -2,6 +2,8 @@ set -e +source "$STATE" + cd $SRCDIR make lint COVERDIR=test/coverage make RM= tests diff --git a/circle.yml b/circle.yml index 0f700619..2d8d9a34 100644 --- a/circle.yml +++ b/circle.yml @@ -12,6 +12,7 @@ machine: SRCDIR: /home/ubuntu/src/github.com/weaveworks/weave PATH: $PATH:$HOME/.local/bin CLOUDSDK_CORE_DISABLE_PROMPTS: 1 + STATE: /home/ubuntu/state.env dependencies: cache_directories: From a9db631836fbef6eb8dca473cafe7dd97f93eb8e Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 10 May 2016 11:21:56 +0100 Subject: [PATCH 3/9] Add toggle for skipping tests --- bin/circle-dependencies-post | 19 ++++++++++++------- bin/circle-deploy-master | 10 ++++++---- bin/circle-teardown-pre | 10 ++++++---- bin/circle-test-override | 10 ++++++---- bin/circle-test-post | 8 +++++--- bin/circle-test-pre | 16 +++++++++------- 6 files changed, 44 insertions(+), 29 deletions(-) diff --git a/bin/circle-dependencies-post b/bin/circle-dependencies-post index 945a9dd7..028b7743 100755 --- a/bin/circle-dependencies-post +++ b/bin/circle-dependencies-post @@ -2,16 +2,21 @@ set -e +echo "SKIP_TESTS=1" > "$STATE" + source "$STATE" sudo apt-get -q update && sudo apt-get -q install bc jq bin/setup-circleci-secrets "$SECRET_PASSWORD" mkdir -p $(dirname $SRCDIR) && cp -r $(pwd)/ $SRCDIR -cd $SRCDIR; git submodule update --init -if [ "$CIRCLE_NODE_INDEX" = "0" ] ; then - cd $SRCDIR/test; ./gce.sh make_template + +if [ -z "$SKIP_TESTS" ] ; then + cd $SRCDIR; git submodule update --init + if [ "$CIRCLE_NODE_INDEX" = "0" ] ; then + cd $SRCDIR/test; ./gce.sh make_template + fi + cd $SRCDIR/build + ../tools/rebuild-image weaveworks/weavebuild . Dockerfile build.sh + touch $SRCDIR/.build.uptodate + sudo chown -R ubuntu /usr/local/go fi -cd $SRCDIR/build -../tools/rebuild-image weaveworks/weavebuild . Dockerfile build.sh -touch $SRCDIR/.build.uptodate -sudo chown -R ubuntu /usr/local/go diff --git a/bin/circle-deploy-master b/bin/circle-deploy-master index 44ad699f..2827ad91 100755 --- a/bin/circle-deploy-master +++ b/bin/circle-deploy-master @@ -4,10 +4,12 @@ set -e source "$STATE" -docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS -cd $SRCDIR -make clean-bin -make publish +if [ -z "$SKIP_TESTS" ] ; then + docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS + cd $SRCDIR + make clean-bin + make publish +fi go get github.com/weaveworks/wordepress cd /home/ubuntu/src/github.com/weaveworks/wordepress diff --git a/bin/circle-teardown-pre b/bin/circle-teardown-pre index f5d7a529..4670e3f1 100755 --- a/bin/circle-teardown-pre +++ b/bin/circle-teardown-pre @@ -4,8 +4,10 @@ set -e source "$STATE" -if [ "$CIRCLE_NODE_INDEX" = "0" ] ; then - go get github.com/mattn/goveralls - goveralls -repotoken $COVERALLS_REPO_TOKEN -coverprofile=$SRCDIR/test/profile.cov -service=circleci - cd $SRCDIR/test; cp coverage.* $CIRCLE_ARTIFACTS +if [ -z "$SKIP_TESTS" ] ; then + if [ "$CIRCLE_NODE_INDEX" = "0" ] ; then + go get github.com/mattn/goveralls + goveralls -repotoken $COVERALLS_REPO_TOKEN -coverprofile=$SRCDIR/test/profile.cov -service=circleci + cd $SRCDIR/test; cp coverage.* $CIRCLE_ARTIFACTS + fi fi diff --git a/bin/circle-test-override b/bin/circle-test-override index 4d25df4e..93aa9883 100755 --- a/bin/circle-test-override +++ b/bin/circle-test-override @@ -4,7 +4,9 @@ set -e source "$STATE" -cd $SRCDIR/test -eval $(./gce.sh hosts) -export COVERAGE=true -./run_all.sh +if [ -z "$SKIP_TESTS" ] ; then + cd $SRCDIR/test + eval $(./gce.sh hosts) + export COVERAGE=true + ./run_all.sh +fi diff --git a/bin/circle-test-post b/bin/circle-test-post index 38e14faf..dac2db4f 100755 --- a/bin/circle-test-post +++ b/bin/circle-test-post @@ -4,6 +4,8 @@ set -e source "$STATE" -cd $SRCDIR/test -./gce.sh destroy -test "$CIRCLE_NODE_INDEX" != "0" || (cd $SRCDIR/test; ./gen_coverage_reports.sh) +if [ -z "$SKIP_TESTS" ] ; then + cd $SRCDIR/test + ./gce.sh destroy + test "$CIRCLE_NODE_INDEX" != "0" || (cd $SRCDIR/test; ./gen_coverage_reports.sh) +fi diff --git a/bin/circle-test-pre b/bin/circle-test-pre index 3256fbdf..e019c3b6 100755 --- a/bin/circle-test-pre +++ b/bin/circle-test-pre @@ -4,11 +4,13 @@ set -e source "$STATE" -cd $SRCDIR -make lint -COVERDIR=test/coverage make RM= tests -make COVERAGE=true RM= all -make testrunner +if [ -z "$SKIP_TESTS" ] ; then + cd $SRCDIR + make lint + COVERDIR=test/coverage make RM= tests + make COVERAGE=true RM= all + make testrunner -cd $SRCDIR/test -./gce.sh setup && eval $(./gce.sh hosts) && ./setup.sh + cd $SRCDIR/test + ./gce.sh setup && eval $(./gce.sh hosts) && ./setup.sh +fi From 238001845701d53eac886e8467abadd3699b9a32 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 10 May 2016 12:46:17 +0100 Subject: [PATCH 4/9] Skip tests if PR contains only site changes --- bin/circle-dependencies-post | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/bin/circle-dependencies-post b/bin/circle-dependencies-post index 028b7743..a651527b 100755 --- a/bin/circle-dependencies-post +++ b/bin/circle-dependencies-post @@ -2,15 +2,35 @@ set -e -echo "SKIP_TESTS=1" > "$STATE" +# We need jq to analyse the PR files JSON, so install that first +sudo apt-get -q update && sudo apt-get -q install bc jq + +rm -f "$STATE" && touch "$STATE" + +if [ -n "$CI_PULL_REQUEST" -a "$CI_PULL_REQUEST" = "$CI_PULL_REQUESTS" ] ; then + if PR=$(echo "$CI_PULL_REQUEST" | grep -oP '(?<=^https://github.com/weaveworks/weave/pull/)[0-9]+$') ; then + if FILES=$(curl -s https://api.github.com/repos/weaveworks/weave/pulls/$PR/files | jq -r '.[]|.filename') ; then + echo "PR touches [$FILES]" + if ! echo "$FILES" | grep -v ^site/ ; then + echo "PR contains site changes only - skipping tests" + echo "SKIP_TESTS=1" >> "$STATE" + else + echo "PR contains non-site changes - running tests" + fi + else + echo "Unable to get files for PR $PR" >&2 + fi + else + echo "Unable to extract PR number from $CI_PULL_REQUEST" >&2 + fi +fi source "$STATE" -sudo apt-get -q update && sudo apt-get -q install bc jq -bin/setup-circleci-secrets "$SECRET_PASSWORD" mkdir -p $(dirname $SRCDIR) && cp -r $(pwd)/ $SRCDIR if [ -z "$SKIP_TESTS" ] ; then + bin/setup-circleci-secrets "$SECRET_PASSWORD" cd $SRCDIR; git submodule update --init if [ "$CIRCLE_NODE_INDEX" = "0" ] ; then cd $SRCDIR/test; ./gce.sh make_template From e1063944f6151099c1d17e1d0e6cf0bb322d07f6 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 11 May 2016 16:20:29 +0100 Subject: [PATCH 5/9] Comment on GitHub PR with site changes --- bin/circle-dependencies-post | 1 + bin/circle-deploy-issues | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/bin/circle-dependencies-post b/bin/circle-dependencies-post index a651527b..fc75eb43 100755 --- a/bin/circle-dependencies-post +++ b/bin/circle-dependencies-post @@ -9,6 +9,7 @@ rm -f "$STATE" && touch "$STATE" if [ -n "$CI_PULL_REQUEST" -a "$CI_PULL_REQUEST" = "$CI_PULL_REQUESTS" ] ; then if PR=$(echo "$CI_PULL_REQUEST" | grep -oP '(?<=^https://github.com/weaveworks/weave/pull/)[0-9]+$') ; then + echo "GH_PR=$PR" >> "$STATE" if FILES=$(curl -s https://api.github.com/repos/weaveworks/weave/pulls/$PR/files | jq -r '.[]|.filename') ; then echo "PR touches [$FILES]" if ! echo "$FILES" | grep -v ^site/ ; then diff --git a/bin/circle-deploy-issues b/bin/circle-deploy-issues index ce3788a5..8923ade7 100755 --- a/bin/circle-deploy-issues +++ b/bin/circle-deploy-issues @@ -1,6 +1,7 @@ #!/bin/bash set -e +set -o pipefail source "$STATE" @@ -12,3 +13,36 @@ go get cd $SRCDIR bin/publish-site "$WP_DEV_URL" "$WP_DEV_USER" "$WP_DEV_PASSWORD" + +site_changes() { + curl -s https://api.github.com/repos/weaveworks/weave/pulls/$1/files | + jq -r '.[]|.status + " " + .filename' | + grep -oP '^(added|modified|removed) site/.*(?=\.md$)' +} + +format_comment() { + if [ ! -d .git ] || ! BRANCH=$(git symbolic-ref --short HEAD) || [ -z "$BRANCH" ] ; then + echo "Could not determine branch" >&2 + return 1 + fi + + echo "#### Documentation changes:" + while read ACTION PAGE; do + echo "$ACTION [${PAGE#site/}]($WP_DEV_URL/docs/net/${BRANCH#issues/}/${PAGE#site/}/)" + done | sort +} + +post_comment() { + jq -s -R '. | tostring | { body: . }' | + curl -s -d @- \ + -H "Authorization: Bearer $WP_GH_COMMENT_TOKEN" \ + -H 'Content-Type: application/json' \ + https://api.github.com/repos/weaveworks/weave/issues/$GH_PR/comments > /dev/null +} + +if [ -n "$WP_GH_COMMENT_TOKEN" -a -n "$GH_PR" ] ; then + echo ">>> Adding doc changelog to GitHub PR $GH_PR" + if CHANGES=$(site_changes $GH_PR) && [ -n "$CHANGES" ] ; then + echo "$CHANGES" | format_comment | post_comment + fi +fi From 263dffeedce5cbece5529233bc6738491aea4527 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 12 May 2016 14:52:57 +0100 Subject: [PATCH 6/9] Extract shared function --- bin/circle-deploy-issues | 16 +++++++--------- bin/circle-deploy-master | 8 +++----- bin/circle-deploy-release | 8 +++----- bin/circle-functions | 9 +++++++++ 4 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 bin/circle-functions diff --git a/bin/circle-deploy-issues b/bin/circle-deploy-issues index 8923ade7..0cf6a053 100755 --- a/bin/circle-deploy-issues +++ b/bin/circle-deploy-issues @@ -3,17 +3,10 @@ set -e set -o pipefail +source "$(dirname "$(readlink -f "$0")")/circle-functions" + source "$STATE" -go get github.com/weaveworks/wordepress -cd /home/ubuntu/src/github.com/weaveworks/wordepress -git checkout v1.0.0 -cd cmd/wordepress -go get - -cd $SRCDIR -bin/publish-site "$WP_DEV_URL" "$WP_DEV_USER" "$WP_DEV_PASSWORD" - site_changes() { curl -s https://api.github.com/repos/weaveworks/weave/pulls/$1/files | jq -r '.[]|.status + " " + .filename' | @@ -40,6 +33,11 @@ post_comment() { https://api.github.com/repos/weaveworks/weave/issues/$GH_PR/comments > /dev/null } +install_wordepress v1.0.0 + +cd $SRCDIR +bin/publish-site "$WP_DEV_URL" "$WP_DEV_USER" "$WP_DEV_PASSWORD" + if [ -n "$WP_GH_COMMENT_TOKEN" -a -n "$GH_PR" ] ; then echo ">>> Adding doc changelog to GitHub PR $GH_PR" if CHANGES=$(site_changes $GH_PR) && [ -n "$CHANGES" ] ; then diff --git a/bin/circle-deploy-master b/bin/circle-deploy-master index 2827ad91..14b484cb 100755 --- a/bin/circle-deploy-master +++ b/bin/circle-deploy-master @@ -2,6 +2,8 @@ set -e +source "$(dirname "$(readlink -f "$0")")/circle-functions" + source "$STATE" if [ -z "$SKIP_TESTS" ] ; then @@ -11,11 +13,7 @@ if [ -z "$SKIP_TESTS" ] ; then make publish fi -go get github.com/weaveworks/wordepress -cd /home/ubuntu/src/github.com/weaveworks/wordepress -git checkout v1.0.0 -cd cmd/wordepress -go get +install_wordepress v1.0.0 cd $SRCDIR bin/publish-site "$WP_DEV_URL" "$WP_DEV_USER" "$WP_DEV_PASSWORD" diff --git a/bin/circle-deploy-release b/bin/circle-deploy-release index ce2e9eb5..1e29a2fe 100755 --- a/bin/circle-deploy-release +++ b/bin/circle-deploy-release @@ -2,13 +2,11 @@ set -e +source "$(dirname "$(readlink -f "$0")")/circle-functions" + source "$STATE" -go get github.com/weaveworks/wordepress -cd /home/ubuntu/src/github.com/weaveworks/wordepress -git checkout v1.0.0 -cd cmd/wordepress -go get +install_wordepress v1.0.0 cd $SRCDIR bin/publish-site "$WP_LIVE_URL" "$WP_LIVE_USER" "$WP_LIVE_PASSWORD" diff --git a/bin/circle-functions b/bin/circle-functions new file mode 100644 index 00000000..8ed249cd --- /dev/null +++ b/bin/circle-functions @@ -0,0 +1,9 @@ +#!/bin/bash + +install_wordepress() { + go get github.com/weaveworks/wordepress + cd /home/ubuntu/src/github.com/weaveworks/wordepress + git checkout $1 + cd cmd/wordepress + go get +} From 835b3f3d6772c2a9077665467d9c5e27d759c88e Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 29 Sep 2016 11:00:29 +0100 Subject: [PATCH 7/9] Improve script names --- bin/circle-test-pre | 4 +--- bin/{circle-test-override => circle-test-smoke} | 0 bin/{circle-test-post => circle-test-teardown} | 0 bin/circle-test-unit | 11 +++++++++++ circle.yml | 6 ++++-- 5 files changed, 16 insertions(+), 5 deletions(-) rename bin/{circle-test-override => circle-test-smoke} (100%) rename bin/{circle-test-post => circle-test-teardown} (100%) create mode 100755 bin/circle-test-unit diff --git a/bin/circle-test-pre b/bin/circle-test-pre index e019c3b6..9c43e1c9 100755 --- a/bin/circle-test-pre +++ b/bin/circle-test-pre @@ -6,10 +6,8 @@ source "$STATE" if [ -z "$SKIP_TESTS" ] ; then cd $SRCDIR - make lint - COVERDIR=test/coverage make RM= tests - make COVERAGE=true RM= all make testrunner + make COVERAGE=true RM= all cd $SRCDIR/test ./gce.sh setup && eval $(./gce.sh hosts) && ./setup.sh diff --git a/bin/circle-test-override b/bin/circle-test-smoke similarity index 100% rename from bin/circle-test-override rename to bin/circle-test-smoke diff --git a/bin/circle-test-post b/bin/circle-test-teardown similarity index 100% rename from bin/circle-test-post rename to bin/circle-test-teardown diff --git a/bin/circle-test-unit b/bin/circle-test-unit new file mode 100755 index 00000000..93a51ec6 --- /dev/null +++ b/bin/circle-test-unit @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +source "$STATE" + +if [ -z "$SKIP_TESTS" ] ; then + cd $SRCDIR + make lint + COVERDIR=test/coverage make RM= tests +fi diff --git a/circle.yml b/circle.yml index 2d8d9a34..0870e542 100644 --- a/circle.yml +++ b/circle.yml @@ -25,11 +25,13 @@ test: - "$SRCDIR/bin/circle-test-pre": parallel: true override: - - "$SRCDIR/bin/circle-test-override": + - "$SRCDIR/bin/circle-test-unit": + parallel: true + - "$SRCDIR/bin/circle-test-smoke": parallel: true timeout: 300 post: - - "$SRCDIR/bin/circle-test-post": + - "$SRCDIR/bin/circle-test-teardown": parallel: true teardown: From 4c304c001312802e24da35cfa7c2d277e9ae9133 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Mon, 3 Oct 2016 14:01:15 +0100 Subject: [PATCH 8/9] Extract install-wordepress --- bin/circle-deploy-issues | 5 +---- bin/circle-deploy-master | 5 +---- bin/circle-deploy-release | 7 +------ bin/circle-functions | 9 --------- bin/install-wordepress | 12 ++++++++++++ 5 files changed, 15 insertions(+), 23 deletions(-) delete mode 100644 bin/circle-functions create mode 100755 bin/install-wordepress diff --git a/bin/circle-deploy-issues b/bin/circle-deploy-issues index 0cf6a053..d8617969 100755 --- a/bin/circle-deploy-issues +++ b/bin/circle-deploy-issues @@ -3,8 +3,6 @@ set -e set -o pipefail -source "$(dirname "$(readlink -f "$0")")/circle-functions" - source "$STATE" site_changes() { @@ -33,9 +31,8 @@ post_comment() { https://api.github.com/repos/weaveworks/weave/issues/$GH_PR/comments > /dev/null } -install_wordepress v1.0.0 - cd $SRCDIR +bin/install-wordepress v1.0.0 bin/publish-site "$WP_DEV_URL" "$WP_DEV_USER" "$WP_DEV_PASSWORD" if [ -n "$WP_GH_COMMENT_TOKEN" -a -n "$GH_PR" ] ; then diff --git a/bin/circle-deploy-master b/bin/circle-deploy-master index 14b484cb..3f6247b4 100755 --- a/bin/circle-deploy-master +++ b/bin/circle-deploy-master @@ -2,8 +2,6 @@ set -e -source "$(dirname "$(readlink -f "$0")")/circle-functions" - source "$STATE" if [ -z "$SKIP_TESTS" ] ; then @@ -13,7 +11,6 @@ if [ -z "$SKIP_TESTS" ] ; then make publish fi -install_wordepress v1.0.0 - cd $SRCDIR +bin/install-wordepress v1.0.0 bin/publish-site "$WP_DEV_URL" "$WP_DEV_USER" "$WP_DEV_PASSWORD" diff --git a/bin/circle-deploy-release b/bin/circle-deploy-release index 1e29a2fe..d7db8d44 100755 --- a/bin/circle-deploy-release +++ b/bin/circle-deploy-release @@ -2,11 +2,6 @@ set -e -source "$(dirname "$(readlink -f "$0")")/circle-functions" - -source "$STATE" - -install_wordepress v1.0.0 - cd $SRCDIR +bin/install-wordepress v1.0.0 bin/publish-site "$WP_LIVE_URL" "$WP_LIVE_USER" "$WP_LIVE_PASSWORD" diff --git a/bin/circle-functions b/bin/circle-functions deleted file mode 100644 index 8ed249cd..00000000 --- a/bin/circle-functions +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -install_wordepress() { - go get github.com/weaveworks/wordepress - cd /home/ubuntu/src/github.com/weaveworks/wordepress - git checkout $1 - cd cmd/wordepress - go get -} diff --git a/bin/install-wordepress b/bin/install-wordepress new file mode 100755 index 00000000..89562d8b --- /dev/null +++ b/bin/install-wordepress @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ $# -ne 1 ] ; then + echo USAGE: install-wordepress [COMMIT-ISH] >&2 + exit 1 +fi + +go get github.com/weaveworks/wordepress +cd /home/ubuntu/src/github.com/weaveworks/wordepress +git checkout $1 +cd cmd/wordepress +go get From b8e7d83f19f1f532071fe84f88d92a5f3da0dc93 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Mon, 3 Oct 2016 14:07:57 +0100 Subject: [PATCH 9/9] Rename SKIP_TESTS --- bin/circle-dependencies-post | 6 +++--- bin/circle-deploy-master | 2 +- bin/circle-teardown-pre | 2 +- bin/circle-test-pre | 2 +- bin/circle-test-smoke | 2 +- bin/circle-test-teardown | 2 +- bin/circle-test-unit | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/circle-dependencies-post b/bin/circle-dependencies-post index fc75eb43..866f0b9a 100755 --- a/bin/circle-dependencies-post +++ b/bin/circle-dependencies-post @@ -5,7 +5,7 @@ set -e # We need jq to analyse the PR files JSON, so install that first sudo apt-get -q update && sudo apt-get -q install bc jq -rm -f "$STATE" && touch "$STATE" +echo "TEST_AND_PUBLISH=1" > "$STATE" if [ -n "$CI_PULL_REQUEST" -a "$CI_PULL_REQUEST" = "$CI_PULL_REQUESTS" ] ; then if PR=$(echo "$CI_PULL_REQUEST" | grep -oP '(?<=^https://github.com/weaveworks/weave/pull/)[0-9]+$') ; then @@ -14,7 +14,7 @@ if [ -n "$CI_PULL_REQUEST" -a "$CI_PULL_REQUEST" = "$CI_PULL_REQUESTS" ] ; then echo "PR touches [$FILES]" if ! echo "$FILES" | grep -v ^site/ ; then echo "PR contains site changes only - skipping tests" - echo "SKIP_TESTS=1" >> "$STATE" + echo "TEST_AND_PUBLISH=" >> "$STATE" else echo "PR contains non-site changes - running tests" fi @@ -30,7 +30,7 @@ source "$STATE" mkdir -p $(dirname $SRCDIR) && cp -r $(pwd)/ $SRCDIR -if [ -z "$SKIP_TESTS" ] ; then +if [ -n "$TEST_AND_PUBLISH" ] ; then bin/setup-circleci-secrets "$SECRET_PASSWORD" cd $SRCDIR; git submodule update --init if [ "$CIRCLE_NODE_INDEX" = "0" ] ; then diff --git a/bin/circle-deploy-master b/bin/circle-deploy-master index 3f6247b4..8afceb87 100755 --- a/bin/circle-deploy-master +++ b/bin/circle-deploy-master @@ -4,7 +4,7 @@ set -e source "$STATE" -if [ -z "$SKIP_TESTS" ] ; then +if [ -n "$TEST_AND_PUBLISH" ] ; then docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS cd $SRCDIR make clean-bin diff --git a/bin/circle-teardown-pre b/bin/circle-teardown-pre index 4670e3f1..d11b1111 100755 --- a/bin/circle-teardown-pre +++ b/bin/circle-teardown-pre @@ -4,7 +4,7 @@ set -e source "$STATE" -if [ -z "$SKIP_TESTS" ] ; then +if [ -n "$TEST_AND_PUBLISH" ] ; then if [ "$CIRCLE_NODE_INDEX" = "0" ] ; then go get github.com/mattn/goveralls goveralls -repotoken $COVERALLS_REPO_TOKEN -coverprofile=$SRCDIR/test/profile.cov -service=circleci diff --git a/bin/circle-test-pre b/bin/circle-test-pre index 9c43e1c9..cfd3949d 100755 --- a/bin/circle-test-pre +++ b/bin/circle-test-pre @@ -4,7 +4,7 @@ set -e source "$STATE" -if [ -z "$SKIP_TESTS" ] ; then +if [ -n "$TEST_AND_PUBLISH" ] ; then cd $SRCDIR make testrunner make COVERAGE=true RM= all diff --git a/bin/circle-test-smoke b/bin/circle-test-smoke index 93aa9883..709c21fa 100755 --- a/bin/circle-test-smoke +++ b/bin/circle-test-smoke @@ -4,7 +4,7 @@ set -e source "$STATE" -if [ -z "$SKIP_TESTS" ] ; then +if [ -n "$TEST_AND_PUBLISH" ] ; then cd $SRCDIR/test eval $(./gce.sh hosts) export COVERAGE=true diff --git a/bin/circle-test-teardown b/bin/circle-test-teardown index dac2db4f..44711219 100755 --- a/bin/circle-test-teardown +++ b/bin/circle-test-teardown @@ -4,7 +4,7 @@ set -e source "$STATE" -if [ -z "$SKIP_TESTS" ] ; then +if [ -n "$TEST_AND_PUBLISH" ] ; then cd $SRCDIR/test ./gce.sh destroy test "$CIRCLE_NODE_INDEX" != "0" || (cd $SRCDIR/test; ./gen_coverage_reports.sh) diff --git a/bin/circle-test-unit b/bin/circle-test-unit index 93a51ec6..b9c98eb4 100755 --- a/bin/circle-test-unit +++ b/bin/circle-test-unit @@ -4,7 +4,7 @@ set -e source "$STATE" -if [ -z "$SKIP_TESTS" ] ; then +if [ -n "$TEST_AND_PUBLISH" ] ; then cd $SRCDIR make lint COVERDIR=test/coverage make RM= tests