update-wiki.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. TEMP_REPO_DIR="wiki_action_$GITHUB_REPOSITORY$GITHUB_SHA"
  11. TEMP_WIKI_DIR="temp_wiki_$GITHUB_SHA"
  12. if [ -z "$WIKI_DIR" ]; then
  13. echo "Wiki location is not specified, using default wiki/"
  14. WIKI_DIR='wiki'
  15. fi
  16. if [ -z "$GH_TOKEN" ]; then
  17. echo "Token is not specified"
  18. exit 1
  19. fi
  20. # Clone wiki repo
  21. echo "Cloning wiki repo https://github.com/$GITHUB_REPOSITORY.wiki.git"
  22. cd "$TEMP_REPO_DIR"
  23. git clone "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git" "$TEMP_WIKI_DIR"
  24. # Get commit details
  25. author=`git log -1 --format="%an"`
  26. email=`git log -1 --format="%ae"`
  27. message=`git log -1 --format="%s"`
  28. # Copy wikis
  29. echo "Copying edited wiki"
  30. cp -R "$WIKI_DIR/" "$TEMP_WIKI_DIR"
  31. # Changes check
  32. echo "Checking if wiki has changes"
  33. cd "$TEMP_WIKI_DIR"
  34. git config --local user.email "$email"
  35. git config --local user.name "$author"
  36. git add .
  37. if git diff-index --quiet HEAD; then
  38. echo "Nothing changed"
  39. exit 0
  40. fi
  41. # Push
  42. echo "Pushing changes to wiki"
  43. git commit -m "$message" && git push "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git"
  44. # Done