From 94693c92e38ede66020bcd6135d79d8f53325795 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sun, 6 Nov 2022 23:25:11 +0000 Subject: [PATCH] ci(sync wiki): overhaul with bash script --- .github/scripts/sync-wiki.sh | 43 ++++++++++++++++++++++++++++++++++++ .github/workflows/wiki.yml | 11 +++------ 2 files changed, 46 insertions(+), 8 deletions(-) create mode 100755 .github/scripts/sync-wiki.sh diff --git a/.github/scripts/sync-wiki.sh b/.github/scripts/sync-wiki.sh new file mode 100755 index 0000000..4041edb --- /dev/null +++ b/.github/scripts/sync-wiki.sh @@ -0,0 +1,43 @@ +#!/bin/sh +set -eu + +TEMP_REPO_DIR="wiki_action_$GITHUB_REPOSITORY$GITHUB_SHA" +TEMP_WIKI_DIR="temp_wiki_$GITHUB_SHA" + +WIKI_DIR='docs' + +if [ -z "$GH_TOKEN" ]; then + echo "Token is not specified" + exit 1 +fi + +#Clone repo +echo "Cloning repo https://github.com/$GITHUB_REPOSITORY" +git clone "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY" "$TEMP_REPO_DIR" + +#Clone wiki repo +echo "Cloning wiki repo https://github.com/$GITHUB_REPOSITORY.wiki.git" +cd "$TEMP_REPO_DIR" +git clone "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git" "$TEMP_WIKI_DIR" + +#Get commit details +author='Jake Stanger' +email='mail@jstanger.dev' +message='action: sync wiki' + +echo "Copying edited wiki" +cp -R "$TEMP_WIKI_DIR/.git" "$WIKI_DIR/" + +echo "Checking if wiki has changes" +cd "$WIKI_DIR" +git config --local user.email "$email" +git config --local user.name "$author" +git add . + +if git diff-index --quiet HEAD; then + echo "Nothing changed" + exit 0 +fi + +echo "Pushing changes to wiki" +git commit -m "$message" && git push "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git" \ No newline at end of file diff --git a/.github/workflows/wiki.yml b/.github/workflows/wiki.yml index e88ffb9..0dd4a70 100644 --- a/.github/workflows/wiki.yml +++ b/.github/workflows/wiki.yml @@ -12,11 +12,6 @@ jobs: - uses: actions/checkout@v3 - name: Sync Wiki - uses: joeizzard/action-wiki-sync@master - with: - username: JakeStanger - access_token: ${{ secrets.GITHUB_TOKEN }} - wiki_folder: docs - commit_username: 'Jake Stanger' - commit_email: 'mail@jstanger.dev' - commit_message: 'sync wiki from main repo' \ No newline at end of file + run: ./.github/scripts/sync-wiki.sh + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}