diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000000..a1fc15abb24 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,50 @@ +name: Release manager + +on: + push: + tags: + # Pattern that roughly matches Oasis Core's version tags. + # For more details on GitHub Actions' pattern match syntax, see: + # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#patterns-to-match-branches-and-tags. + - 'v[0-9]+.[0-9]+*' + +jobs: + + prepare-release: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v1 + - name: Set up Go 1.13 + uses: actions/setup-go@v1.1.2 + with: + go-version: "1.13.x" + - name: Install Oasis Core prerequisites + run: | + sudo apt-get update + sudo apt-get install gcc g++ protobuf-compiler make cmake libssl-dev libseccomp-dev + go get github.com/golang/protobuf/protoc-gen-go + sudo GOBIN=/usr/local/bin go install github.com/golang/protobuf/protoc-gen-go + - name: Install GoReleaser + run: | + cd $(mktemp --directory /tmp/goreleaser.XXXXX) + ${CURL_CMD} ${GORELEASER_URL_PREFIX}/v${GORELEASER_VERSION}/${GORELEASER_TARBALL} \ + --output ${GORELEASER_TARBALL} + ${CURL_CMD} ${GORELEASER_URL_PREFIX}/v${GORELEASER_VERSION}/goreleaser_checksums.txt \ + --output CHECKSUMS + sha256sum --check --ignore-missing CHECKSUMS + tar -xf ${GORELEASER_TARBALL} + sudo mv goreleaser /usr/local/bin + env: + GORELEASER_URL_PREFIX: https://github.com/oasislabs/goreleaser/releases/download/ + GORELEASER_VERSION: 0.123.3-oasis1 + GORELEASER_TARBALL: goreleaser_Linux_x86_64.tar.gz + CURL_CMD: curl --proto =https --tlsv1.2 -sSL + - name: Create release + run: | + make release + env: + # Pass automatically created GitHub App installation token to the action. + # For more info, see: + # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token. + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 3f0af79557c..732a9bee43c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ target/ *.o *.so **/generated +/dist/ # IDE. .idea/* diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 00000000000..1886b03fd37 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,41 @@ +# GoReleaser configuration file. +# +# For more info, browse to http://goreleaser.com. +# +# NOTE: The GoReleaser is not meant to be run directly, but rather through +# Make's release target. + +project_name: Oasis Core + +env: + # Require use of Go modules. + - GO111MODULE=on + +builds: + - env: + - CGO_ENABLED=1 + id: oasis-node + main: ./oasis-node/main.go + binary: oasis-node + dir: go/ + flags: + - -trimpath + ldflags: + - -X github.com/oasislabs/oasis-core/go/common/version.SoftwareVersion={{.Env.VERSION}} + goos: + - linux + goarch: + - amd64 + +archives: + - name_template: "{{.Binary}}_{{.Version}}_{{.Os}}_{{.Arch}}" + +checksum: + name_template: SHA256SUMS + algorithm: sha256 + +snapshot: + name_template: "{{.Version}}-dev" + +release: + name_template: "{{.ProjectName}} {{.Version}}" diff --git a/Makefile b/Makefile index 138c5fb9867..7e3db777631 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,9 @@ build-helpers-go: build-helpers: build-helpers-go +build-go-generate: + @$(MAKE) -C go generate + # Format code. fmt-targets := fmt-rust fmt-go @@ -93,6 +96,10 @@ clean-go: clean: $(clean-targets) +# Prepare release. +release: build-go-generate + @goreleaser $(GORELEASER_ARGS) + # Develop in a Docker container. docker-shell: @docker run -t -i --rm \ @@ -107,8 +114,9 @@ docker-shell: # List of targets that are not actual files. .PHONY: \ $(build-targets) go build \ + build-helpers-go build-helpers build-go-generate \ $(fmt-targets) fmt \ $(test-unit-targets) $(test-targets) test \ $(clean-targets) clean \ - docker-shell \ + release docker-shell \ all diff --git a/common.mk b/common.mk index a2cfa179908..6682433abb9 100644 --- a/common.mk +++ b/common.mk @@ -21,9 +21,16 @@ else ECHO := echo endif -# Try to determine Oasis Core's git revision and if the working directory is -# dirty. -VERSION_BUILD = $(shell git describe --always --match "" --dirty=+ 2>/dev/null) +# Try to determine Oasis Core's version from git. +LATEST_TAG := $(shell git describe --tags --match 'v*' --abbrev=0 2>/dev/null) +VERSION := $(subst v,,$(LATEST_TAG)) +IS_TAG := $(shell git describe --tags --match 'v*' --exact-match 2>/dev/null && echo YES || echo NO) +ifeq ($(and $(LATEST_TAG),$(IS_TAG)),NO) + # The current commit is not exactly a tag, append commit and dirty info to + # the version. + VERSION := $(VERSION)-git$(shell git describe --always --match '' --dirty=+dirty 2>/dev/null) +endif +export VERSION # Go binary to use for all Go commands. OASIS_GO ?= go @@ -36,8 +43,8 @@ GO := env -u GOPATH $(OASIS_GO) GOFLAGS ?= -trimpath -v # Add Oasis Core's version as a linker string value definition. -ifneq ($(VERSION_BUILD),) - GOLDFLAGS += "-X github.com/oasislabs/oasis-core/go/common/version.Build=+$(VERSION_BUILD)" +ifneq ($(VERSION),) + export GOLDFLAGS += "-X github.com/oasislabs/oasis-core/go/common/version.SoftwareVersion=$(VERSION)" endif # Go build command to use by default. @@ -45,3 +52,14 @@ GO_BUILD_CMD := env -u GOPATH $(OASIS_GO) build $(GOFLAGS) # Path to the Urkel interoperability test helpers binary in go/. GO_TEST_HELPER_URKEL_PATH := storage/mkvs/urkel/interop/urkel-test-helpers + +# Instruct GoReleaser to create a "snapshot" release by default. +GORELEASER_ARGS ?= release --snapshot --rm-dist +ifeq ($(GITHUB_ACTIONS), true) + # Running inside GitHub Actions, create a real release. + # TODO: Prepare Release notes from the automatically generated changelog + # after https://github.com/oasislabs/oasis-core/issues/759 is implemented. + RELEASE_NOTES := $(shell mktemp /tmp/oasis-core.XXXXX) + _ := $(shell echo "We're are pleased to present you Oasis Core $(VERSION)!" > $(RELEASE_NOTES)) + GORELEASER_ARGS = release --release-notes $(RELEASE_NOTES) +endif diff --git a/go/Makefile b/go/Makefile index 0f4fadcfe03..e4037f8e034 100644 --- a/go/Makefile +++ b/go/Makefile @@ -32,7 +32,7 @@ build: $(go-binaries) # Urkel interoperability test helpers. urkel: generate @$(ECHO) "$(MAGENTA)*** Building test helpers for $@...$(OFF)" - @$(GO) build $(GOFLAGS) -o ./$(GO_TEST_HELPER_URKEL_PATH) ./$(shell dirname $(GO_TEST_HELPER_URKEL_PATH)) + @$(GO) build $(GOFLAGS) $(GO_EXTRA_FLAGS) -o ./$(GO_TEST_HELPER_URKEL_PATH) ./$(shell dirname $(GO_TEST_HELPER_URKEL_PATH)) build-helpers: $(test-helpers) diff --git a/go/common/version/version.go b/go/common/version/version.go index 9121384d489..5dcd34a035a 100644 --- a/go/common/version/version.go +++ b/go/common/version/version.go @@ -50,8 +50,9 @@ func (v Version) MajorMinor() Version { } var ( - // Build stores current git HEAD and is set by the linker. - Build = "" + // SoftwareVersion represents the Oasis Core's version and should be set + // by the linker. + SoftwareVersion = "0.0-unset" // RuntimeProtocol versions the protocol between the Oasis node(s) and // the runtime. diff --git a/go/oasis-node/cmd/root.go b/go/oasis-node/cmd/root.go index 189905327af..b1db4cdbbd1 100644 --- a/go/oasis-node/cmd/root.go +++ b/go/oasis-node/cmd/root.go @@ -26,7 +26,7 @@ var ( rootCmd = &cobra.Command{ Use: "oasis-node", Short: "Oasis Node", - Version: "0.2.0-alpha" + version.Build, + Version: version.SoftwareVersion, Run: node.Run, } ) diff --git a/go/storage/mkvs/urkel/interop/cmd/root.go b/go/storage/mkvs/urkel/interop/cmd/root.go index de3fd679766..de9ed87a437 100644 --- a/go/storage/mkvs/urkel/interop/cmd/root.go +++ b/go/storage/mkvs/urkel/interop/cmd/root.go @@ -3,13 +3,15 @@ package cmd import ( "github.com/spf13/cobra" + + "github.com/oasislabs/oasis-core/go/common/version" ) var ( rootCmd = &cobra.Command{ Use: "urkel-test-helpers", Short: "Urkel interoperability test helpers", - Version: "0.2.0-alpha", + Version: version.SoftwareVersion, } )