Skip to content

Commit

Permalink
Added CI config, added release script and config, updated version pri…
Browse files Browse the repository at this point in the history
…nting
  • Loading branch information
maoueh committed Feb 16, 2022
1 parent 4b6f143 commit 4f6db8d
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 15 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build and Test

on:
push:
branches:
- master
- develop
pull_request:
branches:
- "**"

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.17.x]
os: [ubuntu-latest, macos-latest]
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Check out code
uses: actions/checkout@v2

- name: Cache Go modules
uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run Tests
run: go test ./...

- name: Build
run: go build ./...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/sf-data
/sf.yaml
/sfeth
/dist
69 changes: 69 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
project_name: sf-ethereum

release:
github:
owner: streamingfast
name: sf-ethereum
name_template: '{{.Tag}}'
builds:
- goos:
- linux
- darwin
goarch:
- arm64
- amd64
targets:
- linux_amd64
- darwin_amd64
- darwin_arm64
main: ./cmd/sfeth
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
binary: sfeth
env:
- CGO_ENABLED=0
archives:
- name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
replacements:
amd64: x86_64
darwin: macOS
linux: linux
format: tar.gz
files:
- LICENSE
- README.md
snapshot:
name_template: '{{ .Tag }}-next'
checksum:
name_template: checksums.txt
changelog:
filters:
exclude:
- '^docs:'
- '^test:'
sort: asc
dist: dist
signs:
- cmd: keybase
args:
- sign
- --infile
- $artifact
- --binary
- --outfile
- $signature
- --detached
signature: ${artifact}.sig
artifacts: checksum
env_files:
github_token: ~/.config/goreleaser/github_token
brews:
- name: sf-ethereum
tap:
owner: streamingfast
name: homebrew-tap
commit_author:
name: goreleaserbot
email: goreleaser@streamingfast.io
homepage: "https://github.com/streamingfast/sf-ethereum"
description: "Firehose on Ethereum stack"
license: "Apache-2.0"
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ go install ./cmd/sfeth

**Note** You will need to have [grpcurl](https://github.com/fullstorydev/grpcurl) and a clone of both https://github.com/streamingfast/proto and https://github.com/streamingfast/proto-ethereum, we assume they are sibling of the folder you are currently in, adjust `-import-path ...` flags in the command above to where the files are located.

## Release

Use the `./bin/release.sh` Bash script to perform a new release. It will ask you questions
as well as driving all the required commands, performing the necessary operation automatically.
The Bash script runs in dry-mode by default, so you can check first that everything is all right.

Releases are performed using [goreleaser](https://goreleaser.com/).

## Contributing

**Issues and PR in this repo related strictly to the Ethereum on StreamingFast.**
Expand Down
117 changes: 117 additions & 0 deletions bin/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env bash

ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"

dry_run="true"
force="false"

main() {
pushd "$ROOT" &> /dev/null

while getopts "hnf" opt; do
case $opt in
h) usage && exit 0;;
n) dry_run="true";;
f) force="true";;
\?) usage_error "Invalid option: -$OPTARG";;
esac
done
shift $((OPTIND-1))

verify_github_token
verify_keybase

if [[ "$dry_run" == "true" && "$force" == "true" ]]; then
usage_error "Only one of -n (dry run) or -f (force) can be provided at a time"
fi

version="$1"; shift
if [[ "$version" == "" ]]; then
printf "What version do you want to release (current latest is `git describe --tags --abbrev=0`)? "
read version
fi

if [[ ! "$version" =~ ^v ]]; then
echo "Version $version is invalid, must start with a 'v'"
exit 1
fi

mode="Dry Run, use -f flag to switch to publishing mode"
if [[ "$force" == "true" ]]; then
mode="Publishing"
fi

echo "About to release version tagged $version ($mode)"
sleep 3

args="--rm-dist"
if [[ "$force" == "false" ]]; then
args="--skip-publish --skip-validate $args"
fi

set -e
git tag "$version"
set +e

goreleaser release $args
if [[ $? -gt 0 || "$force" == "false" ]]; then
git tag -d "$version"
fi
}

verify_github_token() {
if [[ ! -f "$HOME/.config/goreleaser/github_token" && "$GITHUB_TOKEN" = "" ]]; then
echo "No GitHub token could be found in enviornment variable GITHUB_TOKEN"
echo "nor at ~/.config/goreleaser/github_token."
echo ""
echo "You will need to create one on GitHub website and make it available through"
echo "one of the accept way mentionned above."
exit 1
fi
}

verify_keybase() {
if ! command keybase &> /dev/null; then
echo "Keybase is required to sign the release (the checksum of all the artifacts"
echo "to be precise)."
echo ""
echo "You will need to have it available ('brew install keybase' on Mac OS X) and"
echo "configure it, just setting your Git username and a password should be enough."
exit 1
fi
}

usage_error() {
message="$1"
exit_code="$2"

echo "ERROR: $message"
echo ""
usage
exit ${exit_code:-1}
}

usage() {
echo "usage: release.sh [-h] [-f] [-n] [<version>]"
echo ""
echo "Perform the necessary commands to perform a release of the project."
echo "The <version> is optional, if not provided, you'll be asked the question."
echo ""
echo "The release being performed against GitHub, you need a valid GitHub API token"
echo "with the necessary rights to upload release and push to repositories. It needs to"
echo "be provided in file ~/.config/goreleaser/github_token or through an environment"
echo "variable GITHUB_TOKEN."
echo ""
echo "Keybase is required to sign the release (the checksum of all the artifacts"
echo "to be precise)."
echo ""
echo "You will need to have it available ('brew install keybase' on Mac OS X) and"
echo "configure it, just setting your Git username and a password should be enough."
echo ""
echo "Options"
echo " -f Run in write mode publishing the release to GitHub"
echo " -n Run in dry-run mode skipping validation and publishing"
echo " -h Display help about this script"
}

main "$@"
19 changes: 9 additions & 10 deletions cmd/sfeth/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,21 @@ func Main(registerCommonFlags func(cmd *cobra.Command) error, registerCommonModu
derr.Check("dfuse", RootCmd.Execute())
}

func Version(version, commit, isDirty string) string {
shortCommit := commit
if len(shortCommit) >= 15 {
shortCommit = shortCommit[0:15]
func Version(version, commit, date string) string {
var labels []string
if len(commit) >= 7 {
labels = append(labels, fmt.Sprintf("Commit %s", commit[0:7]))
}

if len(shortCommit) == 0 {
shortCommit = "adhoc"
if date != "" {
labels = append(labels, fmt.Sprintf("Built %s", date))
}

out := version + "-" + shortCommit
if isDirty != "" {
out += "-dirty"
if len(labels) == 0 {
return version
}

return out
return fmt.Sprintf("%s (%s)", version, strings.Join(labels, ", "))
}

var startCmdExample = `sfeth start relayer merger --merger-grpc-serving-addr=localhost:12345 --relayer-merger-addr=localhost:12345`
Expand Down
12 changes: 7 additions & 5 deletions cmd/sfeth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@
package main

import (
"time"

"github.com/streamingfast/sf-ethereum/cmd/sfeth/cli"
)

// Commit sha1 value, injected via go build `ldflags` at build time
var Commit = ""
var commit = ""

// Version value, injected via go build `ldflags` at build time
var Version = "dev"
var version = "dev"

// IsDirty value, injected via go build `ldflags` at build time
var IsDirty = ""
// Date value, injected via go build `ldflags` at build time
var date = time.Now().Format(time.RFC3339)

func init() {
cli.RootCmd.Version = cli.Version(Commit, Version, IsDirty)
cli.RootCmd.Version = cli.Version(version, commit, date)
}

func main() {
Expand Down

0 comments on commit 4f6db8d

Please sign in to comment.