From 249924cb380eeb7094ccf6f888c0e0ac45e5ca94 Mon Sep 17 00:00:00 2001 From: Simon Bein Date: Sat, 18 Aug 2018 18:36:40 +0200 Subject: [PATCH] Add ci and cd (github release) (#3) * Add Circle-CI config * Update config.yml to be Circle CI 2.0 compatible * Add support for store_test_results * Change test output format to junit, so circle ci can automatically recognize it * Add ability to list deepwork version * Add ability to persist go binary for release step * Add github release step * Add info about installation in Readme * Use ldflags for app version instead of hardcoding it in main.go * Only run publish-github-release on master branch --- .circleci/config.yml | 67 ++++++++++++++++++++++++++++++++++++++++++++ Readme.md | 11 +++++++- main.go | 10 +++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..2167568 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,67 @@ +version: 2 + +workflows: + version: 2 + main: + jobs: + - build + - publish-github-release: + requires: + - build + filters: + branches: + only: + - master + +jobs: + + build: + docker: + - image: circleci/golang:1.10 + working_directory: /go/src/github.com/simontheleg/deepwork + environment: + TEST_RES_DIR: /tmp/test-results + ARTIFACTS_DIR: /tmp/artifacts + APP_VERSION: v0.1.1 + steps: + - checkout + - run: + name: Create required dirs + command: | + mkdir ${TEST_RES_DIR} + mkdir ${ARTIFACTS_DIR} + # This dependency is required to convert 'go test' results to junit ones for Circle CI to automatically recognize them + - run: + name: Fetch go-junit-report + command: go get github.com/jstemmer/go-junit-report + - run: + name: Resolve dependencies with go-get + command: go get -v -t -d ./... + - run: + name: Run go test + command: | + go test -v -cover ./... | tee ${TEST_RES_DIR}/go-test.out + go-junit-report <${TEST_RES_DIR}/go-test.out > ${TEST_RES_DIR}/go-test-report.xml + - store_test_results: + path: /tmp/test-results + - run: + name: Build app + command: | + env GOOS=darwin GOARCH=amd64 go build -o ${ARTIFACTS_DIR}/deepwork-darwin-64 -ldflags "-X main.version=${APP_VERSION}" + env GOOS=linux GOARCH=amd64 go build -o ${ARTIFACTS_DIR}/deepwork-linux-64 -ldflags "-X main.version=${APP_VERSION}" + - persist_to_workspace: + root: /tmp/artifacts + paths: + - ./* + + publish-github-release: + docker: + - image: simontheleg/github-go-releaser + steps: + - attach_workspace: + at: ./ + - run: + name: Publish Release on Github + command: | + VERSION=$(./deepwork-linux-64 version) + ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./ diff --git a/Readme.md b/Readme.md index 7843726..d2b7894 100644 --- a/Readme.md +++ b/Readme.md @@ -4,7 +4,16 @@ Inspired by the book [Deep Work](http://calnewport.com/books/deep-work/) from Ca Currently only working with Mac OS X, more variety to come soon. -## Set-Up +## Installation + +Simply grab the desired version from the Github Release page and place it in your $PATH, e.g. + +```shell +curl -L https://github.com/SimonTheLeg/deepwork/releases/download/v0.1.0/deepwork-darwin-64 -o /usr/local/bin/deepwork +``` + + +## Configuration create a config file under ~/.deepwork/config.json and add the names of all communication applications. An example config can be found in [example-config.json](example-config.json). By default Mail and Calendar will be added. diff --git a/main.go b/main.go index da28383..ddbaf3c 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,8 @@ import ( var configLocation string +var version = "dev-build" + type config struct { AffectedApps []string `json:"affectedApps"` } @@ -41,6 +43,10 @@ func main() { var action func(name string) error action = determineAction(desAction) + if action == nil { + os.Exit(0) + } + // Execute action for _, app := range config.AffectedApps { err := action(app) @@ -56,7 +62,11 @@ func determineAction(desAction string) func(name string) error { return CloseApp case "off": return OpenApp + case "version": + fmt.Println(version) + return nil default: + fmt.Println("Usage: deepwork [on,off,version]") return nil } }