From a61055939e4e6cb03b69029bf75151c90c089934 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 3 Sep 2020 10:55:10 +0200 Subject: [PATCH] Changed wiki deploy script to include subdirectories (#87) Co-authored-by: Henry Pauli --- .github/deploy_wiki.sh | 76 ++++++++++++++++++++++++++++++ .github/workflows/publish_wiki.yml | 9 ++-- 2 files changed, 79 insertions(+), 6 deletions(-) create mode 100755 .github/deploy_wiki.sh diff --git a/.github/deploy_wiki.sh b/.github/deploy_wiki.sh new file mode 100755 index 000000000..c0d0fe090 --- /dev/null +++ b/.github/deploy_wiki.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +function debug() { + echo "::debug file=${BASH_SOURCE[0]},line=${BASH_LINENO[0]}::$1" +} + +function warning() { + echo "::warning file=${BASH_SOURCE[0]},line=${BASH_LINENO[0]}::$1" +} + +function error() { + echo "::error file=${BASH_SOURCE[0]},line=${BASH_LINENO[0]}::$1" +} + +function add_mask() { + echo "::add-mask::$1" +} + +if [ -z "$GITHUB_ACTOR" ]; then + error "GITHUB_ACTOR environment variable is not set" + exit 1 +fi + +if [ -z "$GITHUB_REPOSITORY" ]; then + error "GITHUB_REPOSITORY environment variable is not set" + exit 1 +fi + +if [ -z "$GH_PERSONAL_ACCESS_TOKEN" ]; then + error "GH_PERSONAL_ACCESS_TOKEN environment variable is not set" + exit 1 +fi + +if [ -z "$WIKI_PATH" ]; then + echo "WIKI_PATH environment variable is not set" + exit 1 +fi + +add_mask "${GH_PERSONAL_ACCESS_TOKEN}" + +if [ -z "${WIKI_COMMIT_MESSAGE:-}" ]; then + debug "WIKI_COMMIT_MESSAGE not set, using default" + WIKI_COMMIT_MESSAGE='Automatically publish wiki' +fi + +GIT_REPOSITORY_URL="https://${GH_PERSONAL_ACCESS_TOKEN}@github.com/$GITHUB_REPOSITORY.wiki.git" + +debug "Checking out wiki repository" +tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) +( + cd "$tmp_dir" || exit 1 + git init + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + git pull "$GIT_REPOSITORY_URL" +) + +debug "Rsync contents of $WIKI_PATH" +rsync -q -a --delete "$GITHUB_WORKSPACE/$WIKI_PATH/" "$tmp_dir" + +if [ ! -r "$tmp_dir/Home.md" ]; then + debug "Copy README.md to wiki/Home.md" + rsync -q -a "$GITHUB_WORKSPACE/README.md" "$tmp_dir/Home.md" +fi + +debug "Committing and pushing changes" +( + cd "$tmp_dir" || exit 1 + git add . + git commit -m "$WIKI_COMMIT_MESSAGE" + git push --set-upstream "$GIT_REPOSITORY_URL" master +) + +rm -rf "$tmp_dir" +exit 0 + diff --git a/.github/workflows/publish_wiki.yml b/.github/workflows/publish_wiki.yml index d9bb9f5eb..ddd2af9ea 100644 --- a/.github/workflows/publish_wiki.yml +++ b/.github/workflows/publish_wiki.yml @@ -13,12 +13,9 @@ jobs: steps: - name: Checkout branch uses: actions/checkout@v1 - - name: Copy README.md to wiki/Home.md - run: cp -f README.md wiki/Home.md - - name: Upload to Wiki - uses: SwiftDocOrg/github-wiki-publish-action@v1 - with: - path: "wiki" + - name: Upload Documentation to Wiki + run: bash ./.github/deploy_wiki.sh env: GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + WIKI_PATH: "wiki"