From 587290335e95e6b0e6f95e66f3142a1f6b73a069 Mon Sep 17 00:00:00 2001 From: hawthorne-abendsen Date: Wed, 8 May 2024 02:18:02 +0300 Subject: [PATCH] change release name format --- .github/workflows/docker-release.yml | 5 +++ .github/workflows/release.yml | 48 ++++++++++++++++++++++------ docker/Dockerfile | 9 ++++++ docker/entrypoint.sh | 43 ++++++++++++++++++++----- 4 files changed, 87 insertions(+), 18 deletions(-) diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 201a583..547ed35 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -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 @@ -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 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9d85476..606e367 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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 }} @@ -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 }} \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index c25ac46..a7e03d6 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index c8224d8..12f948b 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -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 @@ -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 @@ -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 @@ -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 \ No newline at end of file +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" \ No newline at end of file