From 902caa9f02521f29109010836b4f64efe95db83c Mon Sep 17 00:00:00 2001 From: febo Date: Thu, 24 Aug 2023 00:27:46 +0300 Subject: [PATCH] Refactor clients CI --- .github/file-filters.yml | 6 +- .github/workflows/build-rust-client.yml | 12 ++- .github/workflows/create-proposal.yml | 36 +++----- .../{deploy-js.yml => deploy-js-client.yml} | 0 .github/workflows/deploy-rust-client.yml | 92 +++++++++++++++++++ .github/workflows/test-rust-client.yml | 4 +- ...{publish-crate.yml => version-program.yml} | 73 ++++++--------- configs/client-scripts/test-js-client.sh | 16 ++++ .../test-rust-client.sh} | 10 +- package.json | 3 +- 10 files changed, 170 insertions(+), 82 deletions(-) rename .github/workflows/{deploy-js.yml => deploy-js-client.yml} (100%) create mode 100644 .github/workflows/deploy-rust-client.yml rename .github/workflows/{publish-crate.yml => version-program.yml} (65%) create mode 100755 configs/client-scripts/test-js-client.sh rename configs/{program-scripts/sdk.sh => client-scripts/test-rust-client.sh} (60%) diff --git a/.github/file-filters.yml b/.github/file-filters.yml index 7fb245b7..f04ab179 100644 --- a/.github/file-filters.yml +++ b/.github/file-filters.yml @@ -23,9 +23,9 @@ programs: &programs client_common: &client_common - *programs - - ".github/workflows/test-js.yml" - - ".github/workflows/test-sdk.yml" - - ".github/workflows/build-sdk.yml" + - ".github/workflows/test-js-client.yml" + - ".github/workflows/test-rust-client.yml" + - ".github/workflows/build-rust-client.yml" - ".github/workflows/main.yml" - ".github/file-filters.yml" - ".github/.env" diff --git a/.github/workflows/build-rust-client.yml b/.github/workflows/build-rust-client.yml index 616ca981..26867f5d 100644 --- a/.github/workflows/build-rust-client.yml +++ b/.github/workflows/build-rust-client.yml @@ -51,7 +51,15 @@ jobs: command: clippy args: --all-targets --all-features --no-deps --manifest-path ./clients/rust/Cargo.toml - - name: Build SDK + - name: Build Rust client shell: bash working-directory: clients/rust - run: cargo build + run: cargo build --release + + - name: Upload Rust client builds + uses: actions/upload-artifact@v3 + with: + name: rust-client-builds + # First wildcard ensures exported paths are consistently under the clients folder. + path: ./client*/rust/target/release/*mpl_token_metadata* + if-no-files-found: error diff --git a/.github/workflows/create-proposal.yml b/.github/workflows/create-proposal.yml index e259aa9e..52692828 100644 --- a/.github/workflows/create-proposal.yml +++ b/.github/workflows/create-proposal.yml @@ -101,33 +101,21 @@ jobs: - name: Determine program version run: | IDL_NAME=`echo "${{ inputs.program }}" | tr - _` - VERSION=`jq '.version' ./idls/mpl_${IDL_NAME}.json | sed 's/"//g'` + VERSION=`jq '.version' ./idls/${IDL_NAME}.json | sed 's/"//g'` MAJOR=`echo ${VERSION} | cut -d. -f1` MINOR=`echo ${VERSION} | cut -d. -f2` - PATCH=`echo ${VERSION} | cut -d. -f3-4` - - case "$PATCH" in - *"beta"*) - PRERELEASE=`echo ${PATCH} | cut -d. -f2` - PATCH=`echo ${PATCH} | cut -d- -f1` - ;; - *) - PRERELEASE=0 - ;; - esac - - if [ $PRERELEASE -eq 0 ]; then - if [ "${{ inputs.bump }}" == "major" ]; then - MAJOR=$((MAJOR + 1)) - MINOR=0 - PATCH=0 - elif [ "${{ inputs.bump }}" == "minor" ]; then - MINOR=$((MINOR + 1)) - PATCH=0 - else - PATCH=$((PATCH + 1)) - fi + PATCH=`echo ${VERSION} | cut -d. -f3` + + if [ "${{ inputs.bump }}" == "major" ]; then + MAJOR=$((MAJOR + 1)) + MINOR=0 + PATCH=0 + elif [ "${{ inputs.bump }}" == "minor" ]; then + MINOR=$((MINOR + 1)) + PATCH=0 + else + PATCH=$((PATCH + 1)) fi echo PROGRAM_VERSION="${MAJOR}.${MINOR}.${PATCH}" >> $GITHUB_ENV diff --git a/.github/workflows/deploy-js.yml b/.github/workflows/deploy-js-client.yml similarity index 100% rename from .github/workflows/deploy-js.yml rename to .github/workflows/deploy-js-client.yml diff --git a/.github/workflows/deploy-rust-client.yml b/.github/workflows/deploy-rust-client.yml new file mode 100644 index 00000000..f2aa011a --- /dev/null +++ b/.github/workflows/deploy-rust-client.yml @@ -0,0 +1,92 @@ +name: Deploy Rust Client + +on: + workflow_dispatch: + inputs: + level: + description: Level + required: true + default: patch + type: choice + options: + - patch + - minor + - major + - rc + - beta + - alpha + - release + - version + version: + description: Version + required: false + type: string + dry_run: + description: Dry run + required: true + default: true + type: boolean + +env: + CACHE: true + +jobs: + build_rust_client: + name: Rust Client + uses: ./.github/workflows/build-rust-client.yml + secrets: inherit + + test_rust_client: + name: Rust Client + needs: build_rust_client + uses: ./.github/workflows/test-rust-client.yml + secrets: inherit + + publish_crate: + name: Rust Client / Publish Crate + runs-on: ubuntu-latest + needs: test_rust_client + permissions: + contents: write + steps: + - name: Git checkout + uses: actions/checkout@v3 + with: + token: ${{ secrets.SVC_TOKEN }} + + - name: Load environment variables + run: cat .github/.env >> $GITHUB_ENV + + - name: Install Rust + uses: metaplex-foundation/actions/install-rust@v1 + with: + toolchain: ${{ env.RUST_VERSION }} + + - name: Install Solana + uses: metaplex-foundation/actions/install-solana@v1 + with: + version: ${{ env.SOLANA_VERSION }} + cache: ${{ env.CACHE }} + + - name: Install cargo-release + uses: metaplex-foundation/actions/install-cargo-release@v1 + with: + cache: ${{ env.CACHE }} + + - name: Publish Crate + working-directory: ./clients/rust + run: | + if [ "${{ inputs.level }}" == "version" ]; then + BUMP=${{ inputs.version }} + else + BUMP=${{ inputs.level }} + fi + + if [ "${{ inputs.dry_run }}" == "false" ]; then + OPTIONS="--no-confirm --execute" + fi + + if [ "${{ inputs.level }}" == "version" ]; then + + cargo login ${{ secrets.CRATES_TOKEN }} + cargo release $BUMP $OPTIONS diff --git a/.github/workflows/test-rust-client.yml b/.github/workflows/test-rust-client.yml index fdb8b1fb..fc5b4f35 100644 --- a/.github/workflows/test-rust-client.yml +++ b/.github/workflows/test-rust-client.yml @@ -38,5 +38,5 @@ jobs: - name: Run tests shell: bash - working-directory: configs/program-scripts - run: RUST_LOG=error ./sdk.sh + working-directory: configs/client-scripts + run: RUST_LOG=error ./test-rust-client.sh diff --git a/.github/workflows/publish-crate.yml b/.github/workflows/version-program.yml similarity index 65% rename from .github/workflows/publish-crate.yml rename to .github/workflows/version-program.yml index 0b433c64..7f18f5fd 100644 --- a/.github/workflows/publish-crate.yml +++ b/.github/workflows/version-program.yml @@ -1,4 +1,4 @@ -name: Publish Crate +name: Version Program on: workflow_dispatch: @@ -10,11 +10,6 @@ on: type: choice options: - token-metadata - pre_release: - description: Pre-release (beta) - required: true - type: boolean - default: false bump: description: Version bump required: true @@ -42,16 +37,22 @@ jobs: with: program_matrix: '["${{ inputs.program }}"]' - test_js: + test_js_client: name: JS client needs: test_programs - uses: ./.github/workflows/test-js.yml + uses: ./.github/workflows/test-js-client.yml + secrets: inherit + + test_rust_client: + name: Rust client + needs: test_programs + uses: ./.github/workflows/test-rust-client.yml secrets: inherit - publish_crate: - name: Program / Publish Crate + version_program: + name: Program / Version runs-on: ubuntu-latest - needs: test_js + needs: [test_js_client, test_rust_client] permissions: contents: write steps: @@ -81,43 +82,25 @@ jobs: - name: Bump Program Version run: | - IDL_NAME="mpl_`echo "${{ inputs.program }}" | tr - _`" + IDL_NAME="`echo "${{ inputs.program }}" | tr - _`" VERSION=`jq '.version' ./idls/${IDL_NAME}.json | sed 's/"//g'` MAJOR=`echo ${VERSION} | cut -d. -f1` MINOR=`echo ${VERSION} | cut -d. -f2` - PATCH=`echo ${VERSION} | cut -d. -f3-4` - - case "$PATCH" in - *"beta"*) - PRERELEASE=`echo ${PATCH} | cut -d. -f2` - PATCH=`echo ${PATCH} | cut -d- -f1` - ;; - *) - PRERELEASE=0 - ;; - esac - - if [ $PRERELEASE -eq 0 ]; then - if [ "${{ inputs.bump }}" == "major" ]; then - MAJOR=$((MAJOR + 1)) - MINOR=0 - PATCH=0 - elif [ "${{ inputs.bump }}" == "minor" ]; then - MINOR=$((MINOR + 1)) - PATCH=0 - else - PATCH=$((PATCH + 1)) - fi - fi - - if [ "${{ inputs.pre_release }}" == "true" ]; then - PRERELEASE="-beta.$((PRERELEASE + 1))" + PATCH=`echo ${VERSION} | cut -d. -f3` + + if [ "${{ inputs.bump }}" == "major" ]; then + MAJOR=$((MAJOR + 1)) + MINOR=0 + PATCH=0 + elif [ "${{ inputs.bump }}" == "minor" ]; then + MINOR=$((MINOR + 1)) + PATCH=0 else - PRERELEASE="" + PATCH=$((PATCH + 1)) fi - PROGRAM_VERSION="${MAJOR}.${MINOR}.${PATCH}${PRERELEASE}" + PROGRAM_VERSION="${MAJOR}.${MINOR}.${PATCH}" cp ./idls/${IDL_NAME}.json ./idls/${IDL_NAME}-previous.json jq ".version = \"${PROGRAM_VERSION}\"" ./idls/${IDL_NAME}-previous.json > ./idls/${IDL_NAME}.json @@ -130,7 +113,7 @@ jobs: with: name: program-builds - - name: Publish Crate + - name: Version Program working-directory: ./programs/${{ inputs.program }}/program run: | git stash @@ -138,7 +121,7 @@ jobs: git config user.email "${{ env.COMMIT_USER_EMAIL }}" cargo login ${{ secrets.CRATES_TOKEN }} - cargo release ${{ env.PROGRAM_VERSION }} --no-confirm --no-push --no-tag --execute + cargo release ${{ env.PROGRAM_VERSION }} --no-confirm --no-push --no-tag --no-publish --execute git reset --soft HEAD~1 git stash pop @@ -146,5 +129,5 @@ jobs: - name: Commit and tag new version uses: stefanzweifel/git-auto-commit-action@v4 with: - commit_message: Publish mpl-${{ inputs.program }} crate v${{ env.PROGRAM_VERSION }} - tagging_message: mpl-${{ inputs.program }}@v${{ env.PROGRAM_VERSION }} + commit_message: "chore: ${{ inputs.program }} version ${{ env.PROGRAM_VERSION }}" + tagging_message: ${{ inputs.program }}@v${{ env.PROGRAM_VERSION }} \ No newline at end of file diff --git a/configs/client-scripts/test-js-client.sh b/configs/client-scripts/test-js-client.sh new file mode 100755 index 00000000..5493aa01 --- /dev/null +++ b/configs/client-scripts/test-js-client.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +# go to parent folder +cd $(dirname $(dirname $SCRIPT_DIR)) +WORKING_DIR=$(pwd) + +# command-line input +ARGS=$* + +# js client tests folder +cd ${WORKING_DIR}/clients/js + +for t in `ls test/${ARGS}*`; do + pnpm build && pnpm test ${t} +done diff --git a/configs/program-scripts/sdk.sh b/configs/client-scripts/test-rust-client.sh similarity index 60% rename from configs/program-scripts/sdk.sh rename to configs/client-scripts/test-rust-client.sh index 01ee63fd..2a550424 100755 --- a/configs/program-scripts/sdk.sh +++ b/configs/client-scripts/test-rust-client.sh @@ -1,22 +1,22 @@ #!/bin/bash SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -OUTPUT="./programs/.bin" +PROGRAMS_OUTPUT="./programs/.bin" # go to parent folder cd $(dirname $(dirname $SCRIPT_DIR)) -# default to input from the command-line +# command-line input ARGS=$* WORKING_DIR=$(pwd) SOLFMT="solfmt" -export SBF_OUT_DIR="${WORKING_DIR}/${OUTPUT}" +export SBF_OUT_DIR="${WORKING_DIR}/${PROGRAMS_OUTPUT}" # client SDK tests cd ${WORKING_DIR}/clients/rust if [ ! "$(command -v $SOLFMT)" = "" ]; then - CARGO_TERM_COLOR=always cargo test-sbf --sbf-out-dir ${WORKING_DIR}/${OUTPUT} ${ARGS} 2>&1 | ${SOLFMT} + CARGO_TERM_COLOR=always cargo test-sbf --sbf-out-dir ${WORKING_DIR}/${PROGRAMS_OUTPUT} ${ARGS} 2>&1 | ${SOLFMT} else - cargo test-sbf --sbf-out-dir ${WORKING_DIR}/${OUTPUT} ${ARGS} + cargo test-sbf --sbf-out-dir ${WORKING_DIR}/${PROGRAMS_OUTPUT} ${ARGS} fi diff --git a/package.json b/package.json index e36b330b..82938a00 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "programs:test": "RUST_LOG=error ./configs/program-scripts/test.sh", "programs:debug": "./configs/program-scripts/test.sh", "programs:clean": "rm -rf ./programs/.bin", - "programs:sdk": "./configs/program-scripts/sdk.sh", + "clients:rust:test": "./configs/client-scripts/test-rust-client.sh", + "clients:js:test": "./configs/client-scripts/test-js-client.sh", "generate": "pnpm generate:idls && pnpm generate:clients", "generate:idls": "node ./configs/shank.cjs", "generate:clients": "node ./configs/kinobi.cjs",