From 6130425027da9d5dfe016bfda0dece5a8f6f6c4b Mon Sep 17 00:00:00 2001 From: hawthorne-abendsen Date: Wed, 10 Apr 2024 16:49:06 +0300 Subject: [PATCH] switch build process to soroban-cli --- .github/workflows/docker-release.yml | 54 +++++++++++++----- .github/workflows/release.yml | 5 +- docker/Dockerfile | 21 +++++++ docker/entrypoint.sh | 84 ++++------------------------ 4 files changed, 76 insertions(+), 88 deletions(-) diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 8abd35d..6feba12 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -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 "github-actions@github.com" + + - 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 \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 30283ca..c9bddd8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: | @@ -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 diff --git a/docker/Dockerfile b/docker/Dockerfile index 8f26211..2c2f45b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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} diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 5e430b7..3008721 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -26,75 +26,23 @@ 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 @@ -102,14 +50,6 @@ if [ $? -ne 0 ]; then 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") @@ -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