Skip to content

Commit 0ea4387

Browse files
authored
feat: steel clippy fmt and contributing guidelines (#326)
* steel clippy fmt and contributing guidelines * clippy and fmt run fix, steel workspace check * Improve contributing
1 parent 46f66f3 commit 0ea4387

File tree

5 files changed

+171
-36
lines changed

5 files changed

+171
-36
lines changed

.github/workflows/steel.yml

Lines changed: 102 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,40 @@ jobs:
9090
echo "matrix=[$(echo $indices | tr ' ' ',')]" >> $GITHUB_OUTPUT
9191
fi
9292
93+
rust-checks:
94+
needs: changes
95+
if: ${{ github.event_name == 'pull_request' && needs.changes.outputs.total_projects != '0' }}
96+
name: Rust Checks
97+
runs-on: ubuntu-latest
98+
steps:
99+
- uses: actions/checkout@v4
100+
- uses: dtolnay/rust-toolchain@stable
101+
with:
102+
components: rustfmt, clippy
103+
- name: Run sccache-cache
104+
if: github.event_name != 'release'
105+
uses: mozilla-actions/[email protected]
106+
- name: Set Rust cache env vars
107+
if: github.event_name != 'release'
108+
run: |
109+
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
110+
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
111+
- name: Run fmt and clippy
112+
run: |
113+
readarray -t all_projects < <(echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]?')
114+
for project in "${all_projects[@]}"; do
115+
echo "::group::Checking ${project}"
116+
if [ ! -f "${project}/Cargo.toml" ]; then
117+
echo "::error::No Cargo.toml found in ${project}"
118+
exit 1
119+
fi
120+
cd "${project}"
121+
cargo fmt --check
122+
cargo clippy --all-features -- -D warnings
123+
cd - > /dev/null
124+
echo "::endgroup::"
125+
done
126+
93127
build-and-test:
94128
needs: changes
95129
if: needs.changes.outputs.total_projects != '0'
@@ -103,6 +137,19 @@ jobs:
103137
failed_projects: ${{ steps.set-failed.outputs.failed_projects }}
104138
steps:
105139
- uses: actions/checkout@v4
140+
- uses: dtolnay/rust-toolchain@stable
141+
- name: Run sccache-cache
142+
if: github.event_name != 'release'
143+
uses: mozilla-actions/[email protected]
144+
- name: Set Rust cache env vars
145+
if: github.event_name != 'release'
146+
run: |
147+
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
148+
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
149+
- uses: actions/cache@v3
150+
with:
151+
path: ~/.cargo/bin/steel
152+
key: ${{ runner.os }}-steel-cli
106153
- name: Use Node.js
107154
uses: actions/setup-node@v4
108155
with:
@@ -111,6 +158,8 @@ jobs:
111158
- name: Setup build environment
112159
id: setup
113160
run: |
161+
npm install --global pnpm
162+
114163
# Create the build and test function
115164
cat << 'EOF' > build_and_test.sh
116165
function build_and_test() {
@@ -120,27 +169,53 @@ jobs:
120169
cd "$project" || return 1
121170
122171
# Install dependencies
123-
if ! pnpm install --frozen-lockfile; then
124-
echo "::error::pnpm install failed for $project"
125-
echo "$project: pnpm install failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
126-
cd - > /dev/null
127-
return 1
128-
fi
172+
if [ -f "package.json" ]; then
173+
if ! pnpm install --frozen-lockfile; then
174+
echo "::error::pnpm install failed for $project"
175+
echo "$project: pnpm install failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
176+
cd - > /dev/null
177+
return 1
178+
fi
129179
130-
# Build
131-
if ! pnpm build; then
132-
echo "::error::build failed for $project"
133-
echo "$project: build failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
134-
cd - > /dev/null
135-
return 1
136-
fi
180+
# Build
181+
if ! pnpm build; then
182+
echo "::error::build failed for $project"
183+
echo "$project: build failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
184+
cd - > /dev/null
185+
return 1
186+
fi
137187
138-
# Test
139-
if ! pnpm build-and-test; then
140-
echo "::error::tests failed for $project"
141-
echo "$project: tests failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
142-
cd - > /dev/null
143-
return 1
188+
# Test
189+
if ! pnpm build-and-test; then
190+
echo "::error::tests failed for $project"
191+
echo "$project: tests failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
192+
cd - > /dev/null
193+
return 1
194+
fi
195+
else
196+
# Use Steel CLI
197+
if ! cargo install --quiet steel-cli; then
198+
echo "::error::steel-cli installation failed for $project"
199+
echo "$project: steel-cli installation failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
200+
cd - > /dev/null
201+
return 1
202+
fi
203+
204+
# Build
205+
if ! steel build; then
206+
echo "::error::steel build failed for $project"
207+
echo "$project: steel build failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
208+
cd - > /dev/null
209+
return 1
210+
fi
211+
212+
# Test
213+
if ! steel test; then
214+
echo "::error::steel test failed for $project"
215+
echo "$project: steel test failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
216+
cd - > /dev/null
217+
return 1
218+
fi
144219
fi
145220
146221
echo "Build and tests succeeded for $project with $solana_version version."
@@ -177,28 +252,34 @@ jobs:
177252
# Make the script executable
178253
chmod +x build_and_test.sh
179254
180-
# Install pnpm
181-
npm install --global pnpm
182255
- name: Setup Solana stable
183256
uses: heyAyushh/[email protected]
184257
with:
185258
solana-cli-version: stable
186259
- name: Build and Test with Stable
260+
env:
261+
SCCACHE_GHA_ENABLED: "true"
262+
RUSTC_WRAPPER: "sccache"
187263
run: |
188264
source build_and_test.sh
189265
solana -V
190266
rustc -V
191267
process_projects "stable"
268+
sccache --show-stats
192269
- name: Setup Solana 1.18.17
193270
uses: heyAyushh/[email protected]
194271
with:
195272
solana-cli-version: 1.18.17
196273
- name: Build and Test with 1.18.17
274+
env:
275+
SCCACHE_GHA_ENABLED: "true"
276+
RUSTC_WRAPPER: "sccache"
197277
run: |
198278
source build_and_test.sh
199279
solana -V
200280
rustc -V
201281
process_projects "1.18.17"
282+
sccache --show-stats
202283
203284
- name: Set failed projects output
204285
id: set-failed

CONTRIBUTING.md

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,40 @@ Specifically for code in this repo:
2222

2323
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.
2424

25-
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`.
25+
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.
26+
- Project path structure: `/program-examples/category/example-name/<framework_name>`
27+
- Project path structure example for anchor: `/program-examples/category/example-name/anchor`
2628

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

29-
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:
31+
4. Steel framework programs must be organized as a Cargo workspace with separate projects for API and program:
32+
- Project path structure: `/program-examples/category/example-name/steel`
33+
- Initialise project using `steel new <name>`
34+
- Must be a Cargo workspace with two separate projects:
35+
- `api`: Contains API-related code
36+
- `program`: Contains the program implementation
37+
- Steel projects should NOT be added in the root [`Cargo.toml` file](https://github.com/solana-developers/program-examples/blob/main/Cargo.toml)
38+
39+
This structure ensures proper organization and separation of concerns.
40+
41+
5. For Steel framework programs:
42+
- Steel CLI is the recommended way to build and test programs:
43+
```bash
44+
# Install Steel CLI (one-time setup)
45+
cargo install steel-cli
46+
47+
# Create a new Steel project
48+
steel new <name>
49+
50+
# Build the program
51+
steel build
52+
53+
# Run tests
54+
steel test
55+
```
56+
- Alternatively, you can use package.json scripts if you need custom build/test configurations as Solana native one described below.
57+
58+
6. For Solana native programs ensure adding these mandatory pnpm run scripts to your `package.json` file for successful CI/CD builds:
3059

3160
```json
3261
"scripts": {
@@ -37,20 +66,33 @@ Specifically for code in this repo:
3766
},
3867
```
3968

40-
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)
69+
Alternatively, You can add `steel test` and `steel build` as commands according to your project.
4170

42-
6. TypeScript, JavaScript and JSON files are formatted and linted using
71+
"scripts": {
72+
"test": "steel test",
73+
"build-and-test": "steel build && steel test",
74+
"build": "steel build",
75+
"deploy": "solana program deploy ./program/target/so/program.so"
76+
},
77+
78+
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)
79+
80+
```
81+
[scripts]
82+
test = "pnpm ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
83+
```
84+
85+
8. TypeScript, JavaScript and JSON files are formatted and linted using
4386
[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:
4487

4588
```bash
4689
pnpm fix
4790
```
4891

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

53-
5496
## Code of Conduct
5597

5698
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:

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ members = [
1515
"basics/cross-program-invocation/anchor/programs/*",
1616
"basics/hello-solana/native/program",
1717
"basics/hello-solana/anchor/programs/*",
18-
"basics/hello-solana/steel/program",
1918
"basics/pda-rent-payer/native/program",
2019
"basics/pda-rent-payer/anchor/programs/*",
2120
"basics/processing-instructions/native/program",

basics/hello-solana/steel/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[workspace]
2+
resolver = "2"
3+
members = ["program"]
4+
5+
[workspace.package]
6+
version = "0.1.0"
7+
edition = "2021"
8+
license = "Apache-2.0"
9+
homepage = ""
10+
documentation = ""
11+
repository = ""
12+
readme = "./README.md"
13+
keywords = ["solana"]
14+
15+
[workspace.dependencies]
16+
bytemuck = "1.14"
17+
num_enum = "0.7"
18+
solana-program = "1.18"
19+
steel = "2.0"
20+
thiserror = "1.0"
21+
solana-sdk = "1.18"

basics/hello-solana/steel/cargo.toml

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)