Skip to content

Commit

Permalink
Add rust client generation (#6)
Browse files Browse the repository at this point in the history
* Add rust client generation

* Update README.md

* Fix warnings

* Update generated code

* Change program name

* Update rust version

* Update crate name

* Fix configuration

* Update CI

* Fix script path

* Set executable flag

* Fix build directory

* Fix names

* Update lock files

* Fix directory name

* Fix file filter

* Fix IDL name

* Remove program badge

* Tweak solana-program version

* Update getting started

* Use default runner

* Fix permissions

* Add contributing section

* Update solana version

* Add generate clients note
  • Loading branch information
febo committed Oct 21, 2023
1 parent 2cb4b6a commit 1284892
Show file tree
Hide file tree
Showing 58 changed files with 7,920 additions and 4,547 deletions.
4 changes: 2 additions & 2 deletions .github/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CARGO_TERM_COLOR=always
NODE_VERSION=16.x
PROGRAMS=["mpl-project-name"]
RUST_VERSION=1.65.0
SOLANA_VERSION=1.14.13
RUST_VERSION=1.70.0
SOLANA_VERSION=1.16.18
7 changes: 7 additions & 0 deletions .github/file-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ programs: &programs
client_common: &client_common
- *programs
- ".github/workflows/test-js.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
6 changes: 3 additions & 3 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.70.0
required: true
type: string
solana:
description: Solana version
default: 1.14.13
default: 1.16.17
required: true
type: string

Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:

- name: Build programs
shell: bash
working-directory: configs/program-scripts
working-directory: configs/scripts/program
run: ./build.sh
env:
PROGRAMS: ${{ env.PROGRAMS }}
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.70.0
required: true
type: string
solana:
description: Solana version
default: 1.16.17
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_project_name*
if-no-files-found: error
78 changes: 62 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
any: ${{ steps.changes.outputs.any }}
programs: ${{ steps.changes.outputs.programs }}
program_matrix: ${{ steps.program_matrix.outputs.matrix }}
js_client: ${{ steps.changes.outputs.js_client }}
rust_client: ${{ steps.changes.outputs.rust_client }}
steps:
- name: Git checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -59,18 +61,31 @@ jobs:
if: ${{ needs.changes.outputs.any == 'true' }}
needs: build_programs
runs-on: ubuntu-latest
outputs:
js_changed: ${{ steps.changes.outputs.js_client }}
permissions:
contents: write
pull-requests: write
steps:
- name: Git checkout
uses: actions/checkout@v3

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

- name: Install Linux Build Deps
run: sudo apt-get update && sudo apt-get install -y pkg-config build-essential libudev-dev

- 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: Cache program dependencies
if: env.CACHE == 'true'
uses: metaplex-foundation/actions/cache-programs@v1

- name: Install Node.js
uses: metaplex-foundation/actions/install-node-with-pnpm@v1
with:
Expand All @@ -82,23 +97,54 @@ jobs:
if: env.CACHE == 'true'
uses: metaplex-foundation/actions/cache-idl-generators@v1

- name: Generate IDLs and clients
run: pnpm generate
- name: Install Linux Build Deps
run: sudo apt-get update && sudo apt-get install -y pkg-config build-essential libudev-dev

- name: Commit generated clients
uses: stefanzweifel/git-auto-commit-action@v4
- name: Install Rust
uses: metaplex-foundation/actions/install-rust@v1
with:
commit_message: Update generated clients
toolchain: ${{ env.RUST_VERSION }}

- name: Detect client changes
uses: dorny/paths-filter@v2
id: changes
- name: Install Solana
uses: metaplex-foundation/actions/install-solana@v1
with:
filters: .github/file-filters.yml
version: ${{ env.SOLANA_VERSION }}
cache: ${{ env.CACHE }}

- name: Cache program dependencies
if: env.CACHE == 'true'
uses: metaplex-foundation/actions/cache-programs@v1

- name: Install Node.js
uses: metaplex-foundation/actions/install-node-with-pnpm@v1
with:
version: ${{ env.NODE_VERSION }}
cache: ${{ env.CACHE }}
dependencies: true

- name: Generate IDLs and clients
run: pnpm generate

- name: Ensure working directory is clean
run: test -z "$(git status --porcelain)"

test_js:
if: needs.generate_clients.outputs.js_changed == 'true'
if: needs.changes.outputs.js_client == '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.changes.outputs.rust_client == 'true'
name: Rust Client
needs: generate_clients
uses: ./.github/workflows/build-rust-client.yml
secrets: inherit

test_rust_client:
if: needs.changes.outputs.rust_client == 'true'
name: Rust Client
needs: generate_clients
uses: ./.github/workflows/test-rust-client.yml
secrets: inherit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy JS Client
name: Publish JS Client

on:
workflow_dispatch:
Expand Down Expand Up @@ -42,8 +42,8 @@ jobs:
uses: ./.github/workflows/test-js.yml
secrets: inherit

deploy_js:
name: JS client / Deploy
publish_js:
name: JS client / Publish
runs-on: ubuntu-latest
needs: test_js
permissions:
Expand Down
105 changes: 105 additions & 0 deletions .github/workflows/publish-rust-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Publish 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

- 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 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-push --no-tag --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
if [ "${{ inputs.dry_run }}" == "false" ]; then
git reset --soft HEAD~1
fi
CLIENT_NAME=`grep -E '^name\s*=' Cargo.toml | awk -F '"' '{print $2}'`
CLIENT_VERSION=`grep -E '^version\s*=' Cargo.toml | awk -F '"' '{print $2}'`
echo CLIENT_NAME="${CLIENT_NAME}" >> $GITHUB_ENV
echo CLIENT_VERSION="${CLIENT_VERSION}" >> $GITHUB_ENV
- name: Commit and tag new version
uses: stefanzweifel/git-auto-commit-action@v4
if: github.event.inputs.dry_run == 'false'
with:
commit_message: "chore: Release ${{ env.CLIENT_NAME }} version ${{ env.CLIENT_VERSION }}"
tagging_message: ${{ env.CLIENT_NAME }}@v${{ env.CLIENT_VERSION }}
File renamed without changes.
4 changes: 2 additions & 2 deletions .github/workflows/test-programs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:

- name: Run tests
shell: bash
working-directory: configs/program-scripts
run: ./test.sh
working-directory: configs/scripts/program
run: RUST_LOG=error ./test.sh
env:
PROGRAM: ${{ matrix.program }}
Loading

0 comments on commit 1284892

Please sign in to comment.