Jaypore CI

> Jaypore CI: Minimal, Offline, Local CI system.
Log | Files | Refs | README | LICENSE

build_site.sh (2489B)


      1 #!/usr/bin/env bash
      2 
      3 # Runs INSIDE the container.
      4 # The host repo is mounted at /tmp/repo (read-write).
      5 # Generated site is written to /tmp/repo/www_jci/public/releases.
      6 set -euo pipefail
      7 
      8 export REPO_DIR="/tmp/Jaypore CI"
      9 export PUBLIC_DIR="${REPO_DIR}/www_jci/public"
     10 export BUILD_DIR="/build"
     11 export RELEASES_DIR="${PUBLIC_DIR}/releases"
     12 export ASSETS_DIR="${PUBLIC_DIR}/assets"
     13 cd "$REPO_DIR"
     14 
     15 echo "==============="
     16 env
     17 echo "==============="
     18 
     19 # Ensure output directory exists
     20 mkdir -p "${RELEASES_DIR}"
     21 mkdir -p "${BUILD_DIR}"
     22 
     23 # Build a description line from the repo README for stagit
     24 (
     25   cd "${REPO_DIR}"
     26   head README.md | grep '>' > description 2>/dev/null || echo "jci" > description
     27 )
     28 
     29 # Regenerate the README table of contents before building the site
     30 echo "Regenerating README table of contents..."
     31 bash "${REPO_DIR}/scripts/generate_readme_index.sh" "${REPO_DIR}/README.md"
     32 
     33 cp -r "${REPO_DIR}/bin" "${REPO_DIR}/binaries"
     34 cp -r "${REPO_DIR}/bin" "${PUBLIC_DIR}/binaries"
     35 (cd "${BUILD_DIR}" && pwd && stagit -u /releases/git "${REPO_DIR}")
     36 cp -r "${BUILD_DIR}/." "${RELEASES_DIR}"
     37 
     38 # Render README.md to HTML and replace the stagit-generated content
     39 README_SRC="${REPO_DIR}/README.md"
     40 README_DST="${RELEASES_DIR}/file/README.md.html"
     41 if [[ -f "${README_SRC}" && -f "${README_DST}" ]]; then
     42   echo "Rendering README.md to HTML via lowdown..."
     43   README_RENDERED="$(mktemp)"
     44   lowdown -o "${README_RENDERED}" "${README_SRC}"
     45   echo "Injecting rendered README into ${README_DST}"
     46   README_TMP_OUTPUT="$(mktemp)"
     47   awk -v rendered="${README_RENDERED}" '
     48 BEGIN {
     49   in_content = 0
     50   inserted = 0
     51 }
     52 {
     53   if (!inserted && $0 ~ /<div id="content">/) {
     54     print
     55     while ((getline line < rendered) > 0) {
     56       print line
     57     }
     58     close(rendered)
     59     in_content = 1
     60     inserted = 1
     61     next
     62   }
     63   if (in_content) {
     64     if ($0 ~ /<\/div>/) {
     65       print $0
     66       in_content = 0
     67     }
     68     next
     69   }
     70   print
     71 }
     72 END {
     73   if (!inserted) {
     74     print "Failed to inject rendered README: <div id=\"content\"> not found" > "/dev/stderr"
     75     exit 1
     76   }
     77 }
     78 ' "${README_DST}" > "${README_TMP_OUTPUT}"
     79   mv "${README_TMP_OUTPUT}" "${README_DST}"
     80   rm -f "${README_RENDERED}"
     81 fi
     82 
     83 # Clean up the temporary description file
     84 rm -f "${REPO_DIR}/description"
     85 rm -rf "${REPO_DIR}/binaries"
     86 
     87 cp "${ASSETS_DIR}/git.style.css" "${RELEASES_DIR}/style.css"
     88 cp "${ASSETS_DIR}/logo.png" "${RELEASES_DIR}/logo.png"
     89 cp "${ASSETS_DIR}/logo.png" "${RELEASES_DIR}/favicon.png"
     90 
     91 echo "Site generated at ${RELEASES_DIR}"