2
0

update-wiki.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 "Removing old wiki"
  28. old_dir=$(pwd)
  29. cd "$TEMP_REPO_DIR" || exit
  30. git rm -rf .
  31. git clean -fxd
  32. #git update-ref -d refs/heads/master
  33. #git push
  34. #git pull
  35. cd "$old_dir" || exit
  36. echo "Copying edited wiki"
  37. cp -a "$WIKI_DIR/." "$TEMP_REPO_DIR"
  38. # Get commit details
  39. author=$(git log -1 --format="%an")
  40. email=$(git log -1 --format="%ae")
  41. message=$(git log -1 --format="%s")
  42. # Changes check
  43. echo "Checking if wiki has changes"
  44. cd "$TEMP_REPO_DIR" || exit
  45. git config --local user.email "$email"
  46. git config --local user.name "$author"
  47. git add .
  48. if git diff-index --quiet HEAD; then
  49. echo "Nothing changed"
  50. exit 0
  51. fi
  52. # Push
  53. echo "Pushing changes to wiki"
  54. git commit -m "$message" && git push "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git"
  55. # Done