Skip to content

Commit

Permalink
Merge pull request #618 from w3bdesign/develop
Browse files Browse the repository at this point in the history
👷 ci: update repomix workflow to use global install
  • Loading branch information
w3bdesign authored Jan 17, 2025
2 parents 8be4d41 + 28f3a02 commit 90de8d9
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 97 deletions.
73 changes: 66 additions & 7 deletions .github/workflows/repomix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,41 @@ jobs:
with:
node-version: "20"

- name: Install Repomix
run: npm install -g repomix

- name: Generate Repository Documentation
run: |
npx repomix --output DOCS/repository_context.txt --style markdown --remove-empty-lines
echo "Creating DOCS directory..."
mkdir -p DOCS
echo "Running Repomix..."
if ! repomix --output DOCS/repository_context.txt --style markdown --remove-empty-lines --verbose; then
echo "Error: Repomix command failed"
# Print directory contents for debugging
echo "DOCS directory contents:"
ls -la DOCS/
exit 1
fi
echo "Verifying output file..."
if [ ! -f "DOCS/repository_context.txt" ]; then
echo "Error: repository_context.txt was not created"
# Print directory contents for debugging
echo "DOCS directory contents:"
ls -la DOCS/
exit 1
fi
if [ ! -s "DOCS/repository_context.txt" ]; then
echo "Error: repository_context.txt is empty"
exit 1
fi
echo "Repository context file generated successfully"
echo "File size: $(stat --format=%s "DOCS/repository_context.txt") bytes"
echo "First few lines of the file:"
head -n 5 "DOCS/repository_context.txt"
# Handle Pull Request
- name: Comment on PR
Expand Down Expand Up @@ -93,16 +125,43 @@ jobs:
});
}
# Update Documentation (only on push to main)
# Update Documentation
- name: Commit and Push Changes
if: github.event_name == 'push'
run: |
echo "Configuring git..."
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Only commit if there are changes
echo "Checking for changes..."
if [[ -n "$(git status --porcelain)" ]]; then
git add DOCS/repository_context.txt
git commit -m "docs: update repository context via Repomix [skip ci]"
git push
echo "Changes detected, committing..."
# Stage only repository_context.txt to avoid unintended changes
if ! git add DOCS/repository_context.txt; then
echo "Error: Failed to stage repository_context.txt"
exit 1
fi
if ! git commit -m "docs: update repository context via Repomix [skip ci]"; then
echo "Error: Failed to create commit"
exit 1
fi
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "Pushing to PR branch..."
if ! git push origin HEAD:${{ github.head_ref }}; then
echo "Error: Failed to push to PR branch"
exit 1
fi
else
echo "Pushing to main branch..."
if ! git push; then
echo "Error: Failed to push changes"
exit 1
fi
fi
echo "Successfully updated repository context"
else
echo "No changes detected in repository_context.txt"
fi
230 changes: 140 additions & 90 deletions DOCS/repository_context.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This file is a merged representation of the entire codebase, combining all repository files into a single document.
Generated by Repomix on: 2025-01-17T04:19:32.619Z
Generated by Repomix on: 2025-01-17T04:32:12.483Z

# File Summary

Expand Down Expand Up @@ -610,95 +610,145 @@ tsconfig.json

## File: .github/workflows/repomix.yml
```yaml
1: name: Repository Documentation
2: on:
3: push:
4: branches:
5: - main # or your default branch name
6: pull_request:
7: types: [opened, synchronize, reopened]
8: workflow_dispatch: # allows manual triggering
9: permissions:
10: contents: write
11: pull-requests: write
12: jobs:
13: analyze:
14: runs-on: ubuntu-latest
15: steps:
16: - name: Checkout repository
17: uses: actions/checkout@v4
18: with:
19: fetch-depth: 0 # fetch all history for better context
20: - name: Setup Node.js
21: uses: actions/setup-node@v4
22: with:
23: node-version: "20"
24: - name: Generate Repository Documentation
25: run: |
26: npx repomix --output DOCS/repository_context.txt --style markdown --remove-empty-lines
27: # Handle Pull Request
28: - name: Comment on PR
29: if: github.event_name == 'pull_request'
30: uses: actions/github-script@v7
31: with:
32: script: |
33: const fs = require('fs');
34: const repoContext = fs.readFileSync('DOCS/repository_context.txt', 'utf8');
35: // Extract file summary section
36: const summaryMatch = repoContext.match(/# File Summary([\s\S]*?)(?=# |$)/);
37: const fileSummary = summaryMatch ? summaryMatch[1].trim() : '';
38: // Create a summary of the changes
39: const summary = `## 🔍 Repository Context Analysis
40: This PR has been analyzed with Repomix to provide context about how it fits into the overall repository structure.
41: ### Summary
42: ${fileSummary}
43: <details>
44: <summary>View Repository Structure</summary>
45: \`\`\`
46: ${repoContext.match(/# Repository Structure([\s\S]*?)(?=# |$)/)?.[1]?.trim() || ''}
47: \`\`\`
48: </details>
49: > Full context is available in \`DOCS/repository_context.txt\`
50: `;
51: // Find existing bot comment
52: const comments = await github.rest.issues.listComments({
53: owner: context.repo.owner,
54: repo: context.repo.repo,
55: issue_number: context.issue.number,
56: });
57: const botComment = comments.data.find(comment =>
58: comment.user.login === 'github-actions[bot]' &&
59: comment.body.includes('Repository Context Analysis')
60: );
61: if (botComment) {
62: // Update existing comment
63: await github.rest.issues.updateComment({
64: owner: context.repo.owner,
65: repo: context.repo.repo,
66: comment_id: botComment.id,
67: body: summary
68: });
69: } else {
70: // Create new comment
71: await github.rest.issues.createComment({
72: owner: context.repo.owner,
73: repo: context.repo.repo,
74: issue_number: context.issue.number,
75: body: summary
76: });
77: }
78: # Update Documentation (only on push to main)
79: - name: Commit and Push Changes
80: if: github.event_name == 'push'
81: run: |
82: git config --local user.email "github-actions[bot]@users.noreply.github.com"
83: git config --local user.name "github-actions[bot]"
84: # Only commit if there are changes
85: if [[ -n "$(git status --porcelain)" ]]; then
86: git add DOCS/repository_context.txt
87: git commit -m "docs: update repository context via Repomix [skip ci]"
88: git push
89: fi
1: name: Repository Documentation
2: on:
3: push:
4: branches:
5: - main # or your default branch name
6: pull_request:
7: types: [opened, synchronize, reopened]
8: workflow_dispatch: # allows manual triggering
9: permissions:
10: contents: write
11: pull-requests: write
12: jobs:
13: analyze:
14: runs-on: ubuntu-latest
15: steps:
16: - name: Checkout repository
17: uses: actions/checkout@v4
18: with:
19: fetch-depth: 0 # fetch all history for better context
20: - name: Setup Node.js
21: uses: actions/setup-node@v4
22: with:
23: node-version: "20"
24: - name: Install Repomix
25: run: npm install -g repomix
26: - name: Generate Repository Documentation
27: run: |
28: echo "Creating DOCS directory..."
29: mkdir -p DOCS
30: echo "Running Repomix..."
31: if ! repomix --output DOCS/repository_context.txt --style markdown --remove-empty-lines --verbose; then
32: echo "Error: Repomix command failed"
33: # Print directory contents for debugging
34: echo "DOCS directory contents:"
35: ls -la DOCS/
36: exit 1
37: fi
38: echo "Verifying output file..."
39: if [ ! -f "DOCS/repository_context.txt" ]; then
40: echo "Error: repository_context.txt was not created"
41: # Print directory contents for debugging
42: echo "DOCS directory contents:"
43: ls -la DOCS/
44: exit 1
45: fi
46: if [ ! -s "DOCS/repository_context.txt" ]; then
47: echo "Error: repository_context.txt is empty"
48: exit 1
49: fi
50: echo "Repository context file generated successfully"
51: echo "File size: $(stat --format=%s "DOCS/repository_context.txt") bytes"
52: echo "First few lines of the file:"
53: head -n 5 "DOCS/repository_context.txt"
54: # Handle Pull Request
55: - name: Comment on PR
56: if: github.event_name == 'pull_request'
57: uses: actions/github-script@v7
58: with:
59: script: |
60: const fs = require('fs');
61: const repoContext = fs.readFileSync('DOCS/repository_context.txt', 'utf8');
62: // Extract file summary section
63: const summaryMatch = repoContext.match(/# File Summary([\s\S]*?)(?=# |$)/);
64: const fileSummary = summaryMatch ? summaryMatch[1].trim() : '';
65: // Create a summary of the changes
66: const summary = `## 🔍 Repository Context Analysis
67: This PR has been analyzed with Repomix to provide context about how it fits into the overall repository structure.
68: ### Summary
69: ${fileSummary}
70: <details>
71: <summary>View Repository Structure</summary>
72: \`\`\`
73: ${repoContext.match(/# Repository Structure([\s\S]*?)(?=# |$)/)?.[1]?.trim() || ''}
74: \`\`\`
75: </details>
76: > Full context is available in \`DOCS/repository_context.txt\`
77: `;
78: // Find existing bot comment
79: const comments = await github.rest.issues.listComments({
80: owner: context.repo.owner,
81: repo: context.repo.repo,
82: issue_number: context.issue.number,
83: });
84: const botComment = comments.data.find(comment =>
85: comment.user.login === 'github-actions[bot]' &&
86: comment.body.includes('Repository Context Analysis')
87: );
88: if (botComment) {
89: // Update existing comment
90: await github.rest.issues.updateComment({
91: owner: context.repo.owner,
92: repo: context.repo.repo,
93: comment_id: botComment.id,
94: body: summary
95: });
96: } else {
97: // Create new comment
98: await github.rest.issues.createComment({
99: owner: context.repo.owner,
100: repo: context.repo.repo,
101: issue_number: context.issue.number,
102: body: summary
103: });
104: }
105: # Update Documentation
106: - name: Commit and Push Changes
107: run: |
108: echo "Configuring git..."
109: git config --local user.email "github-actions[bot]@users.noreply.github.com"
110: git config --local user.name "github-actions[bot]"
111: echo "Checking for changes..."
112: if [[ -n "$(git status --porcelain)" ]]; then
113: echo "Changes detected, committing..."
114: # Stage only repository_context.txt to avoid unintended changes
115: if ! git add DOCS/repository_context.txt; then
116: echo "Error: Failed to stage repository_context.txt"
117: exit 1
118: fi
119: if ! git commit -m "docs: update repository context via Repomix [skip ci]"; then
120: echo "Error: Failed to create commit"
121: exit 1
122: fi
123: if [ "${{ github.event_name }}" == "pull_request" ]; then
124: echo "Pushing to PR branch..."
125: if ! git push origin HEAD:${{ github.head_ref }}; then
126: echo "Error: Failed to push to PR branch"
127: exit 1
128: fi
129: else
130: echo "Pushing to main branch..."
131: if ! git push; then
132: echo "Error: Failed to push changes"
133: exit 1
134: fi
135: fi
136: echo "Successfully updated repository context"
137: else
138: echo "No changes detected in repository_context.txt"
139: fi
```

## File: .ladle/components.tsx
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Fourth version of my personal portfolio website with Next.js, Motion, Sanity.io
- React Hook Form with Typescript and Zod for efficient form handling and validation
- Reusable GenericForm component for easy form creation and management
- Error handling with react-error-boundary for improved user experience and easier debugging
- AI-friendly repository documentation with automated updates

### Design

Expand Down Expand Up @@ -100,6 +101,13 @@ Fourth version of my personal portfolio website with Next.js, Motion, Sanity.io
- Performance, accessibility, best practices, and SEO checks on every PR
- Configurable thresholds for quality metrics
- Both desktop and performance-focused testing
- Automated repository documentation with Repomix
- AI-friendly documentation generation on every push to main
- Comprehensive repository context maintained in DOCS/repository_context.txt
- Automated PR analysis with repository structure insights
- Security-focused documentation with sensitive information filtering
- Markdown formatting for improved readability
- Automated comments on PRs with codebase context

### Environment Variables

Expand Down

0 comments on commit 90de8d9

Please sign in to comment.