Skip to content

Commit dcd9f01

Browse files
Refactor cleanrepo workflow for clarity and efficiency
1 parent 156e579 commit dcd9f01

File tree

1 file changed

+44
-23
lines changed

1 file changed

+44
-23
lines changed

.github/workflows/cleanrepo.yml

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ jobs:
2828
id: create_branch
2929
run: |
3030
BRANCH_NAME="cleanrepo-all-$(date +'%Y%m%d-%H%M')"
31+
git checkout main || git checkout -b main
32+
git pull origin main
3133
git checkout -b "$BRANCH_NAME"
3234
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
3335
34-
- name: Clean orphaned content in all folders
36+
- name: Run Clean Repo on all folders
3537
uses: actions/github-script@v6
3638
with:
3739
script: |
@@ -55,31 +57,50 @@ jobs:
5557
"defender-vulnerability-management"
5658
];
5759
58-
const functions = [
59-
"FindOrphanedArticles",
60-
"FindOrphanedImages",
61-
"FindOrphanedIncludes",
62-
"FindOrphanedSnippets"
63-
];
64-
6560
for (const folder of folders) {
66-
for (const func of functions) {
67-
await exec.exec('git', ['restore', '--source=HEAD', '--staged', '--worktree', folder]);
68-
await exec.exec('git', ['clean', '-fd', folder]);
69-
await exec.exec('git', ['pull']);
70-
await exec.exec('git', ['checkout', '${{ steps.create_branch.outputs.branch_name }}']);
71-
72-
await exec.exec('gh', [
73-
'run', 'dotnet/docs-tools/cleanrepo@main',
74-
'--function', func,
75-
'--docfx_directory', folder,
76-
'--target_directory', folder,
77-
'--url_base_path', '/dotnet'
78-
]);
79-
}
61+
core.info(`Cleaning folder: ${folder}`);
62+
63+
await exec.exec('git', ['add', folder]);
64+
65+
await exec.exec('git', ['commit', '-m', `Clean Repo: ${folder}`]);
66+
67+
await exec.exec('git', ['push', 'origin', process.env.BRANCH_NAME]);
68+
69+
await exec.exec('gh', [
70+
'workflow', 'run',
71+
'dotnet/docs-tools/cleanrepo@main',
72+
'--function', 'FindOrphanedArticles',
73+
'--docfx_directory', folder,
74+
'--target_directory', folder,
75+
'--url_base_path', '/dotnet'
76+
]);
77+
await exec.exec('gh', [
78+
'workflow', 'run',
79+
'dotnet/docs-tools/cleanrepo@main',
80+
'--function', 'FindOrphanedImages',
81+
'--docfx_directory', folder,
82+
'--target_directory', folder,
83+
'--url_base_path', '/dotnet'
84+
]);
85+
await exec.exec('gh', [
86+
'workflow', 'run',
87+
'dotnet/docs-tools/cleanrepo@main',
88+
'--function', 'FindOrphanedIncludes',
89+
'--docfx_directory', folder,
90+
'--target_directory', folder,
91+
'--url_base_path', '/dotnet'
92+
]);
93+
await exec.exec('gh', [
94+
'workflow', 'run',
95+
'dotnet/docs-tools/cleanrepo@main',
96+
'--function', 'FindOrphanedSnippets',
97+
'--docfx_directory', folder,
98+
'--target_directory', folder,
99+
'--url_base_path', '/dotnet'
100+
]);
80101
}
81102
82-
- name: Commit and push changes
103+
- name: Commit and push all changes
83104
run: |
84105
git add .
85106
git commit -m "Clean Repo: Automated cleanup across all folders"

0 commit comments

Comments
 (0)