Skip to content

Commit

Permalink
Add ci and cd (github release) (#3)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SimonTheLeg committed Aug 18, 2018
1 parent 94f8ff6 commit 249924c
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
67 changes: 67 additions & 0 deletions .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} ./
11 changes: 10 additions & 1 deletion Readme.md
Expand Up @@ -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.

Expand Down
10 changes: 10 additions & 0 deletions main.go
Expand Up @@ -14,6 +14,8 @@ import (

var configLocation string

var version = "dev-build"

type config struct {
AffectedApps []string `json:"affectedApps"`
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
}
Expand Down

0 comments on commit 249924c

Please sign in to comment.