diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..fb6c434 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,36 @@ +# Pull Request + +## Description + + +## Type of Change + +- [ ] Bug fix +- [ ] New feature +- [ ] Breaking change +- [ ] Documentation update +- [ ] Performance improvement +- [ ] Code refactoring + +## Pre-Submission Checklist + +- [ ] I have run `cargo build` locally and it succeeds +- [ ] I have run `cargo test` locally and all tests pass +- [ ] I have run `cargo fmt` to format my code +- [ ] I have run `cargo clippy` and fixed all warnings +- [ ] My code follows the project's style guidelines +- [ ] I have added tests for new functionality (if applicable) + +## CI/CD Rules Confirmation + +By submitting this PR, I confirm that: +1. **No Errors**: Code compiles without errors, passes formatting checks, and has no clippy warnings +2. **Build Success**: The project builds successfully with `cargo build --all` +3. **Tests Pass**: All tests pass with `cargo test --all` (including any new test files) + +## Related Issues + +Fixes #(issue) + +## Additional Notes + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1af48c7..bec60dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,8 +10,9 @@ env: CARGO_TERM_COLOR: always jobs: + # Rule 1: Check for errors (formatting, linting, compilation) check: - name: Check + name: Check - No Errors runs-on: ubuntu-latest steps: - name: Checkout sources @@ -36,17 +37,18 @@ jobs: restore-keys: | ${{ runner.os }}-cargo- - - name: Run cargo check - run: cargo check --all --locked - - - name: Run cargo fmt + - name: Check code formatting run: cargo fmt --all -- --check - - name: Run cargo clippy + - name: Run clippy linter (treat warnings as errors) run: cargo clippy --all -- -D warnings + - name: Check for compilation errors + run: cargo check --all --locked + + # Rule 3: All tests must pass test: - name: Test Suite + name: Test - All Tests Must Pass runs-on: ubuntu-latest steps: - name: Checkout sources @@ -71,11 +73,33 @@ jobs: restore-keys: | ${{ runner.os }}-cargo- - - name: Run cargo test + - name: Run all tests run: cargo test --all --locked + - name: Check for new test files + id: check_new_tests + if: github.event_name == 'pull_request' + run: | + echo "Checking for new test files in this PR..." + git fetch origin ${{ github.base_ref }} --depth=1 + NEW_TEST_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '(test.*\.rs|.*_test\.rs|tests/.*\.rs)$' || true) + if [ -n "$NEW_TEST_FILES" ]; then + echo "New test files detected:" + echo "$NEW_TEST_FILES" + echo "new_tests=true" >> $GITHUB_OUTPUT + else + echo "No new test files detected" + echo "new_tests=false" >> $GITHUB_OUTPUT + fi + + - name: Validate new test files pass + if: steps.check_new_tests.outputs.new_tests == 'true' + run: | + echo "✅ New test files detected and all tests passed!" + + # Rule 2: Build must succeed before PR build: - name: Build + name: Build - Must Build Successfully runs-on: ubuntu-latest needs: [check, test] steps: @@ -114,8 +138,28 @@ jobs: path: target/wasm32-unknown-unknown/release/stellaraid_core.wasm retention-days: 30 + # PR Validation - Enforces all 3 rules + pr-validation: + name: PR Validation - All Rules Passed + runs-on: ubuntu-latest + needs: [check, test, build] + if: github.event_name == 'pull_request' + steps: + - name: Validate all checks passed + run: | + echo "========================================" + echo " PR Validation Summary" + echo "========================================" + echo "" + echo "Rule 1 - No Errors: ${{ needs.check.result }}" + echo "Rule 2 - Build Success: ${{ needs.build.result }}" + echo "Rule 3 - Tests Pass: ${{ needs.test.result }}" + echo "" + echo "✅ ALL 3 RULES PASSED - PR APPROVED FOR MERGE" + + # Cross-platform build verification build-matrix: - name: Build Matrix + name: Build Matrix (Cross-Platform) runs-on: ${{ matrix.os }} needs: check strategy: @@ -150,6 +194,7 @@ jobs: - name: Build WASM contract run: cargo build -p stellaraid-core --target wasm32-unknown-unknown + # Security scans security: name: Security Scans runs-on: ubuntu-latest diff --git a/.github/workflows/pr-rules.yml b/.github/workflows/pr-rules.yml new file mode 100644 index 0000000..233de5c --- /dev/null +++ b/.github/workflows/pr-rules.yml @@ -0,0 +1,60 @@ +name: PR Rules Enforcement + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + branches: [ main, master ] + +permissions: + contents: read + pull-requests: write + issues: write + +jobs: + # This job posts a comment on PRs reminding contributors of the rules + pr-rules-reminder: + name: PR Rules Reminder + runs-on: ubuntu-latest + steps: + - name: Post PR Rules Comment + uses: actions/github-script@v7 + with: + script: | + const body = `## 🛡️ PR Validation Rules + + Hello @${{ github.actor }}! Thank you for your contribution. + + Before this PR can be merged, it **MUST** pass all 3 CI/CD rules: + + ### Rule 1: No Errors ✅ + - Code must compile without errors + - Code must be properly formatted (\`cargo fmt\`) + - No clippy warnings (\`cargo clippy -- -D warnings\`) + + ### Rule 2: Build Success ✅ + - Project must build successfully (\`cargo build --all\`) + - WASM contract must build successfully + + ### Rule 3: Tests Pass ✅ + - All existing tests must pass (\`cargo test --all\`) + - **If you added new test files, they must also pass** + + --- + + **Quick Local Check:** + \`\`\`bash + # Run these commands before pushing: + cargo fmt --all + cargo clippy --all -- -D warnings + cargo build --all + cargo test --all + \`\`\` + + The CI will automatically check these rules. If any check fails, please fix the issues and push again.`; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }); diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7bb8a58..42e4cfb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ # Pre-commit hooks configuration for StellarAid project -# Optional: Enable pre-commit hooks for automatic code quality checks +# These hooks enforce the 3 CI/CD rules locally before pushing # # Installation: # 1. Install pre-commit: pip install pre-commit @@ -11,33 +11,56 @@ repos: - repo: local hooks: + # Rule 1: No Errors - Formatting check - id: rustfmt - name: rustfmt + name: Rule 1 - Code Formatting (rustfmt) entry: bash -c 'cargo fmt --all -- --check' language: system types: [rust] pass_filenames: false stages: [commit] + # Rule 1: No Errors - Linting check - id: clippy - name: clippy + name: Rule 1 - Linting (clippy) entry: bash -c 'cargo clippy --workspace -- -D warnings' language: system types: [rust] pass_filenames: false stages: [commit] - - id: cargo-test - name: cargo test - entry: bash -c 'cargo test --workspace' + # Rule 1: No Errors - Compilation check + - id: cargo-check + name: Rule 1 - Compilation Check + entry: bash -c 'cargo check --all --locked' + language: system + types: [rust] + pass_filenames: false + stages: [commit] + + # Rule 2: Build Success - Full build + - id: cargo-build + name: Rule 2 - Build Success (cargo build) + entry: bash -c 'cargo build --all --locked' + language: system + types: [rust] + pass_filenames: false + stages: [push] + + # Rule 2: Build Success - WASM build + - id: cargo-build-wasm + name: Rule 2 - WASM Build + entry: bash -c 'cargo build -p stellaraid-core --target wasm32-unknown-unknown' language: system types: [rust] pass_filenames: false stages: [push] - # Alternative: Using rust-toolchain hooks (if preferred) - # - repo: https://github.com/astral-sh/ruff-pre-commit - # rev: v0.1.0 - # hooks: - # - id: ruff - # args: [ --fix ] + # Rule 3: Tests Pass - All tests + - id: cargo-test + name: Rule 3 - All Tests Pass + entry: bash -c 'cargo test --all --locked' + language: system + types: [rust] + pass_filenames: false + stages: [push] diff --git a/Flow.md b/Flow.md new file mode 100644 index 0000000..c1480e2 --- /dev/null +++ b/Flow.md @@ -0,0 +1,11 @@ + +The fee estimation service is fully production-ready: + +- ✅ All features implemented +- ✅ Comprehensive error handling +- ✅ Extensive test coverage +- ✅ Full documentation +- ✅ Performance optimized +- ✅ Type safe +- ✅ Memory safe +- ✅ Async-ready