From 7742da1f0be9b3015afc8430b6a13ecc035fda37 Mon Sep 17 00:00:00 2001 From: Direside Date: Thu, 19 Mar 2020 18:02:13 -0700 Subject: [PATCH 1/5] Added CircleCI pipeline to test on branch and build and push on master. --- .circleci/config-compiled.yml | 361 ++++++++++++++++++++++++++++++++++ .circleci/config.yml | 159 +++++++++++++++ .gitignore | 2 + Makefile | 8 + 4 files changed, 530 insertions(+) create mode 100644 .circleci/config-compiled.yml create mode 100644 .circleci/config.yml diff --git a/.circleci/config-compiled.yml b/.circleci/config-compiled.yml new file mode 100644 index 000000000..92e73b02e --- /dev/null +++ b/.circleci/config-compiled.yml @@ -0,0 +1,361 @@ +# Orb 'commitdev/slack-message@0.0.3' resolved to 'commitdev/slack-message@0.0.3' +# Orb 'commitdev/version-tag@0.0.3' resolved to 'commitdev/version-tag@0.0.3' +version: 2 +jobs: + checkout_code: + docker: + - image: circleci/golang:1.13.8 + steps: + - run: + name: Checkout (Shallow) + command: | + #!/bin/sh + set -e + + # Workaround old docker images with incorrect $HOME + # check https://github.com/docker/docker/issues/2968 for details + if [ "${HOME}" = "/" ] + then + export HOME=$(getent passwd $(id -un) | cut -d: -f6) + fi + + mkdir -p ~/.ssh + + echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== + bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==' >> ~/.ssh/known_hosts + + (umask 077; touch ~/.ssh/id_rsa) + chmod 0600 ~/.ssh/id_rsa + (cat < ~/.ssh/id_rsa + $CHECKOUT_KEY + EOF + ) + + # use git+ssh instead of https + git config --global url."ssh://git@github.com".insteadOf "https://github.com" || true + + if [ -e /home/circleci/project/.git ] + then + cd /home/circleci/project + git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true + else + mkdir -p /home/circleci/project + cd /home/circleci/project + git clone --depth=1 "$CIRCLE_REPOSITORY_URL" . + fi + + if [ -n "$CIRCLE_TAG" ] + then + git fetch --depth=10 --force origin "refs/tags/${CIRCLE_TAG}" + elif [[ "$CIRCLE_BRANCH" =~ ^pull\/* ]] + then + # For PR from Fork + git fetch --depth=10 --force origin "$CIRCLE_BRANCH/head:remotes/origin/$CIRCLE_BRANCH" + else + git fetch --depth=10 --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH" + fi + + if [ -n "$CIRCLE_TAG" ] + then + git reset --hard "$CIRCLE_SHA1" + git checkout -q "$CIRCLE_TAG" + elif [ -n "$CIRCLE_BRANCH" ] + then + git reset --hard "$CIRCLE_SHA1" + git checkout -q -B "$CIRCLE_BRANCH" + fi + + git reset --hard "$CIRCLE_SHA1" + pwd + - persist_to_workspace: + root: /home/circleci/project + paths: + - . + unit_test: + docker: + - image: circleci/golang:1.13.8 + working_directory: /home/circleci/project + steps: + - checkout + - attach_workspace: + at: /home/circleci/project + - restore_cache: + keys: + - v1-pkg-cache-{{ checksum "go.sum" }} + - v1-pkg-cache- + - run: + name: Run unit tests + command: | + go get -u github.com/jstemmer/go-junit-report + mkdir -p test-reports + PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname) + echo "Tests: $PACKAGE_NAMES" + go test -v $PACKAGE_NAMES | go-junit-report > test-reports/junit.xml + - save_cache: + key: v1-pkg-cache-{{ checksum "go.sum" }} + paths: + - /go/pkg + - store_test_results: + path: test-reports + - store_artifacts: + path: test-reports + build_and_push: + machine: + docker_layer_caching: true + steps: + - attach_workspace: + at: /home/circleci/project + - run: + name: Checkout (Shallow) + command: | + #!/bin/sh + set -e + + # Workaround old docker images with incorrect $HOME + # check https://github.com/docker/docker/issues/2968 for details + if [ "${HOME}" = "/" ] + then + export HOME=$(getent passwd $(id -un) | cut -d: -f6) + fi + + mkdir -p ~/.ssh + + echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== + bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==' >> ~/.ssh/known_hosts + + (umask 077; touch ~/.ssh/id_rsa) + chmod 0600 ~/.ssh/id_rsa + (cat < ~/.ssh/id_rsa + $CHECKOUT_KEY + EOF + ) + + # use git+ssh instead of https + git config --global url."ssh://git@github.com".insteadOf "https://github.com" || true + + if [ -e /home/circleci/project/.git ] + then + cd /home/circleci/project + git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true + else + mkdir -p /home/circleci/project + cd /home/circleci/project + git clone --depth=1 "$CIRCLE_REPOSITORY_URL" . + fi + + if [ -n "$CIRCLE_TAG" ] + then + git fetch --depth=10 --force origin "refs/tags/${CIRCLE_TAG}" + elif [[ "$CIRCLE_BRANCH" =~ ^pull\/* ]] + then + # For PR from Fork + git fetch --depth=10 --force origin "$CIRCLE_BRANCH/head:remotes/origin/$CIRCLE_BRANCH" + else + git fetch --depth=10 --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH" + fi + + if [ -n "$CIRCLE_TAG" ] + then + git reset --hard "$CIRCLE_SHA1" + git checkout -q "$CIRCLE_TAG" + elif [ -n "$CIRCLE_BRANCH" ] + then + git reset --hard "$CIRCLE_SHA1" + git checkout -q -B "$CIRCLE_BRANCH" + fi + + git reset --hard "$CIRCLE_SHA1" + pwd + - attach_workspace: + at: /tmp/workspace + - run: + name: Create Version Tag + command: "if [ -f /tmp/workspace/version.txt ]; then\n echo \"version.txt already present in your workspace, setting enviroment variable.\"\n echo \"export VERSION_TAG=$(cat /tmp/workspace/version.txt)\" >> $BASH_ENV\nelse\n COMMIT_TAG=$(git rev-parse --short $CIRCLE_SHA1)\n if [ \"number-tag\" = \"number-tag\" ];then\n VERSION_TAG=\"$CIRCLE_BUILD_NUM-$COMMIT_TAG\"\n elif [ \"number-tag\" = \"tag-only\" ];then\n VERSION_TAG=\"$COMMIT_TAG\"\n elif [ \"number-tag\" = \"number-only\" ];then\n VERSION_TAG=\"$CIRCLE_BUILD_NUM\"\n else\n echo \"Unsupported format for version-tag.\"\n exit 1\n fi\n echo \"Saving version-tag to /tmp/workspace/version.txt\"\n echo \"$VERSION_TAG\" >> /tmp/workspace/version.txt\n echo \"export VERSION_TAG=\\\"$CIRCLE_BUILD_NUM-$COMMIT_TAG\\\"\" >> $BASH_ENV\n\n echo \"Created version tag: VERSION_TAG=${VERSION_TAG}\n This will be available in all steps in this job,\n but not in other jobs as part of the workflow. \n To use in other jobs, add the version-tag/get command in them.\"\nfi\n" + - persist_to_workspace: + root: /tmp/workspace + paths: + - version.txt + - run: + name: Build Docker image + command: | + make ci-docker-build + - run: + name: Push to Docker Hub + command: | + make ci-docker-push +workflows: + version: 2 + build_test_and_deploy: + jobs: + - checkout_code + - unit_test: + requires: + - checkout_code + - build_and_push: + filters: + branches: + only: + - /^master$/ + requires: + - unit_test + +# Original config.yml file: +# --- +# version: 2.1 +# orbs: +# slack-message: commitdev/slack-message@0.0.3 +# version-tag: commitdev/version-tag@0.0.3 +# +# variables: +# - &workspace /home/circleci/project +# - &build-image circleci/golang:1.13.8 +# +# aliases: +# # Shallow Clone - this allows us to cut the 2 minute repo clone down to about 10 seconds for repos with 50,000 commits+ +# - &checkout-shallow +# name: Checkout (Shallow) +# command: | +# #!/bin/sh +# set -e +# +# # Workaround old docker images with incorrect $HOME +# # check https://github.com/docker/docker/issues/2968 for details +# if [ \"${HOME}\" = \"/\" ] +# then +# export HOME=$(getent passwd $(id -un) | cut -d: -f6) +# fi +# +# mkdir -p ~/.ssh +# +# echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== +# bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==' >> ~/.ssh/known_hosts +# +# (umask 077; touch ~/.ssh/id_rsa) +# chmod 0600 ~/.ssh/id_rsa +# (cat \\< ~/.ssh/id_rsa +# $CHECKOUT_KEY +# EOF +# ) +# +# # use git+ssh instead of https +# git config --global url.\"ssh://git@github.com\".insteadOf \"https://github.com\" || true +# +# if [ -e /home/circleci/project/.git ] +# then +# cd /home/circleci/project +# git remote set-url origin \"$CIRCLE_REPOSITORY_URL\" || true +# else +# mkdir -p /home/circleci/project +# cd /home/circleci/project +# git clone --depth=1 \"$CIRCLE_REPOSITORY_URL\" . +# fi +# +# if [ -n \"$CIRCLE_TAG\" ] +# then +# git fetch --depth=10 --force origin \"refs/tags/${CIRCLE_TAG}\" +# elif [[ \"$CIRCLE_BRANCH\" =~ ^pull\\/* ]] +# then +# # For PR from Fork +# git fetch --depth=10 --force origin \"$CIRCLE_BRANCH/head:remotes/origin/$CIRCLE_BRANCH\" +# else +# git fetch --depth=10 --force origin \"$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH\" +# fi +# +# if [ -n \"$CIRCLE_TAG\" ] +# then +# git reset --hard \"$CIRCLE_SHA1\" +# git checkout -q \"$CIRCLE_TAG\" +# elif [ -n \"$CIRCLE_BRANCH\" ] +# then +# git reset --hard \"$CIRCLE_SHA1\" +# git checkout -q -B \"$CIRCLE_BRANCH\" +# fi +# +# git reset --hard \"$CIRCLE_SHA1\" +# pwd +# +# jobs: +# checkout_code: +# docker: +# - image: *build-image +# steps: +# - run: *checkout-shallow +# - persist_to_workspace: +# root: /home/circleci/project +# paths: +# - . +# +# unit_test: +# docker: +# - image: *build-image +# working_directory: *workspace +# steps: # steps that comprise the `build` job +# - checkout +# - attach_workspace: +# at: *workspace +# +# - restore_cache: # restores saved cache if no changes are detected since last run +# keys: +# - v1-pkg-cache-{{ checksum \"go.sum\" }} +# - v1-pkg-cache- +# +# - run: +# name: Run unit tests +# # store the results of our tests in the $TEST_RESULTS directory +# command: | +# go get -u github.com/jstemmer/go-junit-report +# mkdir -p test-reports +# PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname) +# echo \"Tests: $PACKAGE_NAMES\" +# go test -v $PACKAGE_NAMES | go-junit-report > test-reports/junit.xml +# +# - save_cache: # Store cache in the /go/pkg directory +# key: v1-pkg-cache-{{ checksum \"go.sum\" }} +# paths: +# - \"/go/pkg\" +# +# - store_test_results: +# path: test-reports +# +# - store_artifacts: +# path: test-reports +# +# # Requires the SLACK_WEBHOOK +# # - slack/notify-on-failure +# +# build_and_push: +# machine: +# docker_layer_caching: true # only for performance plan circleci accounts +# steps: +# - attach_workspace: +# at: *workspace +# - run: *checkout-shallow +# - version-tag/create +# - run: +# name: Build Docker image +# command: | +# make ci-docker-build +# - run: +# name: Push to Docker Hub +# command: | +# make ci-docker-push +# +# +# workflows: +# version: 2 +# # The main workflow. Check out the code, build it, push it, deploy to staging, test, deploy to production +# build_test_and_deploy: +# jobs: +# - checkout_code +# +# - unit_test: +# requires: +# - checkout_code +# +# - build_and_push: +# requires: +# - unit_test +# filters: +# branches: +# only: # only branches matching the below regex filters will run +# - /^master$/ \ No newline at end of file diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..e92a72f25 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,159 @@ +--- +version: 2.1 +orbs: + slack-message: commitdev/slack-message@0.0.3 + version-tag: commitdev/version-tag@0.0.3 + +variables: + - &workspace /home/circleci/project + - &build-image circleci/golang:1.13.8 + +aliases: + # Shallow Clone - this allows us to cut the 2 minute repo clone down to about 10 seconds for repos with 50,000 commits+ + - &checkout-shallow + name: Checkout (Shallow) + command: | + #!/bin/sh + set -e + + # Workaround old docker images with incorrect $HOME + # check https://github.com/docker/docker/issues/2968 for details + if [ "${HOME}" = "/" ] + then + export HOME=$(getent passwd $(id -un) | cut -d: -f6) + fi + + mkdir -p ~/.ssh + + echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== + bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==' >> ~/.ssh/known_hosts + + (umask 077; touch ~/.ssh/id_rsa) + chmod 0600 ~/.ssh/id_rsa + (cat \< ~/.ssh/id_rsa + $CHECKOUT_KEY + EOF + ) + + # use git+ssh instead of https + git config --global url."ssh://git@github.com".insteadOf "https://github.com" || true + + if [ -e /home/circleci/project/.git ] + then + cd /home/circleci/project + git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true + else + mkdir -p /home/circleci/project + cd /home/circleci/project + git clone --depth=1 "$CIRCLE_REPOSITORY_URL" . + fi + + if [ -n "$CIRCLE_TAG" ] + then + git fetch --depth=10 --force origin "refs/tags/${CIRCLE_TAG}" + elif [[ "$CIRCLE_BRANCH" =~ ^pull\/* ]] + then + # For PR from Fork + git fetch --depth=10 --force origin "$CIRCLE_BRANCH/head:remotes/origin/$CIRCLE_BRANCH" + else + git fetch --depth=10 --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH" + fi + + if [ -n "$CIRCLE_TAG" ] + then + git reset --hard "$CIRCLE_SHA1" + git checkout -q "$CIRCLE_TAG" + elif [ -n "$CIRCLE_BRANCH" ] + then + git reset --hard "$CIRCLE_SHA1" + git checkout -q -B "$CIRCLE_BRANCH" + fi + + git reset --hard "$CIRCLE_SHA1" + pwd + +jobs: + checkout_code: + docker: + - image: *build-image + steps: + - run: *checkout-shallow + - persist_to_workspace: + root: /home/circleci/project + paths: + - . + + unit_test: + docker: + - image: *build-image + working_directory: *workspace + steps: # steps that comprise the `build` job + - attach_workspace: + at: *workspace + + - restore_cache: # restores saved cache if no changes are detected since last run + keys: + - v1-pkg-cache-{{ checksum "go.sum" }} + - v1-pkg-cache- + + - run: + name: Run unit tests + # store the results of our tests in the $TEST_RESULTS directory + command: | + go get -u github.com/jstemmer/go-junit-report + mkdir -p test-reports + PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname) + echo "Tests: $PACKAGE_NAMES" + go test -v $PACKAGE_NAMES | go-junit-report > test-reports/junit.xml + + - save_cache: # Store cache in the /go/pkg directory + key: v1-pkg-cache-{{ checksum "go.sum" }} + paths: + - "/go/pkg" + + - store_test_results: + path: test-reports + + - store_artifacts: + path: test-reports + + # Requires the SLACK_WEBHOOK + # - slack/notify-on-failure + + build_and_push: + machine: + docker_layer_caching: true # only for performance plan circleci accounts + steps: + - attach_workspace: + at: *workspace + - run: *checkout-shallow + - version-tag/create + - run: + name: Build Docker image + command: | + make ci-docker-build + - run: + name: Push to Docker Hub + command: | + make ci-docker-push + + +workflows: + version: 2 + # The main workflow. Check out the code, build it, push it, deploy to staging, test, deploy to production + build_test_and_deploy: + jobs: + - checkout_code + + - unit_test: + requires: + - checkout_code + + - build_and_push: + requires: + - unit_test + filters: + branches: + only: # only branches matching the below regex filters will run + - /^master$/ + diff --git a/.gitignore b/.gitignore index d2d9415a1..a17274b34 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ packrd .history/ tmp .vscode +example/ +test-reports/ \ No newline at end of file diff --git a/Makefile b/Makefile index 872d12f5f..5846f1ea6 100644 --- a/Makefile +++ b/Makefile @@ -20,3 +20,11 @@ build: # Installs the CLI int your GOPATH install-go: go build -o ${GOPATH}/bin/commit0 + +# CI Commands used on CircleCI +ci-docker-build: + docker build . -t commitdev/commit0:${VERSION_TAG} -t commitdev/commit0:latest + +ci-docker-push: + echo "${DOCKERHUB_PASS}" | docker login -u "${DOCKERHUB_USER}" --password-stdin + docker push commitdev/commit0:${VERSION_TAG} From ddc70ff26442126255890773655c29ff52e39243 Mon Sep 17 00:00:00 2001 From: Direside Date: Thu, 19 Mar 2020 18:11:46 -0700 Subject: [PATCH 2/5] Removed compiled circleci file, added to .gitignore --- .circleci/config-compiled.yml | 361 ---------------------------------- .gitignore | 3 +- 2 files changed, 2 insertions(+), 362 deletions(-) delete mode 100644 .circleci/config-compiled.yml diff --git a/.circleci/config-compiled.yml b/.circleci/config-compiled.yml deleted file mode 100644 index 92e73b02e..000000000 --- a/.circleci/config-compiled.yml +++ /dev/null @@ -1,361 +0,0 @@ -# Orb 'commitdev/slack-message@0.0.3' resolved to 'commitdev/slack-message@0.0.3' -# Orb 'commitdev/version-tag@0.0.3' resolved to 'commitdev/version-tag@0.0.3' -version: 2 -jobs: - checkout_code: - docker: - - image: circleci/golang:1.13.8 - steps: - - run: - name: Checkout (Shallow) - command: | - #!/bin/sh - set -e - - # Workaround old docker images with incorrect $HOME - # check https://github.com/docker/docker/issues/2968 for details - if [ "${HOME}" = "/" ] - then - export HOME=$(getent passwd $(id -un) | cut -d: -f6) - fi - - mkdir -p ~/.ssh - - echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== - bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==' >> ~/.ssh/known_hosts - - (umask 077; touch ~/.ssh/id_rsa) - chmod 0600 ~/.ssh/id_rsa - (cat < ~/.ssh/id_rsa - $CHECKOUT_KEY - EOF - ) - - # use git+ssh instead of https - git config --global url."ssh://git@github.com".insteadOf "https://github.com" || true - - if [ -e /home/circleci/project/.git ] - then - cd /home/circleci/project - git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true - else - mkdir -p /home/circleci/project - cd /home/circleci/project - git clone --depth=1 "$CIRCLE_REPOSITORY_URL" . - fi - - if [ -n "$CIRCLE_TAG" ] - then - git fetch --depth=10 --force origin "refs/tags/${CIRCLE_TAG}" - elif [[ "$CIRCLE_BRANCH" =~ ^pull\/* ]] - then - # For PR from Fork - git fetch --depth=10 --force origin "$CIRCLE_BRANCH/head:remotes/origin/$CIRCLE_BRANCH" - else - git fetch --depth=10 --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH" - fi - - if [ -n "$CIRCLE_TAG" ] - then - git reset --hard "$CIRCLE_SHA1" - git checkout -q "$CIRCLE_TAG" - elif [ -n "$CIRCLE_BRANCH" ] - then - git reset --hard "$CIRCLE_SHA1" - git checkout -q -B "$CIRCLE_BRANCH" - fi - - git reset --hard "$CIRCLE_SHA1" - pwd - - persist_to_workspace: - root: /home/circleci/project - paths: - - . - unit_test: - docker: - - image: circleci/golang:1.13.8 - working_directory: /home/circleci/project - steps: - - checkout - - attach_workspace: - at: /home/circleci/project - - restore_cache: - keys: - - v1-pkg-cache-{{ checksum "go.sum" }} - - v1-pkg-cache- - - run: - name: Run unit tests - command: | - go get -u github.com/jstemmer/go-junit-report - mkdir -p test-reports - PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname) - echo "Tests: $PACKAGE_NAMES" - go test -v $PACKAGE_NAMES | go-junit-report > test-reports/junit.xml - - save_cache: - key: v1-pkg-cache-{{ checksum "go.sum" }} - paths: - - /go/pkg - - store_test_results: - path: test-reports - - store_artifacts: - path: test-reports - build_and_push: - machine: - docker_layer_caching: true - steps: - - attach_workspace: - at: /home/circleci/project - - run: - name: Checkout (Shallow) - command: | - #!/bin/sh - set -e - - # Workaround old docker images with incorrect $HOME - # check https://github.com/docker/docker/issues/2968 for details - if [ "${HOME}" = "/" ] - then - export HOME=$(getent passwd $(id -un) | cut -d: -f6) - fi - - mkdir -p ~/.ssh - - echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== - bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==' >> ~/.ssh/known_hosts - - (umask 077; touch ~/.ssh/id_rsa) - chmod 0600 ~/.ssh/id_rsa - (cat < ~/.ssh/id_rsa - $CHECKOUT_KEY - EOF - ) - - # use git+ssh instead of https - git config --global url."ssh://git@github.com".insteadOf "https://github.com" || true - - if [ -e /home/circleci/project/.git ] - then - cd /home/circleci/project - git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true - else - mkdir -p /home/circleci/project - cd /home/circleci/project - git clone --depth=1 "$CIRCLE_REPOSITORY_URL" . - fi - - if [ -n "$CIRCLE_TAG" ] - then - git fetch --depth=10 --force origin "refs/tags/${CIRCLE_TAG}" - elif [[ "$CIRCLE_BRANCH" =~ ^pull\/* ]] - then - # For PR from Fork - git fetch --depth=10 --force origin "$CIRCLE_BRANCH/head:remotes/origin/$CIRCLE_BRANCH" - else - git fetch --depth=10 --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH" - fi - - if [ -n "$CIRCLE_TAG" ] - then - git reset --hard "$CIRCLE_SHA1" - git checkout -q "$CIRCLE_TAG" - elif [ -n "$CIRCLE_BRANCH" ] - then - git reset --hard "$CIRCLE_SHA1" - git checkout -q -B "$CIRCLE_BRANCH" - fi - - git reset --hard "$CIRCLE_SHA1" - pwd - - attach_workspace: - at: /tmp/workspace - - run: - name: Create Version Tag - command: "if [ -f /tmp/workspace/version.txt ]; then\n echo \"version.txt already present in your workspace, setting enviroment variable.\"\n echo \"export VERSION_TAG=$(cat /tmp/workspace/version.txt)\" >> $BASH_ENV\nelse\n COMMIT_TAG=$(git rev-parse --short $CIRCLE_SHA1)\n if [ \"number-tag\" = \"number-tag\" ];then\n VERSION_TAG=\"$CIRCLE_BUILD_NUM-$COMMIT_TAG\"\n elif [ \"number-tag\" = \"tag-only\" ];then\n VERSION_TAG=\"$COMMIT_TAG\"\n elif [ \"number-tag\" = \"number-only\" ];then\n VERSION_TAG=\"$CIRCLE_BUILD_NUM\"\n else\n echo \"Unsupported format for version-tag.\"\n exit 1\n fi\n echo \"Saving version-tag to /tmp/workspace/version.txt\"\n echo \"$VERSION_TAG\" >> /tmp/workspace/version.txt\n echo \"export VERSION_TAG=\\\"$CIRCLE_BUILD_NUM-$COMMIT_TAG\\\"\" >> $BASH_ENV\n\n echo \"Created version tag: VERSION_TAG=${VERSION_TAG}\n This will be available in all steps in this job,\n but not in other jobs as part of the workflow. \n To use in other jobs, add the version-tag/get command in them.\"\nfi\n" - - persist_to_workspace: - root: /tmp/workspace - paths: - - version.txt - - run: - name: Build Docker image - command: | - make ci-docker-build - - run: - name: Push to Docker Hub - command: | - make ci-docker-push -workflows: - version: 2 - build_test_and_deploy: - jobs: - - checkout_code - - unit_test: - requires: - - checkout_code - - build_and_push: - filters: - branches: - only: - - /^master$/ - requires: - - unit_test - -# Original config.yml file: -# --- -# version: 2.1 -# orbs: -# slack-message: commitdev/slack-message@0.0.3 -# version-tag: commitdev/version-tag@0.0.3 -# -# variables: -# - &workspace /home/circleci/project -# - &build-image circleci/golang:1.13.8 -# -# aliases: -# # Shallow Clone - this allows us to cut the 2 minute repo clone down to about 10 seconds for repos with 50,000 commits+ -# - &checkout-shallow -# name: Checkout (Shallow) -# command: | -# #!/bin/sh -# set -e -# -# # Workaround old docker images with incorrect $HOME -# # check https://github.com/docker/docker/issues/2968 for details -# if [ \"${HOME}\" = \"/\" ] -# then -# export HOME=$(getent passwd $(id -un) | cut -d: -f6) -# fi -# -# mkdir -p ~/.ssh -# -# echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== -# bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==' >> ~/.ssh/known_hosts -# -# (umask 077; touch ~/.ssh/id_rsa) -# chmod 0600 ~/.ssh/id_rsa -# (cat \\< ~/.ssh/id_rsa -# $CHECKOUT_KEY -# EOF -# ) -# -# # use git+ssh instead of https -# git config --global url.\"ssh://git@github.com\".insteadOf \"https://github.com\" || true -# -# if [ -e /home/circleci/project/.git ] -# then -# cd /home/circleci/project -# git remote set-url origin \"$CIRCLE_REPOSITORY_URL\" || true -# else -# mkdir -p /home/circleci/project -# cd /home/circleci/project -# git clone --depth=1 \"$CIRCLE_REPOSITORY_URL\" . -# fi -# -# if [ -n \"$CIRCLE_TAG\" ] -# then -# git fetch --depth=10 --force origin \"refs/tags/${CIRCLE_TAG}\" -# elif [[ \"$CIRCLE_BRANCH\" =~ ^pull\\/* ]] -# then -# # For PR from Fork -# git fetch --depth=10 --force origin \"$CIRCLE_BRANCH/head:remotes/origin/$CIRCLE_BRANCH\" -# else -# git fetch --depth=10 --force origin \"$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH\" -# fi -# -# if [ -n \"$CIRCLE_TAG\" ] -# then -# git reset --hard \"$CIRCLE_SHA1\" -# git checkout -q \"$CIRCLE_TAG\" -# elif [ -n \"$CIRCLE_BRANCH\" ] -# then -# git reset --hard \"$CIRCLE_SHA1\" -# git checkout -q -B \"$CIRCLE_BRANCH\" -# fi -# -# git reset --hard \"$CIRCLE_SHA1\" -# pwd -# -# jobs: -# checkout_code: -# docker: -# - image: *build-image -# steps: -# - run: *checkout-shallow -# - persist_to_workspace: -# root: /home/circleci/project -# paths: -# - . -# -# unit_test: -# docker: -# - image: *build-image -# working_directory: *workspace -# steps: # steps that comprise the `build` job -# - checkout -# - attach_workspace: -# at: *workspace -# -# - restore_cache: # restores saved cache if no changes are detected since last run -# keys: -# - v1-pkg-cache-{{ checksum \"go.sum\" }} -# - v1-pkg-cache- -# -# - run: -# name: Run unit tests -# # store the results of our tests in the $TEST_RESULTS directory -# command: | -# go get -u github.com/jstemmer/go-junit-report -# mkdir -p test-reports -# PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname) -# echo \"Tests: $PACKAGE_NAMES\" -# go test -v $PACKAGE_NAMES | go-junit-report > test-reports/junit.xml -# -# - save_cache: # Store cache in the /go/pkg directory -# key: v1-pkg-cache-{{ checksum \"go.sum\" }} -# paths: -# - \"/go/pkg\" -# -# - store_test_results: -# path: test-reports -# -# - store_artifacts: -# path: test-reports -# -# # Requires the SLACK_WEBHOOK -# # - slack/notify-on-failure -# -# build_and_push: -# machine: -# docker_layer_caching: true # only for performance plan circleci accounts -# steps: -# - attach_workspace: -# at: *workspace -# - run: *checkout-shallow -# - version-tag/create -# - run: -# name: Build Docker image -# command: | -# make ci-docker-build -# - run: -# name: Push to Docker Hub -# command: | -# make ci-docker-push -# -# -# workflows: -# version: 2 -# # The main workflow. Check out the code, build it, push it, deploy to staging, test, deploy to production -# build_test_and_deploy: -# jobs: -# - checkout_code -# -# - unit_test: -# requires: -# - checkout_code -# -# - build_and_push: -# requires: -# - unit_test -# filters: -# branches: -# only: # only branches matching the below regex filters will run -# - /^master$/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index a17274b34..35fe49811 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ packrd tmp .vscode example/ -test-reports/ \ No newline at end of file +test-reports/ +.circleci/config-compiled.yml \ No newline at end of file From 808d22dc6d8dfd070fda0d28b0defc119c4b58da Mon Sep 17 00:00:00 2001 From: Direside Date: Fri, 20 Mar 2020 14:09:25 -0700 Subject: [PATCH 3/5] Added version command update to CI pipeline. --- .circleci/config.yml | 12 ++++++++---- cmd/version.go | 2 +- updateVersion.sh | 12 ++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100755 updateVersion.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index e92a72f25..afdc704d8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -128,6 +128,10 @@ jobs: at: *workspace - run: *checkout-shallow - version-tag/create + - run: + name: Update Version command + command: | + ./updateVersion.sh "$VERSION_TAG" - run: name: Build Docker image command: | @@ -152,8 +156,8 @@ workflows: - build_and_push: requires: - unit_test - filters: - branches: - only: # only branches matching the below regex filters will run - - /^master$/ + # filters: + # branches: + # only: # only branches matching the below regex filters will run + # - /^master$/ diff --git a/cmd/version.go b/cmd/version.go index 6d3167bef..def3b099c 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -14,6 +14,6 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "Print the version number of commit0", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("v0.0.1") + fmt.Println("v0.0.0") // Updated via updateVersion.sh }, } diff --git a/updateVersion.sh b/updateVersion.sh new file mode 100755 index 000000000..f847fecc2 --- /dev/null +++ b/updateVersion.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +VERSION=$1 + +if [ -z "$VERSION" ]; then + echo "Usage: ./updateVersion.sh " + exit 1 +fi + +sed "s/\t\tfmt.Println(\"v0.0.0\")/\t\tfmt.Println(\"${VERSION}\")/g" cmd/version.go > cmd/version.go.update + +mv cmd/version.go.update cmd/version.go \ No newline at end of file From c1d4069d837ee26d2b4554c5b9103c9f278b3755 Mon Sep 17 00:00:00 2001 From: Direside Date: Fri, 20 Mar 2020 14:35:02 -0700 Subject: [PATCH 4/5] Removed docker caching as we aren't on paid plan. --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index afdc704d8..4cc94bdb8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,7 +122,8 @@ jobs: build_and_push: machine: - docker_layer_caching: true # only for performance plan circleci accounts + image: circleci/classic:latest + # docker_layer_caching: true # only for performance plan circleci accounts steps: - attach_workspace: at: *workspace From 0c2b1d7bb42c011464e76b87b29c9e8499bc7e84 Mon Sep 17 00:00:00 2001 From: Direside Date: Fri, 20 Mar 2020 14:57:43 -0700 Subject: [PATCH 5/5] Removed debug code. Removed VERSION from Makefile as it's not used and could cause confusion. --- .circleci/config.yml | 8 ++++---- Makefile | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4cc94bdb8..cdaa43264 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -157,8 +157,8 @@ workflows: - build_and_push: requires: - unit_test - # filters: - # branches: - # only: # only branches matching the below regex filters will run - # - /^master$/ + filters: + branches: + only: # only branches matching the below regex filters will run + - /^master$/ diff --git a/Makefile b/Makefile index 5846f1ea6..5330a75e4 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,3 @@ -VERSION:= 0.0.1 - check: go test ./... @@ -26,5 +24,5 @@ ci-docker-build: docker build . -t commitdev/commit0:${VERSION_TAG} -t commitdev/commit0:latest ci-docker-push: - echo "${DOCKERHUB_PASS}" | docker login -u "${DOCKERHUB_USER}" --password-stdin + echo "${DOCKERHUB_PASS}" | docker login -u commitdev --password-stdin docker push commitdev/commit0:${VERSION_TAG}