Skip to content

Commit

Permalink
change release name format
Browse files Browse the repository at this point in the history
  • Loading branch information
hawthorne-abendsen committed May 7, 2024
1 parent 05bc558 commit 5872903
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
description: 'Soroban CLI version'
required: false
type: string
rust_version:
description: 'Rust version'
required: false
type: string

permissions:
contents: write
Expand Down Expand Up @@ -63,6 +67,7 @@ jobs:
push: true
build-args: |
SOROBAN_CLI_VERSION=${{ inputs.soroban_cli_version }}
RUST_VERSION=${{ inputs.rust_version }}
tags: |
ghcr.io/${{ github.repository }}:${{ github.sha }}
ghcr.io/${{ github.repository }}:${{ inputs.release_name }}
Expand Down
48 changes: 38 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,49 @@ jobs:
working-directory: ${{ env.BUILD_DIR_PATH }}
run: docker run --rm -e RELATIVE_PATH=${{ inputs.relative_path }} -e MAKE_TARGET=${{ inputs.make_target }} -e PACKAGE=${{ inputs.package }} -v "${{ env.BUILD_DIR_PATH }}:/inspector/home" ghcr.io/stellar-expert/soroban-build-workflow:v20.3.11

- name: Get wasm file name
- name: Get compilation info
working-directory: ${{ env.BUILD_DIR_PATH }}
run: |
cd ${{ env.BUILD_DIR_PATH }}/compilation_workflow_release
wasm_file=$(find -type f -name "*.wasm")
cp $wasm_file ${{ env.BUILD_DIR_PATH }}
echo "WASM_FILE_NAME=$(basename $wasm_file)" >> $GITHUB_ENV
echo "WASM_FILE_SHA256=$(sha256sum $wasm_file | cut -d ' ' -f 1)" >> $GITHUB_ENV
# Compilation info JSON file
JSON_FILE="${BUILD_DIR_PATH}/compilation_workflow_release/compilation_info.json"
# Check if the file exists
if [ -f "$JSON_FILE" ]; then
# Read the JSON file
json=$(cat "$JSON_FILE")
# Parse values from JSON using native Bash commands
PACKAGE_NAME=$(echo "$json" | grep -oP '"packageName": "\K[^"]+')
PACKAGE_VERSION=$(echo "$json" | grep -oP '"packageVersion": "\K[^"]+')
CLI_VERSION=$(echo "$json" | grep -oP '"cliVersion": "\K[^"]+')
WASM_FILE_NAME=$(echo "$json" | grep -oP '"wasmFileName": "\K[^"]+')
WASM_HASH=$(echo "$json" | grep -oP '"wasmHash": "\K[^"]+')
# Set environment variables using 'echo' to be picked up by GitHub Actions
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
echo "CLI_VERSION=$CLI_VERSION" >> $GITHUB_ENV
echo "WASM_FILE_NAME=$WASM_FILE_NAME" >> $GITHUB_ENV
echo "WASM_HASH=$WASM_HASH" >> $GITHUB_ENV
else
echo "The JSON file $JSON_FILE does not exist."
exit 1
fi
- name: Build release name
run: |
if [ -n "${{ inputs.relative_path }}" ]; then
relative_path=$(echo "_${{ inputs.relative_path }}" | sed 's/\W\+/_/g')
fi
tag_name="${{ inputs.release_name }}${relative_path}_${{ env.WASM_FILE_NAME }}"
# Check if the release_name input is equal to PACKAGE_VERSION
if [ "${{ inputs.release_name }}" != "${{ env.PACKAGE_VERSION }}" ] && [ "${{ inputs.release_name }}" != "v${{ env.PACKAGE_VERSION }}" ]; then
pkg_version="_pkg${{ env.PACKAGE_VERSION }}"
else
pkg_version=""
fi
tag_name="${{ inputs.release_name }}${relative_path}_${{ env.PACKAGE_NAME }}${pkg_version}_cli${{ env.CLI_VERSION }}"
echo "TAG_NAME=$tag_name" >> $GITHUB_ENV
- name: Create release
Expand Down Expand Up @@ -101,7 +129,7 @@ jobs:
REL_PATH: ${{ inputs.relative_path }}
PACKAGE: ${{ inputs.package }}
MAKE: ${{ inputs.make_target }}
HASH: ${{ env.WASM_FILE_SHA256 }}
HASH: ${{ env.WASM_HASH }}
WASM: ${{ env.WASM_FILE_NAME }}

- name: Output WASM ${{ env.WASM_OUTPUT }}
Expand Down Expand Up @@ -131,7 +159,7 @@ jobs:
COMMIT_HASH: ${{ github.sha }}
JOB_ID: ${{ github.job }}
RUN_ID: ${{ github.run_id }}
CONTRACT_HASH: ${{ env.WASM_FILE_SHA256 }}
CONTRACT_HASH: ${{ env.WASM_HASH }}
RELATIVE_PATH: ${{ inputs.relative_path }}
PACKAGE_NAME: ${{ inputs.package }}
MAKE_TARGET: ${{ inputs.make_target }}
MAKE_TARGET: ${{ inputs.make_target }}
9 changes: 9 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ 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"

# Define the version argument for rustc with a default value
ARG RUST_VERSION=""

# Install the specified version of rustc
RUN if [ "$RUST_VERSION" ]; then \
rustup install "$RUST_VERSION"; \
rustup default "$RUST_VERSION"; \
fi

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

Expand Down
43 changes: 35 additions & 8 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ fi
OUTPUT="${MOUNT_DIR}/$(uuidgen)"
mkdir -p ${OUTPUT}



# Get metadata
CARGO_METADATA=$(cargo metadata --format-version=1 --no-deps)
if [ $? -ne 0 ]; then
Expand All @@ -60,12 +62,10 @@ if [ "$PACKAGE" ]; then
soroban contract build --package $PACKAGE --out-dir ${OUTPUT}
# Set the package name to the provided package name
PACKAGE_NAME=$PACKAGE
PACKAGE_VERSION=$(echo "$CARGO_METADATA" | jq '.packages[] | select(.name == "'"${PACKAGE_NAME}"'") | .version' | sed -e 's/"//g')
else
soroban contract build --out-dir ${OUTPUT}
# Get the package name from the Cargo.toml file
PACKAGE_NAME=$(grep -m1 '^name =' Cargo.toml | sed -E 's/^name = "(.*)"$/\1/')
PACKAGE_VERSION=$(grep -m1 '^version =' Cargo.toml | sed -E 's/^version = "(.*)"$/\1/')
PACKAGE_NAME=$(grep -m1 '^name =' Cargo.toml | cut -d '"' -f2)
soroban contract build --out-dir ${OUTPUT}
fi

# Verify that the build was successful
Expand All @@ -75,8 +75,15 @@ if [ $? -ne 0 ]; then
fi

# Verify that the package name and version were found
if [ -z "$PACKAGE_NAME" ] || [ -z "$PACKAGE_VERSION" ]; then
echo "ERROR: Failed to get the package name and version"
if [ -z "$PACKAGE_NAME" ]; then
echo "ERROR: Failed to get the package name"
exit 1
fi

# Get the package version
PACKAGE_VERSION=$(echo "$CARGO_METADATA" | jq '.packages[] | select(.name == "'"${PACKAGE_NAME}"'") | .version' | sed -e 's/"//g')
if [ -z "$PACKAGE_VERSION" ]; then
echo "ERROR: Failed to get the package version"
exit 1
fi

Expand Down Expand Up @@ -115,6 +122,26 @@ soroban contract optimize --wasm ${WASM_FILE_NAME} --wasm-out ${WASM_FILE_NAME}

# Verify that the optimized.wasm file exists
if [ ! -f "${RELEASE_DIR}/${WASM_FILE_NAME}" ]; then
echo "ERROR: optimized.wasm file does not exist"
echo "ERROR: wasm file doesn't exist"
exit 1
fi
fi

# Get the CLI version
CLI_VERSION=$(soroban --version | grep -oP 'soroban \K\S+')

# Calculate the SHA256 hash of the wasm file
WASM_FILE_SHA256=$(sha256sum $wasm_file | cut -d ' ' -f 1)

JSON_FILE="${RELEASE_DIR}/compilation_info.json"
jq -n --arg PACKAGE_NAME "$PACKAGE_NAME" \
--arg PACKAGE_VERSION "$PACKAGE_VERSION" \
--arg CLI_VERSION "$CLI_VERSION" \
--arg WASM_FILE_NAME "$WASM_FILE_NAME" \
--arg WASM_FILE_SHA256 "$WASM_FILE_SHA256" \
'{
packageName: $PACKAGE_NAME,
packageVersion: $PACKAGE_VERSION,
cliVersion: $CLI_VERSION,
wasmFileName: $WASM_FILE_NAME,
wasmHash: $WASM_FILE_SHA256
}' > "$JSON_FILE"

0 comments on commit 5872903

Please sign in to comment.