From 1d635d325ddd7be79df4308425c4fae0e2174c3b 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 | 83 +++++++++++++++++--- docs/build.sh | 34 -------- docs/deploy.sh | 18 ----- 3 files changed, 74 insertions(+), 61 deletions(-) delete mode 100755 docs/build.sh delete mode 100755 docs/deploy.sh diff --git a/.github/workflows/build_and_deploy_docs.yaml b/.github/workflows/build_and_deploy_docs.yaml index 8af7555c7c..08448d23e9 100644 --- a/.github/workflows/build_and_deploy_docs.yaml +++ b/.github/workflows/build_and_deploy_docs.yaml @@ -1,5 +1,3 @@ -# This workflow is triggered on any PR's changes - name: Build and deploy docs to Github Pages on: @@ -7,7 +5,6 @@ on: branches: - bugfix/FAIRSPC-87 - jobs: build-saturn: runs-on: ubuntu-latest @@ -23,17 +20,85 @@ jobs: - name: Set up Ruby (required for gem installation) uses: ruby/setup-ruby@v1 with: - ruby-version: '2.7' + ruby-version: '3.3.2' - - 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: | + set -e + + # Initialize variables + 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) + + # Create build directory + mkdir -p $BUILD_DIR/docs + + # Copy all files to the build directory + 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: Run Deploy Docs script - run: ./docs/deploy.sh + - name: Build Docs - Generate PDF and HTML + run: | + set -e + + 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: Deploy Docs (push to Github Pages, will be deployed automatically) + env: + CI_SERVICE_ACCOUNT_USER: ${{ secrets.CI_SERVICE_ACCOUNT_USER }} + CI_SERVICE_ACCOUNT_PASSWORD: ${{ secrets.FNS_PAT }} + DOCS_REPOSITORY_NAME: ${{ vars.DOCS_REPOSITORY_NAME }} + run: | + set -e + + DOCS_REPO_URL="https://${CI_SERVICE_ACCOUNT_USER}:${CI_SERVICE_ACCOUNT_PASSWORD}@github.com/thehyve/${DOCS_REPOSITORY_NAME}" + echo "Cloning documentation repository ${DOCS_REPOSITORY_NAME} ..." + git clone --branch main "${DOCS_REPO_URL}" 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 ${DOCS_REPOSITORY_NAME} ..." + 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_URL}" main + else + echo "Documentation unchanged." + fi diff --git a/docs/build.sh b/docs/build.sh deleted file mode 100755 index b8356ac207..0000000000 --- a/docs/build.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash - -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" -) - - -here=$(dirname "${0}") -pushd "${here}" -version=$(cat ../VERSION) -mkdir -p build/docs -cp ../README.adoc build/ -sed -i -e "s/VERSION/${version}/" build/README.adoc -cp -r images build/docs/ -for f in ${PROJECT_FILES[*]}; do - mkdir -p "build/$(dirname "$f")" - cp "../$f" "build/"$(dirname "$f")"" -done -asciidoctor-pdf -a pdf-theme=pdf-theme.yml -o build/Fairspace.pdf build/README.adoc || { - echo "Error building PDF" - popd - exit 1 -} -asciidoctor -a toc=left -D build/ -o index.html build/README.adoc || { - echo "Error building site" - popd - exit 1 -} -rm build/README.adoc -popd 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