-
Notifications
You must be signed in to change notification settings - Fork 0
181 lines (154 loc) · 6.29 KB
/
Copy pathrefactor-docs.yml
File metadata and controls
181 lines (154 loc) · 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: Refactor Documentation
on:
# Run before generating docs map on pushes to main
push:
branches:
- main
- dev
paths:
- '**.md'
- '.github/scripts/refactor_docs.py'
- '.github/workflows/refactor-docs.yml'
# Run on pull requests that add/modify markdown files
pull_request:
paths:
- '**.md'
- '.github/scripts/refactor_docs.py'
# Allow manual triggering
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run (show changes without applying)'
required: false
type: boolean
default: false
permissions:
contents: write
pull-requests: write
actions: write
jobs:
refactor-documentation:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# Ensure we can push to the branch
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Make script executable
run: chmod +x .github/scripts/refactor_docs.py
- name: Run refactoring (dry-run for PRs)
id: refactor
run: |
if [ "${{ github.event_name }}" == "pull_request" ] || [ "${{ inputs.dry_run }}" == "true" ]; then
echo "Running in dry-run mode..."
python3 .github/scripts/refactor_docs.py --dry-run
echo "dry_run=true" >> $GITHUB_OUTPUT
else
echo "Running refactoring..."
python3 .github/scripts/refactor_docs.py
echo "dry_run=false" >> $GITHUB_OUTPUT
fi
- name: Check for changes
id: check_changes
run: |
git add -A
if git diff --staged --quiet; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "No documentation reorganization needed"
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "Documentation has been reorganized"
fi
- name: Determine target branch
id: target_branch
run: |
# Check if dev branch exists
if git ls-remote --heads origin dev | grep -q dev; then
echo "has_dev=true" >> $GITHUB_OUTPUT
echo "Dev branch exists - will use gitflow"
else
echo "has_dev=false" >> $GITHUB_OUTPUT
echo "No dev branch - will commit to main only"
fi
- name: Commit and push changes
if: steps.check_changes.outputs.changed == 'true' && steps.refactor.outputs.dry_run == 'false' && github.event_name == 'push'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Determine target branch based on current branch and gitflow setup
CURRENT_BRANCH="${{ github.ref_name }}"
if [ "${{ steps.target_branch.outputs.has_dev }}" == "true" ]; then
# Gitflow mode
if [ "$CURRENT_BRANCH" == "main" ]; then
TARGET_BRANCH="main"
else
TARGET_BRANCH="dev"
fi
else
# No gitflow - always commit to main
TARGET_BRANCH="main"
fi
echo "Committing to branch: $TARGET_BRANCH"
# Create commit
git commit -am "docs: refactor documentation organization [skip ci]
Automated documentation reorganization:
- Moved files to appropriate subdirectories
- Updated all internal references
- Maintained clean root directory structure"
git push origin HEAD:$TARGET_BRANCH
- name: Comment on PR with changes
if: steps.check_changes.outputs.changed == 'true' && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## 📁 Documentation Refactoring
This PR triggers documentation reorganization. The refactoring would:
- Move files to appropriate subdirectories (\`docs/project\`, \`docs/archive\`, etc.)
- Update all internal references automatically
- Keep root directory clean (only essential files remain)
**Note:** This is a dry-run preview. Changes will be applied when merged to main/dev.
Check the workflow run logs for detailed information about which files would be moved.`
});
- name: Summary
if: always()
run: |
echo "## Documentation Refactoring" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.refactor.outputs.dry_run }}" == "true" ]; then
echo "🔍 **Mode:** Dry-run (preview only)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ steps.check_changes.outputs.changed }}" == "true" ]; then
echo "✅ Documentation reorganization completed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check the workflow logs for detailed information about:" >> $GITHUB_STEP_SUMMARY
echo "- Files moved to new locations" >> $GITHUB_STEP_SUMMARY
echo "- References updated across the codebase" >> $GITHUB_STEP_SUMMARY
else
echo "ℹ️ No documentation reorganization needed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "All documentation files are already properly organized." >> $GITHUB_STEP_SUMMARY
fi
- name: Trigger documentation map generation
if: steps.check_changes.outputs.changed == 'true' && steps.refactor.outputs.dry_run == 'false' && github.event_name == 'push'
uses: actions/github-script@v7
with:
script: |
// Trigger the docs map workflow
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'generate-docs-map.yml',
ref: context.ref
});
console.log('Triggered documentation map generation workflow');