Last active
December 9, 2024 17:28
-
-
Save legendof-selda/b7374700ec588bde4012954527c146e2 to your computer and use it in GitHub Desktop.
GitHub action which syncs mkdocs to azure devops wiki.
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: Publish docs via GitHub Pages | |
# syncs your mkdocs markdown files with azure devops wiki. | |
# NOTE: this doesn't work with automated markdown files which maybe generated in your case | |
# this also doesn't deal with ordering | |
on: | |
push: | |
branches: | |
- develop | |
workflow_dispatch: | |
jobs: | |
azure-sync: | |
name: Sync with Azure WIKI | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout current repository | |
uses: actions/checkout@v3 | |
- name: Connect to Azure | |
run: | | |
git remote add azure ${{ secrets.AZURE_REPO_URL }} | |
git config user.name ${GITHUB_ACTOR} | |
git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
- name: Get md files | |
# we first remove all the files except docs | |
# Rename docs to some title so its displayed properly in azure wiki | |
# Rename all index.md files to the parent dir name since azure wiki doesn't display it correctly | |
# Rename all `image/` directories to `.image/` dir so azure will hide them. Here i tried .attachments but it wasn't working as expected. | |
# for above 2 steps i needed to do || true to ignore error which I am not sure why it happens. | |
# update in markdown all the `image/` to `.image/` | |
# azure cannot have spaces in md files or folders so replace " " with "_" | |
run: | | |
git rm -rf . | |
git checkout HEAD -- docs README.md LICENSE.txt | |
git rm -rf docs/reference/ | |
git rm -rf docs/css/ | |
find . -name "SUMMARY.md" -type f -delete | |
mv docs/ "Wiki title/" | |
find "$PWD" -type f -name "index.md" -exec bash -c ' DIR=$( dirname "{}" ); mv "{}" "$DIR"/"${DIR##*/}".md ' \; || true | |
find "$PWD" -type d -name "image" -exec bash -c ' DIR=$( dirname "{}" ); mv "{}" "$DIR"/".image/" ' \; || true | |
find . -type f -name "*.md" -exec sed -i -e 's/(image\//(\.image\//g' {} \; | |
find . -name "* *" -type d | sort -dfr | while IFS= read -r file ; do | |
if [[ $(basename "$file") =~ \ ]]; then | |
mv -f "$file" "$(dirname "$file")/$(basename "$file"| sed 's/ /_/g')" | |
fi | |
done | |
find . -name "*.md" -type f | sort -dfr | while IFS= read -r file ; do | |
if [[ $(basename "$file") =~ \ ]]; then | |
mv -f "$file" "$(dirname "$file")/$(basename "$file"| sed 's/ /_/g')" | |
fi | |
done | |
- name: Push Wiki | |
run: | | |
git checkout --orphan wiki | |
git add . | |
git commit --allow-empty -m "WIKI UPDATED on `date +'%Y-%m-%d %H:%M:%S'`" | |
git push -f azure wiki |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment