Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions .github/workflows/build-test-release.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# https://goreleaser.com/ci/actions/
# TODO: replace other build github actions
name: Build + test (and release)
name: Build + test

on:
push:
pull_request:

# only create github release on git tag
permissions:
contents: write
contents: read

jobs:
build_test_release:
Expand All @@ -24,19 +21,18 @@ jobs:
go-version: 1.17
- name: Run unit tests
shell: bash
run: scripts/tests.sh
run: scripts/tests.unit.sh
- name: Run integration tests
shell: bash
run: scripts/integration.sh
- name: Run GoReleaser
run: scripts/tests.integration.sh
- name: Run e2e tests
shell: bash
run: scripts/tests.e2e.sh 1.7.3
- name: Run GoReleaser for cross-platform builds
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
# automate github release page announce and artifact uploads
# TODO: automate github release page announce and artifact uploads?
# https://goreleaser.com/cmd/goreleaser_release/
# add "--skip-announce --skip-publish" to disable github release
args: release --rm-dist
env:
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
args: release --rm-dist --skip-announce --skip-publish
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
go-version: 1.17
- name: Run static analysis tests
shell: bash
run: scripts/lint.sh
run: scripts/tests.lint.sh
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ vendor
.quark-cli-pk
genesis.json
*.test

dist/
4 changes: 1 addition & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ builds:
goarch: 386

release:
# Repo in which the release will be created.
# Default is extracted from the origin remote URL or empty if its private hosted.
github:
owner: gyuho
owner: ava-labs
name: quarkvm
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module github.com/ava-labs/quarkvm

go 1.17

// to add dependency (not needed for test build)
// go get -v github.com/onsi/ginkgo/[email protected]

require (
github.com/ava-labs/avalanchego v1.7.2
github.com/fatih/color v1.9.0
Expand All @@ -12,6 +15,7 @@ require (
github.com/onsi/ginkgo/v2 v2.0.0-rc2
github.com/onsi/gomega v1.17.0
github.com/spf13/cobra v1.2.1
sigs.k8s.io/yaml v1.3.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -886,3 +886,5 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
20 changes: 20 additions & 0 deletions scripts/build.release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

if ! [[ "$0" =~ scripts/build.release.sh ]]; then
echo "must be run from repository root"
exit 255
fi

# https://goreleaser.com/install/
go install -v github.com/goreleaser/goreleaser@latest

# e.g.,
# git tag 1.0.0
goreleaser release \
--config .goreleaser.yml \
--skip-announce \
--skip-publish
16 changes: 0 additions & 16 deletions scripts/e2e.build.sh

This file was deleted.

16 changes: 0 additions & 16 deletions scripts/integration.build.sh

This file was deleted.

31 changes: 0 additions & 31 deletions scripts/integration.sh

This file was deleted.

93 changes: 93 additions & 0 deletions scripts/tests.e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env bash
set -e

# e.g.,
# ./scripts/tests.e2e.sh 1.7.3
if ! [[ "$0" =~ scripts/tests.e2e.sh ]]; then
echo "must be run from repository root"
exit 255
fi

VERSION=$1
if [[ -z "${VERSION}" ]]; then
echo "Missing version argument!"
echo "Usage: ${0} [VERSION]" >> /dev/stderr
exit 255
fi

# download avalanchego
# https://github.com/ava-labs/avalanchego/releases
GOARCH=$(go env GOARCH)
GOOS=$(go env GOOS)
DOWNLOAD_URL=https://github.com/ava-labs/avalanchego/releases/download/v${VERSION}/avalanchego-linux-${GOARCH}-v${VERSION}.tar.gz
DOWNLOAD_PATH=/tmp/avalanchego.tar.gz
if [[ ${GOOS} == "darwin" ]]; then
DOWNLOAD_URL=https://github.com/ava-labs/avalanchego/releases/download/v${VERSION}/avalanchego-macos-v${VERSION}.zip
DOWNLOAD_PATH=/tmp/avalanchego.zip
fi

rm -rf /tmp/avalanchego-v${VERSION}
rm -rf /tmp/avalanchego-build
rm -f ${DOWNLOAD_PATH}

echo "downloading avalanchego ${VERSION} at ${DOWNLOAD_URL}"
curl -L ${DOWNLOAD_URL} -o ${DOWNLOAD_PATH}

echo "extracting downloaded avalanchego"
if [[ ${GOOS} == "linux" ]]; then
tar xzvf ${DOWNLOAD_PATH} -C /tmp
elif [[ ${GOOS} == "darwin" ]]; then
unzip ${DOWNLOAD_PATH} -d /tmp/avalanchego-build
mv /tmp/avalanchego-build/build /tmp/avalanchego-v${VERSION}
fi
find /tmp/avalanchego-v${VERSION}

echo "building quarkvm"
go build \
-o /tmp/avalanchego-v${VERSION}/plugins/tGas3T58KzdjLHhBDMnH2TvrddhqTji5iZAMZ3RXs2NLpSnhH \
./cmd/quarkvm
find /tmp/avalanchego-v${VERSION}

echo "building quark-cli"
go build -v -o /tmp/quark-cli ./cmd/quarkcli

echo "creating VM genesis file"
rm -f /tmp/quarkvm.genesis
/tmp/quark-cli genesis --genesis-file /tmp/quarkvm.genesis

echo "building runner"
pushd ./tests/runner
go build -v -o /tmp/runner .
popd

echo "building e2e.test"
# to install the ginkgo binary (required for test build and run)
go install -v github.com/onsi/ginkgo/v2/[email protected]
ACK_GINKGO_RC=true ginkgo build ./tests/e2e
./tests/e2e/e2e.test --help

echo "launch local test cluster in the background"
/tmp/runner \
--avalanchego-path=/tmp/avalanchego-v${VERSION}/avalanchego \
--vm-id=tGas3T58KzdjLHhBDMnH2TvrddhqTji5iZAMZ3RXs2NLpSnhH \
--vm-genesis-path=/tmp/quarkvm.genesis \
--output-path=/tmp/avalanchego-v${VERSION}/output.yaml 2> /dev/null &
PID=${!}

sleep 60
echo "wait until local cluster is ready from PID ${PID}"
while [[ ! -s /tmp/avalanchego-v${VERSION}/output.yaml ]]
do
echo "waiting for /tmp/avalanchego-v${VERSION}/output.yaml creation"
sleep 3
done
echo "found it!"
cat /tmp/avalanchego-v${VERSION}/output.yaml

echo "running e2e tests against the local cluster with --shutdown"
./tests/e2e/e2e.test \
--ginkgo.v \
--cluster-info-path /tmp/avalanchego-v${VERSION}/output.yaml \
--shutdown

echo "ALL SUCCESS!"
22 changes: 22 additions & 0 deletions scripts/tests.integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -e

if ! [[ "$0" =~ scripts/tests.integration.sh ]]; then
echo "must be run from repository root"
exit 255
fi

# to install the ginkgo binary (required for test build and run)
go install -v github.com/onsi/ginkgo/v2/[email protected]

# run with 3 embedded VMs
ACK_GINKGO_RC=true ginkgo \
run \
-v \
./tests/integration \
-- \
--vms 3 \
--min-difficulty 1 \
--min-block-cost 0

echo "ALL SUCCESS!"
3 changes: 2 additions & 1 deletion scripts/lint.sh → scripts/tests.lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o errexit
set -o pipefail
set -e

if ! [[ "$0" =~ scripts/lint.sh ]]; then
if ! [[ "$0" =~ scripts/tests.lint.sh ]]; then
echo "must be run from repository root"
exit 255
fi
Expand All @@ -23,6 +23,7 @@ fi
# TESTS='license_header' ./scripts/lint.sh
TESTS=${TESTS:-"golangci_lint license_header"}

# https://github.com/golangci/golangci-lint/releases
function test_golangci_lint {
go install -v github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint run --config .golangci.yml
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests.sh → scripts/tests.unit.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e

if ! [[ "$0" =~ scripts/tests.sh ]]; then
if ! [[ "$0" =~ scripts/tests.unit.sh ]]; then
echo "must be run from repository root"
exit 255
fi
Expand Down
43 changes: 43 additions & 0 deletions tests/cluster_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

// Package tests defines common test primitives.
package tests

import (
"io/ioutil"

"sigs.k8s.io/yaml"
)

// ClusterInfo represents the local cluster information.
type ClusterInfo struct {
URIs []string `json:"uris"`
Endpoint string `json:"endpoint"`
PID int `json:"pid"`
LogsDir string `json:"logsDir"`
}

const fsModeWrite = 0o600

func (ci ClusterInfo) Save(p string) error {
ob, err := yaml.Marshal(ci)
if err != nil {
return err
}
return ioutil.WriteFile(p, ob, fsModeWrite)
}

// LoadClusterInfo loads the cluster info YAML file
// to parse it into "ClusterInfo".
func LoadClusterInfo(p string) (ClusterInfo, error) {
ob, err := ioutil.ReadFile(p)
if err != nil {
return ClusterInfo{}, err
}
info := new(ClusterInfo)
if err = yaml.Unmarshal(ob, info); err != nil {
return ClusterInfo{}, err
}
return *info, nil
}
Loading