Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rust client SDK #36

Merged
merged 22 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CARGO_TERM_COLOR=always
NODE_VERSION=16.x
PROGRAMS=["bubblegum"]
RUST_VERSION=1.68.0
SOLANA_VERSION=1.16.5
SOLANA_VERSION=1.16.8
ANCHOR_VERSION=0.27.0
COMMIT_USER_NAME="github-actions[bot]"
COMMIT_USER_EMAIL="41898282+github-actions[bot]@users.noreply.github.com"
COMMIT_USER_NAME="github-actions"
COMMIT_USER_EMAIL="github-actions@github.com"
9 changes: 8 additions & 1 deletion .github/file-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ programs: &programs

client_common: &client_common
- *programs
- ".github/workflows/test-js.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 All @@ -33,8 +35,13 @@ js_client: &js_client
- *client_common
- "clients/js/**"

rust_client: &rust_client
- *client_common
- "clients/rust/**"

clients: &clients
- *js_client
- *rust_client

# Any.

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-programs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ on:
inputs:
rust:
description: Rust version
default: 1.65.0
default: 1.68.0
required: true
type: string
solana:
description: Solana version
default: 1.14.13
default: 1.16.8
required: true
type: string

Expand Down
65 changes: 65 additions & 0 deletions .github/workflows/build-rust-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build Rust Client

on:
workflow_call:
inputs:
rust:
type: string
solana:
type: string
workflow_dispatch:
inputs:
rust:
description: Rust version
default: 1.68.0
required: true
type: string
solana:
description: Solana version
default: 1.16.8
required: true
type: string

env:
CACHE: true

jobs:
build_sdk:
name: Build
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Load environment variables
run: cat .github/.env >> $GITHUB_ENV

- name: Install Rust
uses: metaplex-foundation/actions/install-rust@v1
with:
toolchain: ${{ inputs.rust || env.RUST_VERSION }}

- name: Install Solana
uses: metaplex-foundation/actions/install-solana@v1
with:
version: ${{ inputs.solana || env.SOLANA_VERSION }}
cache: ${{ env.CACHE }}

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --all-features --no-deps --manifest-path ./clients/rust/Cargo.toml

- name: Build Rust client
shell: bash
working-directory: clients/rust
run: cargo build --all-features --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_bubblegum*
if-no-files-found: error
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
test_js:
name: JS client
needs: build_programs
uses: ./.github/workflows/test-js.yml
uses: ./.github/workflows/test-js-client.yml
secrets: inherit

deploy_js:
Expand Down
19 changes: 13 additions & 6 deletions .github/workflows/deploy-program.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ on:
- mainnet-beta
publish_crate:
description: Release cargo crate
required: true
type: boolean
default: false
bump:
Expand Down Expand Up @@ -53,7 +52,7 @@ jobs:
test_js:
name: JS client
needs: test_programs
uses: ./.github/workflows/test-js.yml
uses: ./.github/workflows/test-js-client.yml
secrets: inherit

deploy_program:
Expand Down Expand Up @@ -88,6 +87,14 @@ jobs:
version: ${{ env.ANCHOR_VERSION }}
cache: ${{ env.CACHE }}


- name: Install cargo-release
uses: metaplex-foundation/actions/install-cargo-release@v1
if: github.event.inputs.publish_crate == 'true'
with:
cache: ${{ env.CACHE }}


- name: Install cargo-release
uses: metaplex-foundation/actions/install-cargo-release@v1
if: github.event.inputs.publish_crate == 'true'
Expand Down Expand Up @@ -165,7 +172,7 @@ jobs:
rm ../../program-id.json
rm ./idl.json

- name: Publish crate
- name: Version program
working-directory: ./programs/${{ inputs.program }}/program
if: github.event.inputs.publish_crate == 'true' && github.event.inputs.cluster == 'mainnet-beta'
run: |
Expand All @@ -174,7 +181,7 @@ jobs:
git config user.email "${{ env.COMMIT_USER_EMAIL }}"

cargo login ${{ secrets.CRATES_TOKEN }}
cargo release ${{ inputs.bump }} --no-confirm --no-push --no-tag --execute
cargo release ${{ inputs.bump }} --no-confirm --no-push --no-tag --no-publish --execute

git reset --soft HEAD~1
git stash pop
Expand All @@ -183,5 +190,5 @@ jobs:
uses: stefanzweifel/git-auto-commit-action@v4
if: github.event.inputs.publish_crate == 'true' && github.event.inputs.cluster == 'mainnet-beta'
with:
commit_message: Deploy mpl-${{ inputs.program }} program v${{ env.PROGRAM_VERSION }}
tagging_message: mpl-${{ inputs.program }}@v${{ env.PROGRAM_VERSION }}
commit_message: "chore: ${{ inputs.program }} version ${{ env.PROGRAM_VERSION }}"
tagging_message: v${{ env.PROGRAM_VERSION }}@${{ inputs.cluster }}
91 changes: 91 additions & 0 deletions .github/workflows/deploy-rust-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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_programs:
name: Programs
uses: ./.github/workflows/build-programs.yml
secrets: inherit

build_rust_client:
name: Rust Client
uses: ./.github/workflows/build-rust-client.yml
secrets: inherit

test_rust_client:
name: Rust Client
needs: [build_programs, 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: "1.70.0"

- 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-publish --no-confirm --execute"
git config user.name ${{ env.COMMIT_USER_NAME }}
git config user.email ${{ env.COMMIT_USER_EMAIL }}
fi

cargo login ${{ secrets.CRATES_TOKEN }}
cargo release $BUMP $OPTIONS
17 changes: 16 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
js_changed: ${{ steps.changes.outputs.js_client }}
rust_changed: ${{ steps.changes.outputs.rust_client }}
permissions:
contents: write
pull-requests: write
Expand Down Expand Up @@ -120,5 +121,19 @@ jobs:
if: needs.generate_clients.outputs.js_changed == 'true'
name: JS Client
needs: generate_clients
uses: ./.github/workflows/test-js.yml
uses: ./.github/workflows/test-js-client.yml
secrets: inherit

build_rust_client:
if: needs.generate_clients.outputs.rust_changed == 'true'
name: Rust Client
needs: generate_clients
uses: ./.github/workflows/build-rust-client.yml
secrets: inherit

test_rust_client:
if: needs.generate_clients.outputs.rust_changed == 'true'
name: Rust Client
needs: generate_clients
uses: ./.github/workflows/test-rust-client.yml
secrets: inherit
File renamed without changes.
2 changes: 1 addition & 1 deletion .github/workflows/test-programs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ jobs:
- name: Run tests
shell: bash
working-directory: configs/program-scripts
run: ./test.sh
run: RUST_LOG=error ./test.sh
env:
PROGRAM: ${{ matrix.program }}
42 changes: 42 additions & 0 deletions .github/workflows/test-rust-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Test Rust Client

on:
workflow_call:
inputs:
program_matrix:
type: string

env:
CACHE: true

jobs:
test_sdk:
name: Test
runs-on: ubuntu-latest-16-cores
steps:
- name: Git checkout
uses: actions/checkout@v3

- 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: Download program builds
uses: actions/download-artifact@v3
with:
name: program-builds

- name: Run tests
shell: bash
working-directory: configs/client-scripts
run: RUST_LOG=error ./test-rust-client.sh
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"rust-analyzer.linkedProjects": [
"./clients/rust/Cargo.toml",
"./programs/bubblegum/Cargo.toml",
]
}
4 changes: 0 additions & 4 deletions clients/js/src/generated/instructions/mintToCollectionV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ export function mintToCollectionV1(
if (!resolvedAccounts.collectionAuthority.value) {
resolvedAccounts.collectionAuthority.value = context.identity;
}
if (!resolvedAccounts.collectionAuthorityRecordPda.value) {
resolvedAccounts.collectionAuthorityRecordPda.value = programId;
resolvedAccounts.collectionAuthorityRecordPda.isWritable = false;
}
febo marked this conversation as resolved.
Show resolved Hide resolved
if (!resolvedAccounts.collectionMetadata.value) {
resolvedAccounts.collectionMetadata.value = findMetadataPda(context, {
mint: expectPublicKey(resolvedAccounts.collectionMint.value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ export function setAndVerifyCollection(
if (!resolvedAccounts.collectionAuthority.value) {
resolvedAccounts.collectionAuthority.value = context.identity;
}
if (!resolvedAccounts.collectionAuthorityRecordPda.value) {
resolvedAccounts.collectionAuthorityRecordPda.value = programId;
resolvedAccounts.collectionAuthorityRecordPda.isWritable = false;
}
if (!resolvedAccounts.collectionMetadata.value) {
resolvedAccounts.collectionMetadata.value = findMetadataPda(context, {
mint: expectPublicKey(resolvedAccounts.collectionMint.value),
Expand Down
4 changes: 0 additions & 4 deletions clients/js/src/generated/instructions/unverifyCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,6 @@ export function unverifyCollection(
if (!resolvedAccounts.collectionAuthority.value) {
resolvedAccounts.collectionAuthority.value = context.identity;
}
if (!resolvedAccounts.collectionAuthorityRecordPda.value) {
resolvedAccounts.collectionAuthorityRecordPda.value = programId;
resolvedAccounts.collectionAuthorityRecordPda.isWritable = false;
}
if (!resolvedAccounts.collectionMetadata.value) {
resolvedAccounts.collectionMetadata.value = findMetadataPda(context, {
mint: expectPublicKey(resolvedAccounts.collectionMint.value),
Expand Down
Loading