Skip to content

Commit b487354

Browse files
authored
Merge pull request #36 from ahmadogo/workflow
jikan mousa
2 parents 901258d + ec917a8 commit b487354

5 files changed

Lines changed: 197 additions & 22 deletions

File tree

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Pull Request
2+
3+
## Description
4+
<!-- Describe your changes in detail -->
5+
6+
## Type of Change
7+
<!-- Mark relevant options with [x] -->
8+
- [ ] Bug fix
9+
- [ ] New feature
10+
- [ ] Breaking change
11+
- [ ] Documentation update
12+
- [ ] Performance improvement
13+
- [ ] Code refactoring
14+
15+
## Pre-Submission Checklist
16+
<!-- All items MUST be checked before submitting PR -->
17+
- [ ] I have run `cargo build` locally and it succeeds
18+
- [ ] I have run `cargo test` locally and all tests pass
19+
- [ ] I have run `cargo fmt` to format my code
20+
- [ ] I have run `cargo clippy` and fixed all warnings
21+
- [ ] My code follows the project's style guidelines
22+
- [ ] I have added tests for new functionality (if applicable)
23+
24+
## CI/CD Rules Confirmation
25+
<!-- These rules are enforced automatically -->
26+
By submitting this PR, I confirm that:
27+
1. **No Errors**: Code compiles without errors, passes formatting checks, and has no clippy warnings
28+
2. **Build Success**: The project builds successfully with `cargo build --all`
29+
3. **Tests Pass**: All tests pass with `cargo test --all` (including any new test files)
30+
31+
## Related Issues
32+
<!-- Link to related issues using #issue_number -->
33+
Fixes #(issue)
34+
35+
## Additional Notes
36+
<!-- Any additional information for reviewers -->

.github/workflows/ci.yml

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ env:
1010
CARGO_TERM_COLOR: always
1111

1212
jobs:
13+
# Rule 1: Check for errors (formatting, linting, compilation)
1314
check:
14-
name: Check
15+
name: Check - No Errors
1516
runs-on: ubuntu-latest
1617
steps:
1718
- name: Checkout sources
@@ -36,17 +37,18 @@ jobs:
3637
restore-keys: |
3738
${{ runner.os }}-cargo-
3839
39-
- name: Run cargo check
40-
run: cargo check --all --locked
41-
42-
- name: Run cargo fmt
40+
- name: Check code formatting
4341
run: cargo fmt --all -- --check
4442

45-
- name: Run cargo clippy
43+
- name: Run clippy linter (treat warnings as errors)
4644
run: cargo clippy --all -- -D warnings
4745

46+
- name: Check for compilation errors
47+
run: cargo check --all --locked
48+
49+
# Rule 3: All tests must pass
4850
test:
49-
name: Test Suite
51+
name: Test - All Tests Must Pass
5052
runs-on: ubuntu-latest
5153
steps:
5254
- name: Checkout sources
@@ -71,11 +73,33 @@ jobs:
7173
restore-keys: |
7274
${{ runner.os }}-cargo-
7375
74-
- name: Run cargo test
76+
- name: Run all tests
7577
run: cargo test --all --locked
7678

79+
- name: Check for new test files
80+
id: check_new_tests
81+
if: github.event_name == 'pull_request'
82+
run: |
83+
echo "Checking for new test files in this PR..."
84+
git fetch origin ${{ github.base_ref }} --depth=1
85+
NEW_TEST_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '(test.*\.rs|.*_test\.rs|tests/.*\.rs)$' || true)
86+
if [ -n "$NEW_TEST_FILES" ]; then
87+
echo "New test files detected:"
88+
echo "$NEW_TEST_FILES"
89+
echo "new_tests=true" >> $GITHUB_OUTPUT
90+
else
91+
echo "No new test files detected"
92+
echo "new_tests=false" >> $GITHUB_OUTPUT
93+
fi
94+
95+
- name: Validate new test files pass
96+
if: steps.check_new_tests.outputs.new_tests == 'true'
97+
run: |
98+
echo "✅ New test files detected and all tests passed!"
99+
100+
# Rule 2: Build must succeed before PR
77101
build:
78-
name: Build
102+
name: Build - Must Build Successfully
79103
runs-on: ubuntu-latest
80104
needs: [check, test]
81105
steps:
@@ -114,8 +138,28 @@ jobs:
114138
path: target/wasm32-unknown-unknown/release/stellaraid_core.wasm
115139
retention-days: 30
116140

141+
# PR Validation - Enforces all 3 rules
142+
pr-validation:
143+
name: PR Validation - All Rules Passed
144+
runs-on: ubuntu-latest
145+
needs: [check, test, build]
146+
if: github.event_name == 'pull_request'
147+
steps:
148+
- name: Validate all checks passed
149+
run: |
150+
echo "========================================"
151+
echo " PR Validation Summary"
152+
echo "========================================"
153+
echo ""
154+
echo "Rule 1 - No Errors: ${{ needs.check.result }}"
155+
echo "Rule 2 - Build Success: ${{ needs.build.result }}"
156+
echo "Rule 3 - Tests Pass: ${{ needs.test.result }}"
157+
echo ""
158+
echo "✅ ALL 3 RULES PASSED - PR APPROVED FOR MERGE"
159+
160+
# Cross-platform build verification
117161
build-matrix:
118-
name: Build Matrix
162+
name: Build Matrix (Cross-Platform)
119163
runs-on: ${{ matrix.os }}
120164
needs: check
121165
strategy:
@@ -150,6 +194,7 @@ jobs:
150194
- name: Build WASM contract
151195
run: cargo build -p stellaraid-core --target wasm32-unknown-unknown
152196

197+
# Security scans
153198
security:
154199
name: Security Scans
155200
runs-on: ubuntu-latest

.github/workflows/pr-rules.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: PR Rules Enforcement
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
branches: [ main, master ]
7+
8+
permissions:
9+
contents: read
10+
pull-requests: write
11+
issues: write
12+
13+
jobs:
14+
# This job posts a comment on PRs reminding contributors of the rules
15+
pr-rules-reminder:
16+
name: PR Rules Reminder
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Post PR Rules Comment
20+
uses: actions/github-script@v7
21+
with:
22+
script: |
23+
const body = `## 🛡️ PR Validation Rules
24+
25+
Hello @${{ github.actor }}! Thank you for your contribution.
26+
27+
Before this PR can be merged, it **MUST** pass all 3 CI/CD rules:
28+
29+
### Rule 1: No Errors ✅
30+
- Code must compile without errors
31+
- Code must be properly formatted (\`cargo fmt\`)
32+
- No clippy warnings (\`cargo clippy -- -D warnings\`)
33+
34+
### Rule 2: Build Success ✅
35+
- Project must build successfully (\`cargo build --all\`)
36+
- WASM contract must build successfully
37+
38+
### Rule 3: Tests Pass ✅
39+
- All existing tests must pass (\`cargo test --all\`)
40+
- **If you added new test files, they must also pass**
41+
42+
---
43+
44+
**Quick Local Check:**
45+
\`\`\`bash
46+
# Run these commands before pushing:
47+
cargo fmt --all
48+
cargo clippy --all -- -D warnings
49+
cargo build --all
50+
cargo test --all
51+
\`\`\`
52+
53+
The CI will automatically check these rules. If any check fails, please fix the issues and push again.`;
54+
55+
github.rest.issues.createComment({
56+
issue_number: context.issue.number,
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
body: body
60+
});

.pre-commit-config.yaml

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Pre-commit hooks configuration for StellarAid project
2-
# Optional: Enable pre-commit hooks for automatic code quality checks
2+
# These hooks enforce the 3 CI/CD rules locally before pushing
33
#
44
# Installation:
55
# 1. Install pre-commit: pip install pre-commit
@@ -11,33 +11,56 @@
1111
repos:
1212
- repo: local
1313
hooks:
14+
# Rule 1: No Errors - Formatting check
1415
- id: rustfmt
15-
name: rustfmt
16+
name: Rule 1 - Code Formatting (rustfmt)
1617
entry: bash -c 'cargo fmt --all -- --check'
1718
language: system
1819
types: [rust]
1920
pass_filenames: false
2021
stages: [commit]
2122

23+
# Rule 1: No Errors - Linting check
2224
- id: clippy
23-
name: clippy
25+
name: Rule 1 - Linting (clippy)
2426
entry: bash -c 'cargo clippy --workspace -- -D warnings'
2527
language: system
2628
types: [rust]
2729
pass_filenames: false
2830
stages: [commit]
2931

30-
- id: cargo-test
31-
name: cargo test
32-
entry: bash -c 'cargo test --workspace'
32+
# Rule 1: No Errors - Compilation check
33+
- id: cargo-check
34+
name: Rule 1 - Compilation Check
35+
entry: bash -c 'cargo check --all --locked'
36+
language: system
37+
types: [rust]
38+
pass_filenames: false
39+
stages: [commit]
40+
41+
# Rule 2: Build Success - Full build
42+
- id: cargo-build
43+
name: Rule 2 - Build Success (cargo build)
44+
entry: bash -c 'cargo build --all --locked'
45+
language: system
46+
types: [rust]
47+
pass_filenames: false
48+
stages: [push]
49+
50+
# Rule 2: Build Success - WASM build
51+
- id: cargo-build-wasm
52+
name: Rule 2 - WASM Build
53+
entry: bash -c 'cargo build -p stellaraid-core --target wasm32-unknown-unknown'
3354
language: system
3455
types: [rust]
3556
pass_filenames: false
3657
stages: [push]
3758

38-
# Alternative: Using rust-toolchain hooks (if preferred)
39-
# - repo: https://github.com/astral-sh/ruff-pre-commit
40-
# rev: v0.1.0
41-
# hooks:
42-
# - id: ruff
43-
# args: [ --fix ]
59+
# Rule 3: Tests Pass - All tests
60+
- id: cargo-test
61+
name: Rule 3 - All Tests Pass
62+
entry: bash -c 'cargo test --all --locked'
63+
language: system
64+
types: [rust]
65+
pass_filenames: false
66+
stages: [push]

Flow.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
The fee estimation service is fully production-ready:
3+
4+
- ✅ All features implemented
5+
- ✅ Comprehensive error handling
6+
- ✅ Extensive test coverage
7+
- ✅ Full documentation
8+
- ✅ Performance optimized
9+
- ✅ Type safe
10+
- ✅ Memory safe
11+
- ✅ Async-ready

0 commit comments

Comments
 (0)