Skip to content

Commit

Permalink
switch build process to soroban-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
hawthorne-abendsen committed Apr 10, 2024
1 parent 2fd05c0 commit 6130425
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 88 deletions.
54 changes: 40 additions & 14 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,73 @@
name: Build, Package and Release

on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
release_name:
description: 'Name for the release'
required: true
type: string

permissions:
contents: write

jobs:
build_and_docker:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.RELEASE_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Configure git
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
- name: Update soroban-build-workflow version
run: sed -i 's/ghcr.io\/stellar-expert\/soroban-build-workflow:[^"]*/ghcr.io\/stellar-expert\/soroban-build-workflow:${{ inputs.release_name }}/' .github/workflows/release.yml

- name: Extract version tag
run: echo "VERSION_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Commit and push changes using gh
run: |
if git diff --exit-code; then
echo "No changes to commit."
exit 0
fi
git add .github/workflows/release.yml
git commit -m "Update version to ${{ inputs.release_name }}"
gh auth setup-git
git push
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GHCR using a PAT
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
password: ${{ secrets.RELEASE_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
context: ./docker
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ github.sha }}
ghcr.io/${{ github.repository }}:${{ env.VERSION_TAG }}
ghcr.io/${{ github.repository }}:${{ inputs.release_name }}
ghcr.io/${{ github.repository }}:latest
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
with:
tag_name: ${{ env.VERSION_TAG }}
tag_name: ${{ inputs.release_name }}
draft: false
prerelease: false
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ jobs:
matrix:
directory: ${{ fromJson(inputs.build_path) }}
steps:
- name: Set build directory name
- name: Set directory names and paths
run: |
build_dir_name="build_${{ strategy.job-index }}"
echo "BUILD_DIR_NAME=$build_dir_name" >> $GITHUB_ENV
echo "BUILD_DIR_PATH=${{ github.workspace }}/$build_dir_name" >> $GITHUB_ENV
echo "CONTRACT_DIR_NAME=${{ matrix.directory || '/' }}" >> $GITHUB_ENV
- name: Verify that checkout directory doesn't exist
run: |
Expand All @@ -59,7 +60,7 @@ jobs:
echo "WASM_FILE_NAME=$(basename $wasm_file)" >> $GITHUB_ENV
echo "WASM_FILE_SHA256=$(sha256sum $wasm_file | cut -d ' ' -f 1)" >> $GITHUB_ENV
- name: Wasm file from directory "${{ matrix.directory }}" with hash ${{ env.WASM_FILE_SHA256 }} created
- name: Compiled WASM ${{ env.WASM_FILE_SHA256 }} from ${{ env.CONTRACT_DIR_NAME }}
run: echo ${{ env.WASM_FILE_NAME }}

- name: Upload artifact
Expand Down
21 changes: 21 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install Rust using rustup
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

# Add Rust's cargo bin directory to your PATH
ENV PATH="${PATH}:/root/.cargo/bin"

# Install the wasm32-unknown-unknown target
RUN rustup target add wasm32-unknown-unknown

# Install soroban-cli
RUN cargo install --locked soroban-cli --features opt

# Print the version of rustc
RUN rustc --version

# Print the version of cargo
RUN cargo --version

# Print the version of soroban-cli
RUN soroban --version

# Specify the contract directory
ENV CONTRACT_DIR=${CONTRACT_DIR}

Expand Down
84 changes: 12 additions & 72 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,90 +26,30 @@ if [ "${CONTRACT_DIR}" ]; then
ls -la
fi

# Check if the Cargo.toml file exists
if [ ! -f "Cargo.toml" ]; then
echo "ERROR: Cargo.toml file does not exist"
exit 1
fi

RUST_VERSION=$(sed -n '/\[package\]/,/^$/{/rust-version = /{s/rust-version = "\(.*\)"/\1/p;}}' Cargo.toml)

# If rust version is not found in Cargo.toml, set it to the default version
if [ -z "$RUST_VERSION" ]; then
RUST_VERSION="beta"
fi
echo "Required Rust version: $RUST_VERSION"

# Installing rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && . $HOME/.cargo/env

# Verify that rustup was installed
if [ $? -ne 0 ]; then
echo "ERROR: Failed to install rustup"
exit 1
fi

# Install the required rust version
rustup install $RUST_VERSION

# Verify that rust was installed
if [ $? -ne 0 ]; then
echo "ERROR: Failed to install rust"
exit 1
fi

# Set the default rust version
rustup default $RUST_VERSION

# Verify that rust was installed
if [ $? -ne 0 ]; then
echo "ERROR: Failed to set the default rust version"
exit 1
fi

# Add the cargo bin directory to the PATH
PATH="/root/.cargo/bin:${PATH}"

# Add the wasm32-unknown-unknown target
rustup target add wasm32-unknown-unknown
# Print Rust version
rustc --version

# Verify that wasm32-unknown-unknown target was added
if [ $? -ne 0 ]; then
echo "ERROR: Failed to add wasm32-unknown-unknown target"
exit 1
fi
# Print Cargo version
cargo --version

# Install wasm-opt
wget https://github.com/WebAssembly/binaryen/releases/download/version_101/binaryen-version_101-x86_64-linux.tar.gz && \
tar -xzf binaryen-version_101-x86_64-linux.tar.gz && \
cp binaryen-version_101/bin/wasm-opt /usr/local/bin/ && \
rm -rf binaryen-version_101 binaryen-version_101-x86_64-linux.tar.gz
# Print Soroban version
soroban --version

# Verify that wasm-opt was installed
if [ $? -ne 0 ]; then
echo "ERROR: Failed to install wasm-opt"
# Check if the Cargo.toml file exists
if [ ! -f "Cargo.toml" ]; then
echo "ERROR: Cargo.toml file does not exist"
exit 1
fi

echo "Rustc Version:" $(rustc --version) && echo "Cargo Version:" $(cargo --version)

# Build the project with cargo for wasm32-unknown-unknown target
cargo build --target wasm32-unknown-unknown --release
# Build the contract
soroban contract build

# Verify that the build was successful
if [ $? -ne 0 ]; then
echo "ERROR: Failed to build the project"
exit 1
fi

echo "Rustc Version:" $(rustc --version) && echo "Cargo Version:" $(cargo --version)

# Check if the Cargo.toml file exists
if [ ! -f "Cargo.toml" ]; then
echo "ERROR: Cargo.toml file does not exist"
exit 1
fi

# Get the target directory
TARGET_DIR=$(cargo metadata --format-version=1 --no-deps | jq -r ".target_directory")

Expand Down Expand Up @@ -153,7 +93,7 @@ fi
cd ${MOUNT_DIR}/release

# Optimize the WASM file
wasm-opt -Oz ${WASM_FILE_NAME} -o ${WASM_FILE_NAME}
soroban contract optimize --wasm ${WASM_FILE_NAME} --wasm-out ${WASM_FILE_NAME}

# Verify that the optimized.wasm file exists
if [ ! -f "${MOUNT_DIR}/release/${WASM_FILE_NAME}" ]; then
Expand Down

0 comments on commit 6130425

Please sign in to comment.