Auto-Sync Docs from Repositories #28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Auto-Sync Docs from Repositories | |
on: | |
schedule: | |
- cron: "0 2 * * *" # Runs daily at 2 AM UTC | |
workflow_dispatch: | |
repository_dispatch: | |
types: [sync-docs] | |
jobs: | |
sync-docs: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout GitHub Pages Repo | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
fetch-depth: 0 | |
- name: Fetch Repo List from GitHub API | |
env: | |
GH_PAT: ${{ secrets.ORG_REPO_TOKEN }} | |
run: | | |
curl -s -H "Authorization: token $GH_PAT" \ | |
"https://api.github.com/orgs/khulnasoft/repos?per_page=100" \ | |
| jq -r '.[].name' > repos.txt | |
echo "Updated repos.txt:" | |
cat repos.txt | |
- name: Set up Git | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Clone and Sync Docs | |
env: | |
GH_PAT: ${{ secrets.GH_PAT }} | |
run: | | |
mkdir -p repos docs && cd repos | |
while IFS= read -r REPO; do | |
echo "Cloning $REPO..." | |
git clone --depth 1 https://x-access-token:[email protected]/khulnasoft/$REPO.git || { | |
echo "Failed to clone $REPO. Skipping..."; | |
continue; | |
} | |
mkdir -p ../docs/$REPO | |
if [ -d "$REPO/docs" ]; then | |
cp -r $REPO/docs/* ../docs/$REPO/ | |
elif [ -f "$REPO/README.md" ]; then | |
cp $REPO/README.md ../docs/$REPO.md | |
else | |
echo "Warning: No docs found for $REPO. Skipping..." | |
fi | |
rm -rf $REPO | |
done < ../repos.txt | |
cd .. | |
- name: Commit & Push Changes | |
run: | | |
git add . | |
if git diff --cached --quiet; then | |
echo "No changes detected." | |
else | |
git commit -m "Auto-sync latest docs from all repos" | |
git push "https://x-access-token:[email protected]/khulnasoft/khulnasoft.github.io.git" master |