Skip to content

Commit

Permalink
Added CICD
Browse files Browse the repository at this point in the history
  • Loading branch information
sdomozhylkin-everstake committed May 2, 2023
1 parent 4bd0ee5 commit 96704e1
Show file tree
Hide file tree
Showing 9 changed files with 382 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
versions_for_test="1.13.6 1.13.7"
74 changes: 74 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Source:
# https://github.com/solana-labs/solana-accountsdb-plugin-postgres/blob/master/.github/workflows/test.yml

on:
push:
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Set env vars
run: |
source ci/rust-version.sh
echo "RUST_STABLE=$rust_stable" | tee -a $GITHUB_ENV
- if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y \
gnupg \
libudev-dev \
libsasl2-dev \
libssl-dev \
libzstd-dev
sudo touch /etc/apt/sources.list.d/debian.list
echo 'deb http://ftp.debian.org/debian sid main' | sudo tee -a /etc/apt/sources.list.d/debian.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0E98404D386FA1D9
sudo apt-get update
sudo apt-get install -y protobuf-compiler
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_STABLE }}
override: true
profile: minimal
components: rustfmt, clippy

- uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: cargo-build-${{ hashFiles('**/Cargo.lock', 'rust-toolchain') }}-${{ env.RUST_STABLE }}

- name: cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

# - name: cargo clippy
# uses: actions-rs/cargo@v1
# with:
# command: clippy
# args: --workspace --all-targets -- --deny=warnings

- name: Build
run: ./ci/cargo-build-test.sh


- name: Install solana
run: |
curl -sSf https://raw.githubusercontent.com/solana-labs/solana/v1.13.5/install/solana-install-init.sh | sh -s - 1.13.7
export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH"
- name: Test geyser plugin
run: ./ci/test-geyser-plugin.sh
52 changes: 52 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
on:
push:
tags:
- 'v*'
pull_request:
paths:
- '.github/workflows/release.yml'

env:
CARGO_TERM_COLOR: always

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set env vars
run: |
source ci/rust-version.sh
echo "RUST_STABLE=$rust_stable" | tee -a $GITHUB_ENV
- if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libudev-dev libssl-dev libsasl2-dev libzstd-dev
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_STABLE }}
override: true
profile: minimal
components: rustfmt

- name: Check Solana version
run: |
echo "CI_TAG=${GITHUB_REF#refs/*/}" >> "$GITHUB_ENV"
echo "CI_OS_NAME=linux" >> "$GITHUB_ENV"
SOLANA_VERSION="$(./ci/solana-version.sh)"
SOLANA_VERSION="v${SOLANA_VERSION#=}"
echo "SOLANA_VERSION=$SOLANA_VERSION" >> "$GITHUB_ENV"
- name: Build release tarball
run: ./ci/create-tarball.sh

- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
body: |
libsolana_geyser_plugin_scaffold ${{ env.CI_TAG }}
solana ${{ env.SOLANA_VERSION }}
rust ${{ env.RUST_STABLE }}
files: |
libsolana_geyser_plugin_scaffold*
20 changes: 20 additions & 0 deletions ci/cargo-build-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# Source:
# https://github.com/solana-labs/solana-accountsdb-plugin-postgres/blob/master/ci/cargo-build-test.sh

set -e
cd "$(dirname "$0")/.."

source ./ci/rust-version.sh stable

export RUSTFLAGS="-D warnings"
export RUSTBACKTRACE=1

set -x

# Build/test all host crates
cargo +"$rust_stable" build --release
cargo +"$rust_stable" test -- --nocapture

exit 0
76 changes: 76 additions & 0 deletions ci/cargo-install-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash

set -e

usage() {
exitcode=0
if [[ -n "$1" ]]; then
exitcode=1
echo "Error: $*"
fi
cat <<EOF
usage: $0 [+<cargo version>] [--debug] <install directory>
EOF
exit $exitcode
}

case "$CI_OS_NAME" in
osx)
libExt=dylib
;;
linux)
libExt=so
;;
*)
echo CI_OS_NAME unsupported
exit 1
;;
esac

maybeRustVersion=
installDir=
buildVariant=release
maybeReleaseFlag=--release

while [[ -n $1 ]]; do
if [[ ${1:0:1} = - ]]; then
if [[ $1 = --debug ]]; then
maybeReleaseFlag=
buildVariant=debug
shift
else
usage "Unknown option: $1"
fi
elif [[ ${1:0:1} = \+ ]]; then
maybeRustVersion=$1
shift
else
installDir=$1
shift
fi
done

if [[ -z "$installDir" ]]; then
usage "Install directory not specified"
exit 1
fi

installDir="$(mkdir -p "$installDir"; cd "$installDir"; pwd)"

echo "Install location: $installDir ($buildVariant)"

cd "$(dirname "$0")"/..

SECONDS=0

mkdir -p "$installDir/lib"

(
set -x
# shellcheck disable=SC2086 # Don't want to double quote $rust_version
cargo $maybeRustVersion build $maybeReleaseFlag --lib
)

cp -fv "target/$buildVariant/libsolana_geyser_plugin_scaffold.$libExt" "$installDir"/lib/

echo "Done after $SECONDS seconds"
54 changes: 54 additions & 0 deletions ci/create-tarball.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Source:
#https://github.com/Blockdaemon/solana-accountsdb-plugin-kafka/blob/main/ci/create-tarball.sh

#!/usr/bin/env bash
set -e

cd "$(dirname "$0")/.."

case "$CI_OS_NAME" in
osx)
_cputype="$(uname -m)"
if [[ $_cputype = arm64 ]]; then
_cputype=aarch64
fi
TARGET=${_cputype}-apple-darwin
;;
linux)
TARGET=x86_64-unknown-linux-gnu
;;
*)
echo CI_OS_NAME unsupported
exit 1
;;
esac

RELEASE_BASENAME="${RELEASE_BASENAME:=libsolana_geyser_plugin_scaffold}"
TARBALL_BASENAME="${TARBALL_BASENAME:="$RELEASE_BASENAME"}"

echo --- Creating release tarball
(
set -x
rm -rf "${RELEASE_BASENAME:?}"/
mkdir "${RELEASE_BASENAME}"/

COMMIT="$(git rev-parse HEAD)"

(
echo "channel: $CI_TAG"
echo "commit: $COMMIT"
echo "target: $TARGET"
) > "${RELEASE_BASENAME}"/version.yml

# Make CHANNEL available to include in the software version information
export CHANNEL

source ci/rust-version.sh stable
ci/cargo-install-all.sh stable "${RELEASE_BASENAME}"

tar cvf "${TARBALL_BASENAME}"-$TARGET.tar "${RELEASE_BASENAME}"
bzip2 "${TARBALL_BASENAME}"-$TARGET.tar
cp "${RELEASE_BASENAME}"/version.yml "${TARBALL_BASENAME}"-$TARGET.yml
)

echo --- ok
69 changes: 69 additions & 0 deletions ci/rust-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash

# Source:
# https://github.com/solana-labs/solana-accountsdb-plugin-postgres/blob/master/ci/rust-version.sh

#
# This file maintains the rust versions for use by CI.
#
# Obtain the environment variables without any automatic toolchain updating:
# $ source ci/rust-version.sh
#
# Obtain the environment variables updating both stable and nightly, only stable, or
# only nightly:
# $ source ci/rust-version.sh all
# $ source ci/rust-version.sh stable
# $ source ci/rust-version.sh nightly

# Then to build with either stable or nightly:
# $ cargo +"$rust_stable" build
# $ cargo +"$rust_nightly" build
#

if [[ -n $RUST_STABLE_VERSION ]]; then
stable_version="$RUST_STABLE_VERSION"
else
stable_version=1.64.0
fi

if [[ -n $RUST_NIGHTLY_VERSION ]]; then
nightly_version="$RUST_NIGHTLY_VERSION"
else
nightly_version=2022-04-01
fi


export rust_stable="$stable_version"
export rust_stable_docker_image=solanalabs/rust:"$stable_version"

export rust_nightly=nightly-"$nightly_version"
export rust_nightly_docker_image=solanalabs/rust-nightly:"$nightly_version"

[[ -z $1 ]] || (
rustup_install() {
declare toolchain=$1
if ! cargo +"$toolchain" -V > /dev/null; then
echo "$0: Missing toolchain? Installing...: $toolchain" >&2
rustup install "$toolchain"
cargo +"$toolchain" -V
fi
}

set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
case $1 in
stable)
rustup_install "$rust_stable"
;;
nightly)
rustup_install "$rust_nightly"
;;
all)
rustup_install "$rust_stable"
rustup_install "$rust_nightly"
;;
*)
echo "$0: Note: ignoring unknown argument: $1" >&2
;;
esac
)
12 changes: 12 additions & 0 deletions ci/solana-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# Source:
#https://github.com/Blockdaemon/solana-accountsdb-plugin-kafka/blob/main/ci/solana-version.sh

# Prints the Solana version.

set -e

cd "$(dirname "$0")/.."

cargo read-manifest | jq -r '.dependencies[] | select(.name == "solana-geyser-plugin-interface") | .req'
24 changes: 24 additions & 0 deletions ci/test-geyser-plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -x
export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH"
source .env

for i in $versions_for_test
do
echo "Test on version $i"
solana-install init $i
timeout 10 solana-test-validator --geyser-plugin-config config/geyser-plugin-config.json &
sleep 5
RES=$(curl -s http://127.0.0.1:8899 -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "id": 1, "method": "getIdentity"}' | jq .result.identity)
if [[ -n $RES ]]
then
echo "PASSED $RES"
else
echo "NOT PASSED $RES"
exit 1
fi
sleep 7
done



0 comments on commit 96704e1

Please sign in to comment.