Skip to content

Commit 0061f49

Browse files
committed
Merge PR #6: Test validation PR
2 parents 42ae566 + 4dd0a50 commit 0061f49

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3117
-702
lines changed

.github/workflows/auto-fix.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Auto-fix Code Quality Issues
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
workflow_dispatch: # Allow manual triggering
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
auto-fix:
14+
name: Auto-fix Formatting and Clippy Issues
15+
runs-on: ubuntu-latest
16+
if: ${{ !contains(github.event.head_commit.message, '[skip auto-fix]') }}
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
token: ${{ secrets.GITHUB_TOKEN }}
22+
fetch-depth: 0
23+
24+
- name: Install Rust
25+
uses: dtolnay/rust-toolchain@stable
26+
with:
27+
components: rustfmt, clippy
28+
29+
- name: Cache cargo registry
30+
uses: actions/cache@v4
31+
with:
32+
path: |
33+
~/.cargo/registry
34+
~/.cargo/git
35+
target
36+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
37+
38+
- name: Check if fixes are needed
39+
id: check
40+
run: |
41+
echo "Running format check..."
42+
FORMAT_NEEDED=false
43+
if ! cargo fmt --all -- --check; then
44+
FORMAT_NEEDED=true
45+
echo "format_needed=true" >> $GITHUB_OUTPUT
46+
fi
47+
48+
echo "Running clippy check..."
49+
CLIPPY_NEEDED=false
50+
if ! cargo clippy --all-targets --all-features -- -D warnings; then
51+
CLIPPY_NEEDED=true
52+
echo "clippy_needed=true" >> $GITHUB_OUTPUT
53+
fi
54+
55+
if [ "$FORMAT_NEEDED" = true ] || [ "$CLIPPY_NEEDED" = true ]; then
56+
echo "fixes_needed=true" >> $GITHUB_OUTPUT
57+
else
58+
echo "fixes_needed=false" >> $GITHUB_OUTPUT
59+
fi
60+
61+
- name: Apply formatting fixes
62+
if: steps.check.outputs.format_needed == 'true'
63+
run: |
64+
echo "🔧 Applying formatting fixes..."
65+
cargo fmt --all
66+
67+
- name: Apply clippy fixes
68+
if: steps.check.outputs.clippy_needed == 'true'
69+
run: |
70+
echo "🔧 Applying clippy fixes..."
71+
cargo clippy --all-targets --all-features --fix --allow-dirty --allow-staged
72+
73+
- name: Commit and push fixes
74+
if: steps.check.outputs.fixes_needed == 'true'
75+
run: |
76+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
77+
git config --local user.name "github-actions[bot]"
78+
79+
# Check if there are changes to commit
80+
if ! git diff --quiet; then
81+
git add .
82+
83+
# Create detailed commit message
84+
FORMAT_NEEDED="${FORMAT_NEEDED_VAR}"
85+
CLIPPY_NEEDED="${CLIPPY_NEEDED_VAR}"
86+
COMMIT_MSG="auto-fix: apply code quality fixes [skip auto-fix]"
87+
if [ "$FORMAT_NEEDED" = "true" ]; then
88+
COMMIT_MSG="$COMMIT_MSG
89+
90+
- Apply cargo fmt formatting"
91+
fi
92+
if [ "$CLIPPY_NEEDED" = "true" ]; then
93+
COMMIT_MSG="$COMMIT_MSG
94+
95+
- Apply clippy suggestions"
96+
fi
97+
98+
git commit -m "$COMMIT_MSG"
99+
git push
100+
101+
echo "✅ Code quality fixes applied and pushed!"
102+
else
103+
echo "ℹ️ No changes were made by the auto-fix tools."
104+
fi
105+
env:
106+
FORMAT_NEEDED_VAR: ${{ steps.check.outputs.format_needed }}
107+
CLIPPY_NEEDED_VAR: ${{ steps.check.outputs.clippy_needed }}

.github/workflows/ci.yml

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

1212
jobs:
13-
test:
14-
name: Test
13+
testing-agent:
14+
name: Testing Agent
1515
runs-on: ${{ matrix.os }}
1616
strategy:
1717
matrix:
@@ -28,25 +28,46 @@ jobs:
2828
- uses: actions/checkout@v4
2929

3030
- name: Install Rust
31-
uses: dtolnay/rust-toolchain@master
31+
uses: dtolnay/rust-toolchain@stable
3232
with:
3333
toolchain: ${{ matrix.rust }}
3434
components: rustfmt, clippy
3535

3636
- name: Cache cargo registry
37-
uses: actions/cache@v3
37+
uses: actions/cache@v4
3838
with:
3939
path: |
4040
~/.cargo/registry
4141
~/.cargo/git
4242
target
4343
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
44-
44+
4545
- name: Check formatting
4646
run: cargo fmt --all -- --check
47-
47+
continue-on-error: true
48+
id: fmt-check
49+
50+
- name: Formatting feedback
51+
if: steps.fmt-check.outcome == 'failure'
52+
run: |
53+
echo "::warning::Code formatting issues detected!"
54+
echo "Please run 'cargo fmt --all' to fix formatting."
55+
echo "Or add this to your pre-commit hook:"
56+
echo " cargo fmt --all"
57+
4858
- name: Run clippy
4959
run: cargo clippy --all-targets --all-features -- -D warnings
60+
continue-on-error: true
61+
id: clippy-check
62+
63+
- name: Clippy feedback
64+
if: steps.clippy-check.outcome == 'failure'
65+
run: |
66+
echo "::warning::Clippy issues detected!"
67+
echo "Please run 'cargo clippy --all-targets --all-features --fix --allow-dirty' to fix issues."
68+
echo "Or add this to your development workflow:"
69+
echo " cargo clippy --fix --allow-dirty"
70+
echo "Or run './scripts/fix-code-quality.sh' to auto-fix both formatting and clippy issues."
5071
5172
- name: Build
5273
run: cargo build --verbose
@@ -70,24 +91,59 @@ jobs:
7091

7192
- name: Install cargo-llvm-cov
7293
uses: taiki-e/install-action@cargo-llvm-cov
73-
94+
95+
- name: Cache cargo registry
96+
uses: actions/cache@v4
97+
with:
98+
path: |
99+
~/.cargo/registry
100+
~/.cargo/git
101+
target
102+
key: ${{ runner.os }}-cargo-coverage-${{ hashFiles('**/Cargo.lock') }}
103+
74104
- name: Generate code coverage
75-
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
105+
run: cargo llvm-cov --all-features --lcov --output-path lcov.info
106+
76107
- name: Upload coverage report
77108
uses: actions/upload-artifact@v4
78109
with:
79110
name: coverage-report
80111
path: lcov.info
81-
82112

83113
security:
84114
name: Security Audit
85115
runs-on: ubuntu-latest
86116
steps:
87117
- uses: actions/checkout@v4
88-
118+
89119
- name: Install cargo-audit
90120
uses: taiki-e/install-action@cargo-audit
91-
121+
92122
- name: Run security audit
93-
run: cargo audit
123+
run: cargo audit
124+
125+
code-review-agent:
126+
name: Code Review Agent
127+
runs-on: ubuntu-latest
128+
if: github.event_name == 'pull_request'
129+
permissions:
130+
pull-requests: write
131+
contents: read
132+
steps:
133+
- uses: actions/checkout@v4
134+
135+
- name: Install Rust
136+
uses: dtolnay/rust-toolchain@stable
137+
with:
138+
components: clippy
139+
140+
- name: Run clippy
141+
run: cargo clippy --all-targets --all-features -- -D warnings
142+
143+
- name: Comment on PR if issues found
144+
if: failure()
145+
run: |
146+
gh pr comment $PR_NUMBER --body "Code review agent detected issues. Please address the clippy warnings."
147+
env:
148+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149+
PR_NUMBER: ${{ github.event.pull_request.number }}

.github/workflows/docs.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Deploy Docs
33
on:
44
push:
55
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
68
workflow_dispatch:
79

810
permissions:
@@ -17,19 +19,20 @@ concurrency:
1719
jobs:
1820
build:
1921
runs-on: ubuntu-latest
22+
if: github.event_name != 'pull_request'
2023
steps:
2124
- uses: actions/checkout@v4
2225

2326
- name: Install Rust
2427
uses: dtolnay/rust-toolchain@stable
2528

2629
- name: Cache cargo registry
27-
uses: actions/cache@v3
30+
uses: actions/cache@v4
2831
with:
2932
path: |
3033
~/.cargo/registry
3134
~/.cargo/git
32-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
35+
key: ${{ runner.os }}-cargo-docs-${{ hashFiles('**/Cargo.lock') }}
3336

3437
- name: Build Documentation
3538
run: cargo doc --no-deps --workspace --document-private-items
@@ -57,7 +60,7 @@ jobs:
5760
uses: actions/configure-pages@v4
5861

5962
- name: Upload artifact
60-
uses: actions/upload-pages-artifact@v3
63+
uses: actions/upload-pages-artifact@v4
6164
with:
6265
path: ./target/doc
6366

@@ -67,7 +70,32 @@ jobs:
6770
url: ${{ steps.deployment.outputs.page_url }}
6871
runs-on: ubuntu-latest
6972
needs: build
73+
if: github.event_name != 'pull_request'
7074
steps:
7175
- name: Deploy to GitHub Pages
7276
id: deployment
7377
uses: actions/deploy-pages@v4
78+
79+
docs-agent:
80+
name: Docs Agent
81+
runs-on: ubuntu-latest
82+
if: github.event_name == 'pull_request'
83+
permissions:
84+
pull-requests: write
85+
contents: read
86+
steps:
87+
- uses: actions/checkout@v4
88+
89+
- name: Install Rust
90+
uses: dtolnay/rust-toolchain@stable
91+
92+
- name: Check documentation
93+
run: cargo doc --no-deps --workspace --document-private-items
94+
95+
- name: Comment on PR if docs issues
96+
if: failure()
97+
run: |
98+
gh pr comment $PR_NUMBER --body "Docs agent detected issues in documentation generation."
99+
env:
100+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
PR_NUMBER: ${{ github.event.pull_request.number }}

.github/workflows/monitor.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Monitor Workflows
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *' # Daily at midnight UTC
6+
workflow_dispatch: # Allow manual trigger for testing
7+
8+
jobs:
9+
monitor:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
issues: write
13+
contents: read
14+
actions: read
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: List recent workflow runs
20+
run: |
21+
# Calculate date 24 hours ago in ISO 8601 format
22+
since=$(date -u -d '24 hours ago' +%Y-%m-%dT%H:%M:%SZ)
23+
echo "Fetching runs since: $since"
24+
25+
# Fetch recent runs with retry logic to handle rate limits
26+
max_retries=3
27+
retry_count=0
28+
while [ $retry_count -lt $max_retries ]; do
29+
if gh run list --created ">=$since" --limit 1000 --json number,status,conclusion,workflowName,createdAt,updatedAt > runs.json 2>/dev/null; then
30+
break
31+
else
32+
retry_count=$((retry_count + 1))
33+
echo "Retry $retry_count/$max_retries due to potential rate limit or error"
34+
sleep 60
35+
fi
36+
done
37+
38+
if [ $retry_count -eq $max_retries ]; then
39+
echo "Failed to fetch runs after $max_retries retries"
40+
exit 1
41+
fi
42+
43+
- name: Check for failures in monitored workflows
44+
run: |
45+
# Define monitored workflows (without .yml extension)
46+
workflows=("auto-fix" "CI" "docs" "release" "pages")
47+
48+
failures=()
49+
50+
for wf in "${workflows[@]}"; do
51+
# Find failed runs for this workflow
52+
failed_runs=$(jq -r ".[] | select(.workflowName == \"$wf\" and .conclusion == \"failure\") | \"Run #\\(.number) (\\(.createdAt))\"" runs.json 2>/dev/null || echo "")
53+
54+
if [ -n "$failed_runs" ] && [ "$failed_runs" != "null" ]; then
55+
failures+=("$wf workflow failures:")
56+
while IFS= read -r run; do
57+
failures+=(" - $run")
58+
done <<< "$failed_runs"
59+
failures+=("") # Empty line for separation
60+
fi
61+
done
62+
63+
if [ ${#failures[@]} -gt 0 ]; then
64+
echo "Failures detected:"
65+
printf '%s\n' "${failures[@]}"
66+
67+
# Prepare notification content
68+
title="Workflow Failures Detected - $(date -u +%Y-%m-%d)"
69+
body="The following workflows have failed in the last 24 hours:\n\n$(printf '%s\n' "${failures[@]}")\n\nPlease investigate the failed runs in the Actions tab."
70+
71+
# Check for existing open issue with similar title
72+
existing_issue=$(gh issue list --label "workflow-failure" --state open --json number,title --limit 10 | jq -r ".[] | select(.title | startswith(\"Workflow Failures Detected\")) | .number" | head -1)
73+
74+
if [ -z "$existing_issue" ]; then
75+
echo "Creating new issue for workflow failures"
76+
gh issue create --title "$title" --body "$body" --label "workflow-failure,bug"
77+
else
78+
echo "Commenting on existing issue #$existing_issue"
79+
gh issue comment "$existing_issue" --body "New failures detected:\n\n$body"
80+
fi
81+
else
82+
echo "No workflow failures detected in the last 24 hours."
83+
fi

0 commit comments

Comments
 (0)