2
0

update-wiki.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. echo "Copying : $WIKI_DIR -> $TEMP_REPO_DIR"
  29. cp -a "$WIKI_DIR" "$TEMP_REPO_DIR"
  30. # Get commit details
  31. author=$(git log -1 --format="%an")
  32. email=$(git log -1 --format="%ae")
  33. message=$(git log -1 --format="%s")
  34. # Changes check
  35. echo "Checking if wiki has changes"
  36. cd "$TEMP_REPO_DIR" || exit
  37. git config --local user.email "$email"
  38. git config --local user.name "$author"
  39. git add .
  40. if git diff-index --quiet HEAD; then
  41. echo "Nothing changed"
  42. exit 0
  43. fi
  44. # Push
  45. echo "Pushing changes to wiki"
  46. git commit -m "$message" && git push "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git"
  47. # Done