Skip to content

Commit

Permalink
Refactor clients CI
Browse files Browse the repository at this point in the history
  • Loading branch information
febo committed Aug 23, 2023
1 parent 693f3f8 commit 902caa9
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 82 deletions.
6 changes: 3 additions & 3 deletions .github/file-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/build-rust-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 12 additions & 24 deletions .github/workflows/create-proposal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
92 changes: 92 additions & 0 deletions .github/workflows/deploy-rust-client.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions .github/workflows/test-rust-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Crate
name: Version Program

on:
workflow_dispatch:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -130,21 +113,21 @@ jobs:
with:
name: program-builds

- name: Publish Crate
- name: Version Program
working-directory: ./programs/${{ inputs.program }}/program
run: |
git stash
git config user.name "${{ env.COMMIT_USER_NAME }}"
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
- 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 }}
16 changes: 16 additions & 0 deletions configs/client-scripts/test-js-client.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 902caa9

Please sign in to comment.