|
| 1 | +#!/usr/bin/env sh |
| 2 | +# |
| 3 | +# Copyright (C) 2021-2024 The ESPResSo project |
| 4 | +# |
| 5 | +# This file is part of ESPResSo. |
| 6 | +# |
| 7 | +# ESPResSo is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU General Public License as published by |
| 9 | +# the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# ESPResSo is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License |
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | +# |
| 20 | + |
| 21 | +set -e # exit on first non-zero return code |
| 22 | +set -x # print each command line before executing it |
| 23 | + |
| 24 | +if [ ! "${GITHUB_ACTIONS}" = "true" ]; then |
| 25 | + echo "This script is meant to be executed by a GitHub Actions workflow"; |
| 26 | + exit 1; |
| 27 | +fi |
| 28 | + |
| 29 | +# checkout GitHub pages |
| 30 | +cd "${HOME}" |
| 31 | +git clone --quiet git@github.com:espressomd/espressomd.github.io.git |
| 32 | +cd espressomd.github.io |
| 33 | + |
| 34 | +# check if already up-to-date (i.e. the commit SHA of the |
| 35 | +# generated docs is identical to the current commit SHA) |
| 36 | +LAST_COMMIT=$(git log -1 --pretty='format:"%s"' remotes/origin/main) |
| 37 | +NEXT_COMMIT="Documentation for ${GITHUB_SHA}" |
| 38 | +if [ "${NEXT_COMMIT}" = "${LAST_COMMIT}" ]; then |
| 39 | + echo "Documentation already up-to-date."; |
| 40 | + exit 0; |
| 41 | +fi |
| 42 | + |
| 43 | +# download artifacts |
| 44 | +gitlab_rest_api_get() { |
| 45 | + # shellcheck disable=SC2068 |
| 46 | + curl --fail --location --request GET --header "PRIVATE-TOKEN: ${GITLAB_READ_API}" $@ |
| 47 | +} |
| 48 | +rest_api="https://gitlab.icp.uni-stuttgart.de/api/v4" |
| 49 | +project_id=390 |
| 50 | +# get the status of the most recent CI pipelines |
| 51 | +gitlab_rest_api_get --silent "${rest_api}/projects/${project_id}/pipelines?per_page=60" > pipelines.json |
| 52 | +# get the most recent successful nightly build (where tutorials are available) |
| 53 | +# and the most recent successful build (where sphinx and doxygen are available) |
| 54 | +pipeline_sched_id=$(jq '[ .[] | select(.ref=="python" and .status=="success" and .source=="schedule") ][0].id' pipelines.json) |
| 55 | +pipeline_merge_id=$(jq '[ .[] | select(.ref=="python" and .status=="success") ][0].id' pipelines.json) |
| 56 | +gitlab_rest_api_get --silent "${rest_api}/projects/${project_id}/pipelines/${pipeline_sched_id}/jobs?per_page=100" > jobs_scheduled_pipeline.json |
| 57 | +gitlab_rest_api_get --silent "${rest_api}/projects/${project_id}/pipelines/${pipeline_merge_id}/jobs?per_page=100" > jobs_branch_head_pipeline.json |
| 58 | +# get the tutorial, sphinx, and doxygen CI job ids and download their artifacts |
| 59 | +tutorial_job_id=$(jq '.[] | select(.name=="run_tutorials").id' jobs_scheduled_pipeline.json) |
| 60 | +doxygen_job_id=$(jq '.[] | select(.name=="run_doxygen").id' jobs_branch_head_pipeline.json) |
| 61 | +sphinx_job_id=$(jq '.[] | select(.name=="check_sphinx").id' jobs_branch_head_pipeline.json) |
| 62 | +gitlab_rest_api_get --output tutorials.zip "${rest_api}/projects/${project_id}/jobs/${tutorial_job_id}/artifacts" |
| 63 | +gitlab_rest_api_get --output doxygen.zip "${rest_api}/projects/${project_id}/jobs/${doxygen_job_id}/artifacts" |
| 64 | +gitlab_rest_api_get --output sphinx.zip "${rest_api}/projects/${project_id}/jobs/${sphinx_job_id}/artifacts" |
| 65 | +if grep -F '<!DOCTYPE html>' ./*.zip; then |
| 66 | + echo "The artifacts could not be downloaded."; |
| 67 | + exit 1; |
| 68 | +fi |
| 69 | +unzip -q "*.zip" |
| 70 | + |
| 71 | +# create a fresh main branch containing the docs of old releases |
| 72 | +git config --global user.email "noreply@icp.uni-stuttgart.de" |
| 73 | +git config --global user.name "espresso-ci" |
| 74 | +git checkout -b new_main remotes/origin/releases |
| 75 | + |
| 76 | +# generate the landing page by merging the branch containing the |
| 77 | +# HTML theme and Markdown files, then convert them to HTML files |
| 78 | +git merge --quiet --commit --no-edit --allow-unrelated-histories remotes/origin/landing_page |
| 79 | +make tutorials.md |
| 80 | +make videos.md |
| 81 | +for filename in *.md; do |
| 82 | + make "${filename%.md}.html"; |
| 83 | +done |
| 84 | +rm ./*_header.html |
| 85 | +git add ./*.html |
| 86 | +git clean -f |
| 87 | +git rm ./*.md ./*.py Makefile |
| 88 | +git commit --quiet -m "Generate landing page" |
| 89 | + |
| 90 | +# add devel documentation |
| 91 | +rsync -a --delete --exclude="*.md5" --exclude="*.map" "build/doc/doxygen/html/" dox/ |
| 92 | +rsync -a --delete --exclude=".buildinfo" "build/doc/sphinx/html/" doc/ |
| 93 | +rsync -a --delete "build/doc/tutorials/html/" tutorials/ |
| 94 | +git add doc dox tutorials |
| 95 | +git commit --quiet -m "${NEXT_COMMIT}" |
| 96 | + |
| 97 | +# deploy |
| 98 | +git push -f origin new_main:main |
0 commit comments