Skip to content

Commit

Permalink
Added ci build scripts
Browse files Browse the repository at this point in the history
Added basic github actions build scripts.
  • Loading branch information
linuskendall authored and ckamm committed May 14, 2022
1 parent c2f0c0a commit c18632c
Show file tree
Hide file tree
Showing 8 changed files with 421 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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 rust version
run: |
source ci/rust-version.sh
echo "RUST_STABLE=$rust_stable" | tee -a $GITHUB_ENV
- name: Set env vars
run: |
source ci/env.sh
echo "GEYSER_PLUGIN_NAME=$plugin_name" | tee -a $GITHUB_ENV
echo "GEYSER_PLUGIN_LIB=lib${plugin_lib_name}" | 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: |
${{ env.GEYSER_PLUGIN_NAME }} ${{ env.CI_TAG }}
solana ${{ env.SOLANA_VERSION }}
rust ${{ env.RUST_STABLE }}
files: |
${{ env.GEYSER_PLUGIN_NAME }}-release-*
60 changes: 60 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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-latest
steps:
- uses: actions/checkout@v2

- name: Set rust version
run: |
source ci/rust-version.sh
echo "RUST_STABLE=$rust_stable" | tee -a $GITHUB_ENV
- name: Set env vars
run: |
source ci/env.sh
echo "GEYSER_PLUGIN_NAME=$plugin_name" | tee -a $GITHUB_ENV
echo "GEYSER_PLUGIN_LIB=lib${plugin_lib_name}" | 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, clippy

- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
key: cargo-build-${{ hashFiles('**/Cargo.lock') }}-${{ 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
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
cargo +"$rust_stable" test -- --nocapture

exit 0
78 changes: 78 additions & 0 deletions ci/cargo-install-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/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/${GEYSER_PLUGIN_LIB}.$libExt" "$installDir"/lib/

echo "Done after $SECONDS seconds"

51 changes: 51 additions & 0 deletions ci/create-tarball.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/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:="${GEYSER_PLUGIN_NAME}-release"}"
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
3 changes: 3 additions & 0 deletions ci/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
plugin_name=solana-geyser-sqs-grpc-release
plugin_lib_name=solana_geyser_connector_plugin_grpc
Loading

0 comments on commit c18632c

Please sign in to comment.