Skip to content

Generate Documentation from All Repositories #10997

Generate Documentation from All Repositories

Generate Documentation from All Repositories #10997

Workflow file for this run

name: Generate Documentation from All Repositories
on:
schedule:
- cron: '0 * * * *'
push:
branches:
- main
workflow_dispatch:
jobs:
generate-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Git
run: |
git config --global user.name "Jan Galek"
git config --global user.email "ghome.cz@gmail.com"
- name: Get list of repositories
id: repos
run: |
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/orgs/${{ github.repository_owner }}/repos?per_page=100" | jq -r '.[].full_name' > repos.txt
- name: Clone repositories and copy docs
run: |
rm -f -R ./docs
mkdir -p ./docs
CURRENT_REPO="${{ github.repository }}"
while IFS= read -r repo; do
if [[ "$repo" == "$CURRENT_REPO" ]]; then
echo "Přeskakuji aktuální repozitář: $repo"
continue
fi
echo "Clone repository: $repo"
git clone https://github.com/$repo.git
REPO_NAME=$(basename $repo)
mkdir -p ./docs/$REPO_NAME
mkdir -p ./docs/$REPO_NAME/docs
cp $REPO_NAME/README.md ./docs/$REPO_NAME/README.md
if [ -d "$REPO_NAME/docs" ]; then
echo "Nalezená složka docs v repozitáři: $repo"
if compgen -G "$REPO_NAME/docs/*.md" > /dev/null; then
cp $REPO_NAME/docs/*.* ./docs/$REPO_NAME/
else
echo "Žádné Markdown soubory nenalezeny ve složce docs v repozitáři: $repo"
fi
if compgen -G "$REPO_NAME/docs/*.*" > /dev/null; then
cp $REPO_NAME/docs/*.* ./docs/$REPO_NAME/docs/
else
echo "Žádné Markdown soubory nenalezeny ve složce docs v repozitáři: $repo"
fi
else
echo "Složka docs nenalezena v repozitáři: $repo"
fi
repo_name=$(basename $repo)
echo "[$repo_name](./$repo_name/)" >> ./docs/index.md
rm -rf $repo_name # Odstraní repozitář po zpracování
done < repos.txt
- uses: actions/setup-node@v4
with:
node-version: 20
- run: |
npm install markdown-table-formatter -g
- name: Generate _data/repos.yml
run: |
mkdir -p _data
echo "" > _data/repos.yml
for repo in ./docs/*; do
echo "Found: $repo"
if [ -d "$repo" ]; then
repo_name=$(basename "$repo")
echo "Found name: $repo_name"
echo "- name: $repo_name" >> _data/repos.yml
echo " sections:" >> _data/repos.yml
for file in "$repo"/*.md; do
if [ -f "$file" ] && [[ $(basename "$file") != "README.md" ]]; then
section_name=$(basename "$file" .md | sed 's/-/ /g' | sed 's/\b\(.\)/\u\1/g')
section_link="/docs/$repo_name/$(basename "$file" .md)"
echo " - title: $section_name" >> _data/repos.yml
echo " link: $section_link" >> _data/repos.yml
fi
done
fi
done
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Table formatter
run: |
npm install markdown-table-formatter -g
for md_file in ./docs/**/*.md; do
if [ -f "$md_file" ]; then
echo "Formátování Markdown souboru: $md_file"
markdown-table-formatter "$md_file"
fi
done
- name: Generate the sitemap
id: sitemap
uses: cicirello/generate-sitemap@v1
with:
base-url-path: https://gouef.github.io/
sitemap-format: xml
additional-extensions: md
- name: Output stats
run: |
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}"
- name: Fix permissions
run: sudo chown -R $(id -u):$(id -g) sitemap.xml
- name: Move sitemap.xml
run: mv sitemap.xml assets/
- name: Commit and push changes
run: |
if git diff --quiet ./; then
echo "Žádné změny, nic k commitování."
else
git add ./docs
git add .
git add ./docs/**/*.*
git commit -m "[Update] Automate update documentation"
git pull --rebase
git push origin HEAD:main
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Debug docs folder
run: ls -la docs
- name: Deploy Documentation to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: docs
clean-exclude:
sitemap.xml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}