Skip to content

fix: improve write_program logic; add tests (#579) #444

fix: improve write_program logic; add tests (#579)

fix: improve write_program logic; add tests (#579) #444

Workflow file for this run

name: Build Binaries
on:
push:
branches:
- main
- ci
- supervised
- feat/surfpool-studio
workflow_dispatch:
env:
AWS_REGION: us-east-1
S3_BUCKET: txtx-public
concurrency:
group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
get_release_info:
name: Get Release Info
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.new_release_tag.outputs.TAG }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get latest release
if: startsWith(github.ref, 'refs/heads/main')
id: release
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: ${{ github.repository }}
excludes: prerelease, draft
- name: Determine if release build
if: startsWith(github.ref, 'refs/heads/main')
id: new_release_tag
env:
LATEST_RELEASE: ${{ steps.release.outputs.release }}
run: |
CARGO_VERSION=v$(grep "version" Cargo.toml | head -n 1 | cut -d\" -f2)
if [[ "${CARGO_VERSION}" != "${LATEST_RELEASE}" ]]; then
echo "::set-output name=TAG::${CARGO_VERSION}"
echo "::warning::Will create release for version: ${CARGO_VERSION}"
else
echo "::warning::Will not create a release"
fi
dist_surfpool:
name: Build Surfpool Distributions
runs-on: ${{ matrix.os }}
outputs:
LINUX_X64_SHA: ${{ steps.linux_x64_sha.outputs.LINUX_X64_SHA }}
MACOS_X64_SHA: ${{ steps.macos_x64_sha.outputs.MACOS_X64_SHA }}
MACOS_ARM64_SHA: ${{ steps.macos_arm64_sha.outputs.MACOS_ARM64_SHA }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
platform: linux
target: x86_64-unknown-linux-gnu
architecture: x64
- os: windows-latest
platform: windows
target: x86_64-pc-windows-msvc
architecture: x64
- os: macos-latest
platform: darwin
target: x86_64-apple-darwin
architecture: x64
- os: macos-latest
platform: darwin
target: aarch64-apple-darwin
architecture: arm64
steps:
# pre-build for windows
- name: Configure git to use LF (Windows)
if: matrix.os == 'windows-latest'
run: |
git config --global core.autocrlf false
git config --global core.eol lf
# pre-build for all OS
- name: Checkout repository
uses: actions/checkout@v4
# set up rust for all envs
- name: Install Rust toolchain
run: rustup toolchain install 1.86.0 --profile minimal --target ${{ matrix.target }}
- name: Install Rust Target
run: rustup target add ${{ matrix.target }}
# env vars unix
- name: Get Rust version (unix)
if: matrix.os != 'windows-latest'
run: echo "RUST_VERSION_HASH=$(rustc --version | shasum -a 256 | awk '{print $1}')" >> $GITHUB_ENV
# env vars windows
- name: "Get Rust version (windows)"
if: matrix.os == 'windows-latest'
shell: bash
run: echo "RUST_VERSION_HASH=$(rustc --version | sha256sum | awk '{print $1}')" >> $GITHUB_ENV
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/
./target/${{ matrix.target }}/release/
key: ${{ runner.os }}-rust-${{ env.RUST_VERSION_HASH }}-cargo-${{ hashFiles('./Cargo.lock') }}
# Set environment variables required from cross compiling from macos-x86_64 to macos-arm64
- name: Configure macos-arm64 cross compile config
if: matrix.target == 'aarch64-apple-darwin'
run: |
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
- name: Configure openssl (macos x64)
if: matrix.os == 'macos-latest' && matrix.architecture == 'x64'
run: |
brew install openssl@1.1
echo "OPENSSL_DIR=$(brew --prefix openssl@1.1)" >> $GITHUB_ENV
echo "OPENSSL_INCLUDE_DIR=$(brew --prefix openssl@1.1)/include" >> $GITHUB_ENV
echo "OPENSSL_LIB_DIR=$(brew --prefix openssl@1.1)/lib" >> $GITHUB_ENV
- name: Configure openssl (macos arm64)
if: matrix.os == 'macos-latest' && matrix.architecture == 'arm64'
run: |
brew install openssl@1.1
echo "OPENSSL_DIR=$(brew --prefix openssl@1.1)" >> $GITHUB_ENV
echo "OPENSSL_INCLUDE_DIR=$(brew --prefix openssl@1.1)/include" >> $GITHUB_ENV
echo "OPENSSL_LIB_DIR=$(brew --prefix openssl@1.1)/lib" >> $GITHUB_ENV
- name: Install LLVM (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install llvm
echo "LIBCLANG_PATH=$(brew --prefix llvm)/lib" >> $GITHUB_ENV
echo "BINDGEN_EXTRA_CLANG_ARGS=-I$(xcrun --show-sdk-path)/usr/include" >> $GITHUB_ENV
echo "LLVM_CONFIG_PATH=$(brew --prefix llvm)/bin/llvm-config" >> $GITHUB_ENV
- name: Install LLVM/Clang (Linux)
if: matrix.os == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y clang llvm-dev libclang-dev pkg-config
echo "LIBCLANG_PATH=/usr/lib/llvm-14/lib" >> $GITHUB_ENV
# - name: Download OpenSSL (windows)
# if: matrix.os == 'windows-latest'
# run: |
# Invoke-WebRequest -Uri https://slproweb.com/download/Win64OpenSSL-3_0_16.exe -OutFile openssl-installer.exe
# Start-Process -Wait -FilePath .\openssl-installer.exe -ArgumentList "/silent", "/verysilent", "/dir=C:\OpenSSL"
# - name: Set Env Vars for OpenSSL (windows)
# if: matrix.os == 'windows-latest'
# run: |
# echo "OPENSSL_DIR=C:\OpenSSL" >> $env:GITHUB_ENV
# echo "OPENSSL_LIB_DIR=C:\OpenSSL\lib\VC" >> $env:GITHUB_ENV
# echo "OPENSSL_NO_VENDOR=1" >> $env:GITHUB_ENV
- name: Cache vcpkg (windows)
if: matrix.os == 'windows-latest'
uses: actions/cache@v3
with:
path: |
C:\vcpkg
key: ${{ runner.os }}-vcpkg-openssl
- name: Setup vcpkg and install OpenSSL (windows)
if: matrix.os == 'windows-latest'
run: |
git clone https://github.com/microsoft/vcpkg C:\vcpkg
cd C:\vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg install openssl:x64-windows
echo "OPENSSL_DIR=C:\vcpkg\installed\x64-windows" >> $env:GITHUB_ENV
echo "OPENSSL_NO_VENDOR=1" >> $env:GITHUB_ENV
- name: Configure artifact names
shell: bash
run: |
echo "SHORT_TARGET_NAME=${{ matrix.platform }}-${{ matrix.architecture }}" >> $GITHUB_ENV
echo "PRE_GYP_TARGET_NAME=${{ matrix.platform }}-${{ matrix.architecture }}-unknown" >> $GITHUB_ENV
- name: Install dependencies
if: matrix.os == 'ubuntu-22.04'
run: sudo apt-get update && sudo apt-get install -y libudev-dev
- name: Build - Cargo (Windows)
if: matrix.os == 'windows-latest'
run: cargo build --release --locked --target ${{ matrix.target }} --features supervisor_ui --features version_check --features subgraph
- name: Build - Cargo (macOS x64)
if: matrix.os == 'macos-latest' && matrix.architecture == 'x64'
run: cargo build --release --locked --target ${{ matrix.target }} --features supervisor_ui --features version_check --features subgraph
- name: Build - Cargo (macOS ARM64)
if: matrix.os == 'macos-latest' && matrix.architecture == 'arm64'
run: cargo build --release --locked --target ${{ matrix.target }} --features supervisor_ui --features version_check --features subgraph
- name: Build - Cargo (Linux)
if: matrix.os == 'ubuntu-22.04'
run: cargo build --release --locked --target ${{ matrix.target }} --features supervisor_ui --features version_check --features subgraph # --features geyser_plugin # Disabled: version conflicts with litesvm 0.9.1 (requires solana-instruction =3.0.0 vs ~3.1)
# Don't compress for Windows because winget can't yet unzip files
- name: Compress cargo artifact (not windows)
if: matrix.os != 'windows-latest'
run: tar -C target/${{ matrix.target }}/release -zcvf surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz surfpool
- name: Compress artifact (Windows)
if: matrix.os == 'windows-latest'
shell: bash
run: tar -czf surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz -C target/${{ matrix.target }}/release surfpool.exe
- name: Store SHA256 Hash of Tar (Linux x64)
if: matrix.platform == 'linux'
id: linux_x64_sha
run: |
echo "LINUX_X64_SHA=$(sha256sum surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz | awk '{ print $1 }')" >> "$GITHUB_OUTPUT"
- name: Store SHA256 Hash of Tar (Mac x64)
if: matrix.os == 'macos-latest' && matrix.architecture == 'x64'
id: macos_x64_sha
run: |
echo "MACOS_X64_SHA=$(shasum -a 256 surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz | awk '{ print $1 }')" >> "$GITHUB_OUTPUT"
- name: Store SHA256 Hash of Tar (Mac arm64)
if: matrix.os == 'macos-latest' && matrix.architecture == 'arm64'
id: macos_arm64_sha
run: |
echo "MACOS_ARM64_SHA=$(shasum -a 256 surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz | awk '{ print $1 }')" >> "$GITHUB_OUTPUT"
# Separate uploads to prevent paths from being preserved
- name: Upload cargo artifacts (not windows)
if: matrix.os != 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: surfpool-${{ env.SHORT_TARGET_NAME }}
path: surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz
- name: Upload tar archive (Windows)
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: surfpool-${{ env.SHORT_TARGET_NAME }}
path: surfpool-${{ env.SHORT_TARGET_NAME }}.tar.gz
build-image-amd64:
name: Build Docker Image (amd64)
runs-on: ubuntu-latest
needs: get_release_info
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != ''
permissions:
contents: read
env:
REGISTRY: docker.io
IMAGE_NAME: surfpool/surfpool
outputs:
digest: ${{ steps.build.outputs.digest }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=buildkit-amd64
cache-to: type=gha,scope=buildkit-amd64,mode=max
build-image-arm64:
name: Build Docker Image (arm64)
runs-on: ubuntu-24.04-arm
needs: get_release_info
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != ''
permissions:
contents: read
env:
REGISTRY: docker.io
IMAGE_NAME: surfpool/surfpool
outputs:
digest: ${{ steps.build.outputs.digest }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/arm64
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=buildkit-arm64
cache-to: type=gha,scope=buildkit-arm64,mode=max
merge-image-manifest:
name: Merge Docker Manifest
runs-on: ubuntu-latest
needs:
- get_release_info
- build-image-amd64
- build-image-arm64
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != ''
permissions:
contents: read
env:
REGISTRY: docker.io
IMAGE_NAME: surfpool/surfpool
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Generate Docker tags
id: tags
run: |
VERSION="${{ needs.get_release_info.outputs.tag }}"
VERSION="${VERSION#v}"
MAJOR="${VERSION%%.*}"
MINOR="${VERSION%.*}"
echo "tags<<EOF" >> $GITHUB_OUTPUT
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${VERSION}" >> $GITHUB_OUTPUT
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${MINOR}" >> $GITHUB_OUTPUT
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${MAJOR}" >> $GITHUB_OUTPUT
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create multi-arch manifest
run: |
AMD64_DIGEST="${{ needs.build-image-amd64.outputs.digest }}"
ARM64_DIGEST="${{ needs.build-image-arm64.outputs.digest }}"
while IFS= read -r TAG; do
[ -z "$TAG" ] && continue
docker buildx imagetools create --tag "$TAG" \
"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${AMD64_DIGEST}" \
"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${ARM64_DIGEST}"
done <<< "${{ steps.tags.outputs.tags }}"
release:
name: Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != ''
needs:
- dist_surfpool
- get_release_info
permissions:
actions: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download pre-built dists
uses: actions/download-artifact@v4
with:
pattern: surfpool-*
- name: Tag and Release
uses: ncipollo/release-action@v1
with:
artifacts: "**/*.tar.gz,**/*.msi"
tag: ${{ needs.get_release_info.outputs.tag }}
commit: ${{ env.GITHUB_SHA }}
- name: Pack artifacts
run: |
tar -czvf surfpool-linux-x64.tar.gz surfpool-linux-x64
tar -czvf surfpool-darwin-arm64.tar.gz surfpool-darwin-arm64