2
0

update-wiki.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/sh
  2. #
  3. # Copyright (c) Milan Jurkulák 2024.
  4. # Contact:
  5. # e: mimoccc@gmail.com
  6. # e: mj@mjdev.org
  7. # w: https://mjdev.org
  8. #
  9. set -eu
  10. #
  11. TEMP_REPO_DIR="$GITHUB_REPOSITORY$GITHUB_SHA"
  12. #
  13. if [ -z "$WIKI_DIR" ]; then
  14. echo "Wiki location is not specified, using default wiki/"
  15. WIKI_DIR='wiki'
  16. fi
  17. #
  18. if [ -z "$GH_TOKEN" ]; then
  19. echo "Token is not specified"
  20. exit 1
  21. fi
  22. # Clone wiki repo
  23. echo "Cloning wiki repo https://github.com/$GITHUB_REPOSITORY.wiki.git"
  24. #
  25. git clone "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git" "$TEMP_REPO_DIR"
  26. # Copy wikis
  27. echo "Copying edited wiki"
  28. cp -R "$WIKI_DIR/" "$TEMP_REPO_DIR"
  29. # Get commit details
  30. author=`git log -1 --format="%an"`
  31. email=`git log -1 --format="%ae"`
  32. message=`git log -1 --format="%s"`
  33. # Changes check
  34. echo "Checking if wiki has changes"
  35. cd "$TEMP_REPO_DIR" || exit
  36. git config --local user.email "$email"
  37. git config --local user.name "$author"
  38. git add .
  39. if git diff-index --quiet HEAD; then
  40. echo "Nothing changed"
  41. exit 0
  42. fi
  43. # Push
  44. echo "Pushing changes to wiki"
  45. git commit -m "$message" && git push "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git"
  46. # Done