Skip to content

Commit

Permalink
Merge pull request #2486 from oasislabs/tjanez/add-goreleaser
Browse files Browse the repository at this point in the history
Automate build and release process for Oasis Core
  • Loading branch information
tjanez committed Dec 18, 2019
2 parents 48d05ce + 6bd9d7e commit b39faf7
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 11 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ target/
*.o
*.so
**/generated
/dist/

# IDE.
.idea/*
Expand Down
41 changes: 41 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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}}"
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 \
Expand All @@ -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
28 changes: 23 additions & 5 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,12 +43,23 @@ 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.
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
2 changes: 1 addition & 1 deletion go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions go/common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion go/oasis-node/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
)
Expand Down
4 changes: 3 additions & 1 deletion go/storage/mkvs/urkel/interop/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
)

Expand Down

0 comments on commit b39faf7

Please sign in to comment.