فهرست منبع

steel clippy fmt and contributing guidelines

Ayush 11 ماه پیش
والد
کامیت
4e4a97ac4c
3فایلهای تغییر یافته به همراه131 افزوده شده و 25 حذف شده
  1. 97 19
      .github/workflows/steel.yml
  2. 34 5
      CONTRIBUTING.md
  3. 0 1
      Cargo.toml

+ 97 - 19
.github/workflows/steel.yml

@@ -90,6 +90,50 @@ jobs:
             echo "matrix=[$(echo $indices | tr ' ' ',')]" >> $GITHUB_OUTPUT
           fi
 
+  fmt:
+    needs: changes
+    if: ${{ github.event_name == 'pull_request' && needs.changes.outputs.total_projects != '0' }}
+    name: Rustfmt
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+      - uses: dtolnay/rust-toolchain@stable
+        with:
+          components: rustfmt
+      - uses: mozilla-actions/sccache-action@v0.0.4
+      - name: Run fmt
+        run: |
+          readarray -t projects < <(echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]')
+          for project in "${projects[@]}"; do
+            if [ -f "$project/Cargo.toml" ]; then
+              cd "$project"
+              cargo fmt --check
+              cd - > /dev/null
+            fi
+          done
+
+  clippy:
+    needs: changes
+    if: ${{ github.event_name == 'pull_request' && needs.changes.outputs.total_projects != '0' }}
+    name: Clippy
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+      - uses: dtolnay/rust-toolchain@stable
+        with:
+          components: clippy
+      - uses: mozilla-actions/sccache-action@v0.0.4
+      - name: Run clippy
+        run: |
+          readarray -t projects < <(echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]')
+          for project in "${projects[@]}"; do
+            if [ -f "$project/Cargo.toml" ]; then
+              cd "$project"
+              cargo clippy -- -D warnings
+              cd - > /dev/null
+            fi
+          done
+
   build-and-test:
     needs: changes
     if: needs.changes.outputs.total_projects != '0'
@@ -120,27 +164,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 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."
@@ -184,21 +254,29 @@ jobs:
         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

+ 34 - 5
CONTRIBUTING.md

@@ -23,10 +23,38 @@ 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`.
+  - Project path structure: `/program-examples/category/example-name/steel`
 
 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:
+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": {
@@ -37,20 +65,21 @@ 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
+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)
+
+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:

+ 0 - 1
Cargo.toml

@@ -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",