Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile improvements #498

Merged
merged 3 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 31 additions & 36 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
- [Issues](#issues)
- [Reporting an Issue](#reporting-an-issue)
- [Issue Lifecycle](#issue-lifecycle)
- [Setting up Go to work on doctl](#setting-up-go-to-work-on-doctl)
- [Contributing code](#contributing-code)
- [dependencies](#dependencies)
- [`godo` mocks](#godo-mocks)
- [Releasing `doctl`](#releasing-doctl)
- [Setup](#setup)
- [Cutting a release](#cutting-a-release)
- [Updating Homebrew](#updating-homebrew)
- [Developing](#developing)
- [Go environment](#go-environment)
- [Docker](#docker)
- [Testing](#testing)
- [`godo` mocks](#godo-mocks)
- [Releasing](#releasing)
- [Setup](#setup)
- [Cutting a release](#cutting-a-release)
- [Updating Homebrew](#updating-homebrew)

<!-- markdown-toc end -->

Expand Down Expand Up @@ -59,45 +60,39 @@ lets us merge or address your contributions quickly.
the issue tracker clean. The issue is still indexed and available for
future viewers, or can be re-opened if necessary.

## Setting up Go to work on doctl
## Developing

If you have never worked with Go before, you will have to complete the
following steps in order to be able to compile and test doctl.
`doctl` has `make` targets for most tooling in the `Makefile`. Run `make`
or `make list` for a list of available targets.

1. Install Go. Make sure the Go version is at least Go 1.11.
On Mac OS X, you can `brew install go` to install the latest stable version.
### Go environment

1. Set and export the `GOPATH` environment variable and update your `PATH`.
For example, you can add to your `.bash_profile`.
The minimal version of Golang for `doctl` is 1.11. `doctl` uses [Go
modules](https://github.com/golang/go/wiki/Modules) for dependency
management [with vendoring](https://github.com/golang/go/wiki/Modules#how-do-i-use-vendoring-with-modules-is-vendoring-going-away).
Please run `make vendor` after any dependency modifications.

```
export GOPATH=$HOME/Documents/golang
export PATH=$PATH:$GOPATH/bin
```
Be sure to run `go fmt` on your code before submitting a pull request.

1. Make your changes to the doctl source, being sure to run the basic
tests.
### Docker

1. If everything works well and the tests pass, run `go fmt` on your code
before submitting a pull request.
You can create a local Docker container via `make docker_build`.

## Contributing code
### Testing

### dependencies
Run the tests locally via `make test`, or on Travis CI by opening a PR.

This project uses [Go
modules](https://github.com/golang/go/wiki/Modules) for dependency
management and employs vendoring. Please run `make vendor` after any
dependency modifications.
#### `godo` mocks

### `godo` mocks
When you upgrade `godo` you have to re-generate the mocks.

When you upgrade `godo` you have to re-generate the mocks using [mockery](https://github.com/vektra/mockery).
Install mockery in your `GOPATH` then run the `scripts/regenmocks.sh` script to produce them.
```
make mocks
```

### Releasing `doctl`
## Releasing

#### Setup
### Setup

To release `doctl`, you need to install:

Expand All @@ -108,7 +103,7 @@ And make it available in your `PATH`. You can use `go get -u` and add your

You will also need a valid `GITHUB_TOKEN` environment variable with access to the `digitalocean/doctl` repo. You can generate a token [here](https://github.com/settings/tokens), it needs the `public_repo` access.

#### Cutting a release
### Cutting a release

1. Run `make changelog` and add the results to the [CHANGELOG](https://github.com/digitalocean/doctl/blob/master/CHANGELOG.md)
under the version you're going to release if they aren't already there.
Expand All @@ -131,7 +126,7 @@ in `builds/major.minor.patch/release`.
1. Go to [releases](https://github.com/digitalocean/doctl/releases) and update the release
description to contain all changelog entries for this specific release. Uncheck the pre-release checkbox.

#### Updating Homebrew
### Updating Homebrew

Using the url and sha from the github release, update the
[homebrew formula](https://github.com/Homebrew/homebrew-core/blob/master/Formula/doctl.rb).
Expand Down
63 changes: 29 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
# need to set go version to at least 1.11

export CGO=0
export CGO = 0

export GO111MODULE := on

list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null |\
awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' |\
sort |\
egrep -v -e '^[^[:alnum:]]' -e '^$@$$'

.PHONY: test
test:
go test ./cmd/... ./commands/... ./do/... ./install/... ./pkg/... ./pluginhost/... .

.PHONY: clean
clean:
@rm -rf builds

.PHONY: vendor
vendor:
go mod vendor
go mod tidy

.PHONY: changelog
changelog:
scripts/changelog.sh

.PHONY: mocks
mocks:
scripts/regenmocks.sh

# These builds are for convenience. This logic isn't used in the build-release process
my_d=$(shell pwd)
my_d = $(shell pwd)
OUT_D = $(shell echo $${OUT_D:-$(my_d)/builds})

UNAME_S := $(shell uname -s)
Expand Down Expand Up @@ -37,21 +64,6 @@ native: _build
# end convenience builds

# docker targets for developing in docker
.PHONY: build_mac
build_mac: GOOS = darwin
build_mac: GOARCH = 386
build_mac: _build

.PHONY: build_linux_386
build_linux_386: GOOS = linux
build_linux_386: GOARCH = 386
build_linux_386: _build

.PHONY: build_linux_amd64
build_linux_amd64: GOOS = linux
build_linux_amd64: GOARCH = amd64
build_linux_amd64: _build

.PHONY: _base_docker_cntr
_base_docker_cntr:
docker build -f Dockerfile.build . -t doctl_builder
Expand All @@ -71,20 +83,3 @@ docker_build: _base_docker_cntr
@echo "Built binaries to $(OUT_D)"
@echo "Created a local Docker container. To use, run: docker run --rm -it doctl_local"
# end docker targets

.PHONY: clean
clean:
@rm -rf builds

.PHONY: test
test:
go test ./cmd/... ./commands/... ./do/... ./install/... ./pkg/... ./pluginhost/... .

.PHONY: vendor
vendor:
go mod vendor
go mod tidy

.PHONY: changelog
changelog:
scripts/changelog.sh