From b6baebd27a8c4e5bfb4e9bc3f9bd2c80d6ace46e Mon Sep 17 00:00:00 2001 From: anton Date: Sat, 8 Jun 2024 00:02:57 +0200 Subject: [PATCH] FAIRSPC-87: added workflow to Build and deploy docs to Github Pages and fixed table in doc --- .github/workflows/build_and_deploy_docs.yaml | 72 ++++++++++++++++++-- docs/deploy.sh | 18 ----- docs/{ => scripts}/build.sh | 10 ++- docs/scripts/deploy.sh | 40 +++++++++++ 4 files changed, 116 insertions(+), 24 deletions(-) delete mode 100755 docs/deploy.sh rename docs/{ => scripts}/build.sh (73%) create mode 100755 docs/scripts/deploy.sh diff --git a/.github/workflows/build_and_deploy_docs.yaml b/.github/workflows/build_and_deploy_docs.yaml index 8af7555c7c..fa45b84e73 100644 --- a/.github/workflows/build_and_deploy_docs.yaml +++ b/.github/workflows/build_and_deploy_docs.yaml @@ -25,15 +25,79 @@ jobs: with: ruby-version: '2.7' - - name: Install Asciidoctor + - name: Install Asciidoctor to build docs run: | gem install asciidoctor gem install asciidoctor-pdf gem install rouge - - name: Run Build Docs script - run: ./docs/build.sh + - name: Build Docs - Collect needed files + run: | + PROJECT_FILES=( + "projects/saturn/src/main/resources/log4j2.properties" + "projects/saturn/src/main/resources/system-vocabulary.ttl" + "projects/saturn/taxonomies.ttl" + "projects/saturn/views.yaml" + "projects/saturn/vocabulary.ttl" + ) + BUILD_DIR=./docs/build + version=$(cat VERSION) + + mkdir -p $BUILD_DIR/docs + cp ./README.adoc $BUILD_DIR + sed -i -e "s/VERSION/${version}/" $BUILD_DIR/README.adoc + cp -r ./docs/images $BUILD_DIR/docs/ + for f in ${PROJECT_FILES[*]}; do + mkdir -p "$BUILD_DIR/$(dirname "$f")" + cp "$f" "$BUILD_DIR/"$(dirname "$f")"" + done + + - name: Build Docs - Generate PDF and HTML + run: | + BUILD_DIR=./docs/build + asciidoctor-pdf -a pdf-theme=./docs/pdf-theme.yml -o $BUILD_DIR/Fairspace.pdf $BUILD_DIR/README.adoc || { + echo "Error building PDF" + popd + exit 1 + } + asciidoctor -a toc=left -D $BUILD_DIR/ -o index.html $BUILD_DIR/README.adoc || { + echo "Error building site" + popd + exit 1 + } + rm $BUILD_DIR/README.adoc - name: Run Deploy Docs script - run: ./docs/deploy.sh + env: + CI_SERVICE_ACCOUNT_USER: ${{ secrets.CI_SERVICE_ACCOUNT_USER }} + CI_SERVICE_ACCOUNT_PASSWORD: ${{ secrets.FNS_PAT }} + DOCUMENTATION_REPO: ${{ vars.DOCUMENTATION_REPO }} + run: | + DOCS_REPO="https://${CI_SERVICE_ACCOUNT_USER}:${CI_SERVICE_ACCOUNT_PASSWORD}@github.com/thehyve/${DOCUMENTATION_REPO}" + echo "Cloning documentation repository ${DOCUMENTATION_REPO} ..." + git clone --branch main "${DOCS_REPO}" fairspace-docs + + DOCS_DIR=$(pwd)/fairspace-docs + echo "Copying documentation to ${DOCS_DIR} ..." + cp -r ./docs/build/* "${DOCS_DIR}/" + cd "${DOCS_DIR}" + + if [ ! "$(git status -s)" == "" ]; then + echo "Committing and pushing changes to ${DOCUMENTATION_REPO} ..." + git config --global user.email "${CI_SERVICE_ACCOUNT_USER}@thehyve.nl" + git config --global user.name "${CI_SERVICE_ACCOUNT_USER}" + git add . + git commit -a -m "Update documentation" + git push "${DOCS_REPO}" main + else + echo "Documentation unchanged." + fi + +# +# - name: Run Deploy Docs script +# env: +# CI_SERVICE_ACCOUNT_USER: ${{ secrets.CI_SERVICE_ACCOUNT_USER }} +# CI_SERVICE_ACCOUNT_PASSWORD: ${{ secrets.FNS_PAT }} +# DOCUMENTATION_REPO: ${{ vars.DOCUMENTATION_REPO }} +# run: ./docs/scripts/deploy.sh diff --git a/docs/deploy.sh b/docs/deploy.sh deleted file mode 100755 index afbc8f1699..0000000000 --- a/docs/deploy.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -cd .. -git clone "https://${CI_SERVICE_ACCOUNT_USER}:${CI_SERVICE_ACCOUNT_PASSWORD}@github.com/${DOCUMENTATION_REPO}" fairspace-docs -export DOCS_DIR=$(pwd)/fairspace-docs - -cp -r ./fairspace/docs/build/* "${DOCS_DIR}/" - -pushd "${DOCS_DIR}" -if [ ! "$(git status -s)" == "" ]; then - echo "Committing changes to ${DOCUMENTATION_REPO} ..." - git add . - git commit -a -m "Update from the documentation branch of ${TRAVIS_REPO_SLUG}." - git push "https://${GITHUB_USERNAME}:${GITHUB_PASSWORD}@github.com/${DOCUMENTATION_REPO}" main -else - echo "Documentation unchanged." -fi -popd diff --git a/docs/build.sh b/docs/scripts/build.sh similarity index 73% rename from docs/build.sh rename to docs/scripts/build.sh index b8356ac207..baffc87d63 100755 --- a/docs/build.sh +++ b/docs/scripts/build.sh @@ -1,4 +1,6 @@ #!/usr/bin/env bash +# the script builds the documentation and saves it to the build directory to be deployed by the deploy.sh script +set -e PROJECT_FILES=( "projects/saturn/src/main/resources/log4j2.properties" @@ -8,9 +10,13 @@ PROJECT_FILES=( "projects/saturn/vocabulary.ttl" ) - +# Set working directory +# Get the directory where the script is located here=$(dirname "${0}") -pushd "${here}" +# Move one level up from the script's directory +parent_dir=$(cd "${here}/.." && pwd) +pushd "${parent_dir}" + version=$(cat ../VERSION) mkdir -p build/docs cp ../README.adoc build/ diff --git a/docs/scripts/deploy.sh b/docs/scripts/deploy.sh new file mode 100755 index 0000000000..2487e9f536 --- /dev/null +++ b/docs/scripts/deploy.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# the script pulls the documentation repository, copies the built documentation to the repository, commits and pushes the changes +# the documentation repository is configured to deploy the documentation to the GitHub Pages on push to the main branch +set -e + +# Set working directory +# Get the directory where the script is located +here=$(dirname "${0}") +echo "Script directory: ${here}" +pwd +# Move two levels up from the script's directory +parent_dir=$(cd "${here}/../.." && pwd) +pushd "${parent_dir}" +echo "Working directory: ${parent_dir}" + +export DOCS_REPO="https://${CI_SERVICE_ACCOUNT_USER}:${CI_SERVICE_ACCOUNT_PASSWORD}@github.com/thehyve/${DOCUMENTATION_REPO}" +echo "Cloning documentation repository ${DOCS_REPO} ..." +pwd +git clone --branch main "${DOCS_REPO}" fairspace-docs +echo "Cloning done." +pwd +git config --global user.email "ci_fairspace@thehyve.nl" +git config --global user.name "${CI_SERVICE_ACCOUNT_USER}" +export DOCS_DIR=$(pwd)/fairspace-docs + +echo "Copying documentation to ${DOCS_DIR} ..." +pwd +ls +cp -r ./fairspace/docs/build/* "${DOCS_DIR}/" + +pushd "${DOCS_DIR}" +if [ ! "$(git status -s)" == "" ]; then + echo "Committing changes to ${DOCUMENTATION_REPO} ..." + git add . + git commit -a -m "Update documentation" + git push "${DOCS_REPO}" main +else + echo "Documentation unchanged." +fi +popd