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

feat: steel clippy fmt and contributing guidelines #326

Merged
merged 7 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
123 changes: 102 additions & 21 deletions .github/workflows/steel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,40 @@ jobs:
echo "matrix=[$(echo $indices | tr ' ' ',')]" >> $GITHUB_OUTPUT
fi

rust-checks:
needs: changes
if: ${{ github.event_name == 'pull_request' && needs.changes.outputs.total_projects != '0' }}
name: Rust Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Run sccache-cache
if: github.event_name != 'release'
uses: mozilla-actions/sccache-action@v0.0.6
- name: Set Rust cache env vars
if: github.event_name != 'release'
run: |
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
- name: Run fmt and clippy
run: |
readarray -t all_projects < <(echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]?')
for project in "${all_projects[@]}"; do
echo "::group::Checking ${project}"
if [ ! -f "${project}/Cargo.toml" ]; then
echo "::error::No Cargo.toml found in ${project}"
exit 1
fi
cd "${project}"
cargo fmt --check
cargo clippy --all-features -- -D warnings
cd - > /dev/null
echo "::endgroup::"
done

build-and-test:
needs: changes
if: needs.changes.outputs.total_projects != '0'
Expand All @@ -103,6 +137,19 @@ jobs:
failed_projects: ${{ steps.set-failed.outputs.failed_projects }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Run sccache-cache
if: github.event_name != 'release'
uses: mozilla-actions/sccache-action@v0.0.6
- name: Set Rust cache env vars
if: github.event_name != 'release'
run: |
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
path: ~/.cargo/bin/steel
key: ${{ runner.os }}-steel-cli
- name: Use Node.js
uses: actions/setup-node@v4
with:
Expand All @@ -111,6 +158,8 @@ jobs:
- name: Setup build environment
id: setup
run: |
npm install --global pnpm

# Create the build and test function
cat << 'EOF' > build_and_test.sh
function build_and_test() {
Expand All @@ -120,27 +169,53 @@ jobs:
cd "$project" || return 1

# Install dependencies
if ! pnpm install --frozen-lockfile; then
echo "::error::pnpm install failed for $project"
echo "$project: pnpm install failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
cd - > /dev/null
return 1
fi
if [ -f "package.json" ]; then
if ! pnpm install --frozen-lockfile; then
echo "::error::pnpm install failed for $project"
echo "$project: pnpm install failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
cd - > /dev/null
return 1
fi

# Build
if ! pnpm build; then
echo "::error::build failed for $project"
echo "$project: build failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
cd - > /dev/null
return 1
fi
# Build
if ! pnpm build; then
echo "::error::build failed for $project"
echo "$project: build failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
cd - > /dev/null
return 1
fi

# Test
if ! pnpm build-and-test; then
echo "::error::tests failed for $project"
echo "$project: tests failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
cd - > /dev/null
return 1
# Test
if ! pnpm build-and-test; then
echo "::error::tests failed for $project"
echo "$project: tests failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
cd - > /dev/null
return 1
fi
else
# Use Steel CLI
if ! cargo install --quiet steel-cli; then
echo "::error::steel-cli installation failed for $project"
echo "$project: steel-cli installation failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
cd - > /dev/null
return 1
fi

# Build
if ! steel build; then
echo "::error::steel build failed for $project"
echo "$project: steel build failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
cd - > /dev/null
return 1
fi

# Test
if ! steel test; then
echo "::error::steel test failed for $project"
echo "$project: steel test failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
cd - > /dev/null
return 1
fi
fi

echo "Build and tests succeeded for $project with $solana_version version."
Expand Down Expand Up @@ -177,28 +252,34 @@ jobs:
# Make the script executable
chmod +x build_and_test.sh

# Install pnpm
npm install --global pnpm
- name: Setup Solana stable
uses: heyAyushh/setup-solana@v5.4
with:
solana-cli-version: stable
- name: Build and Test with Stable
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
run: |
source build_and_test.sh
solana -V
rustc -V
process_projects "stable"
sccache --show-stats
- name: Setup Solana 1.18.17
uses: heyAyushh/setup-solana@v5.4
with:
solana-cli-version: 1.18.17
- name: Build and Test with 1.18.17
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
run: |
source build_and_test.sh
solana -V
rustc -V
process_projects "1.18.17"
sccache --show-stats

- name: Set failed projects output
id: set-failed
Expand Down
54 changes: 48 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,40 @@ Specifically for code in this repo:

1. Use pnpm as the default package manager for the project. You can [install pnpm by following the instructions](https://pnpm.io/installation). Commit `pnpm-lock.yaml` to the repository.

2. Anchor programs should be in directory `anchor`, programs written for Solana Native should be in directory `native`, TypeScript in `poseidon` and Python in `seahorse`.
2. Solana Programs written for Anchor framework should be in directory (`anchor`)[https://www.anchor-lang.com], Solana Native in (`native`)[https://solana.com/developers/guides/getstarted/intro-to-native-rust], Steel Framework in (`steel`)[https://github.com/regolith-labs/steel], TypeScript in (`poseidon`)[https://github.com/Turbin3/poseidon], respectively.
- Project path structure: `/program-examples/category/example-name/<framework_name>`
- Project path structure example for anchor: `/program-examples/category/example-name/anchor`

3. Tests for Solana native programs, steel framework programs, and Anchor should be written with [solana-bankrun](https://kevinheavey.github.io/solana-bankrun)

4. For Solana native programs and Steel framework programs ensure adding these mandatory pnpm run scripts to your `package.json` file for successful CI/CD builds:
heyAyushh marked this conversation as resolved.
Show resolved Hide resolved
4. Steel framework programs must be organized as a Cargo workspace with separate projects for API and program:
- Project path structure: `/program-examples/category/example-name/steel`
- Initialise project using `steel new <name>`
- Must be a Cargo workspace with two separate projects:
- `api`: Contains API-related code
- `program`: Contains the program implementation
- Steel projects should NOT be added in the root [`Cargo.toml` file](https://github.com/solana-developers/program-examples/blob/main/Cargo.toml)

This structure ensures proper organization and separation of concerns.

5. For Steel framework programs:
- Steel CLI is the recommended way to build and test programs:
```bash
# Install Steel CLI (one-time setup)
cargo install steel-cli

# Create a new Steel project
steel new <name>

# Build the program
steel build

# Run tests
steel test
```
- Alternatively, you can use package.json scripts if you need custom build/test configurations as Solana native one described below.

6. For Solana native programs ensure adding these mandatory pnpm run scripts to your `package.json` file for successful CI/CD builds:

```json
"scripts": {
Expand All @@ -37,20 +66,33 @@ Specifically for code in this repo:
},
```

5. Test command for Anchor should execute `pnpm test` instead of `yarn run test` for anchor programs. Replace `yarn` with `pnpm` in `[script]` table inside [Anchor.toml file.](https://www.anchor-lang.com/docs/manifest#scripts-required-for-testing)
Alternatively, You can add `steel test` and `steel build` as commands according to your project.

6. TypeScript, JavaScript and JSON files are formatted and linted using
"scripts": {
"test": "steel test",
"build-and-test": "steel build && steel test",
"build": "steel build",
"deploy": "solana program deploy ./program/target/so/program.so"
},

7. Test command for Anchor should execute `pnpm test` instead of `yarn run test` for anchor programs. Replace `yarn` with `pnpm` in `[script]` table inside [Anchor.toml file.](https://www.anchor-lang.com/docs/manifest#scripts-required-for-testing)
heyAyushh marked this conversation as resolved.
Show resolved Hide resolved

```
[scripts]
test = "pnpm ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
```

8. TypeScript, JavaScript and JSON files are formatted and linted using
[Biome](https://biomejs.dev/). Execute the following command to format and lint your code at the root of this project before submitting a pull request:

```bash
pnpm fix
```

7. Some projects can be ignored from the building and testing process by adding the project name to the `.gitignore` file.
9. Some projects can be ignored from the building and testing process by adding the project name to the `.gitignore` file.
When removing or updating an example, please ensure that the example is removed from the `.gitignore` file
and there's a change in that example's directory.


## Code of Conduct

We are committed to providing a friendly, safe, and welcoming environment for all contributors, regardless of their background, experience level, or personal characteristics. As a contributor, you are expected to:
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ members = [
"basics/cross-program-invocation/anchor/programs/*",
"basics/hello-solana/native/program",
"basics/hello-solana/anchor/programs/*",
"basics/hello-solana/steel/program",
"basics/pda-rent-payer/native/program",
"basics/pda-rent-payer/anchor/programs/*",
"basics/processing-instructions/native/program",
Expand Down
21 changes: 21 additions & 0 deletions basics/hello-solana/steel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[workspace]
resolver = "2"
members = ["program"]

[workspace.package]
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
homepage = ""
documentation = ""
repository = ""
readme = "./README.md"
keywords = ["solana"]

[workspace.dependencies]
bytemuck = "1.14"
num_enum = "0.7"
solana-program = "1.18"
steel = "2.0"
thiserror = "1.0"
solana-sdk = "1.18"
8 changes: 0 additions & 8 deletions basics/hello-solana/steel/cargo.toml

This file was deleted.

Loading