build_site.sh (2297B)
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 cp -r "${REPO_DIR}/bin" "${REPO_DIR}/binaries" 30 cp -r "${REPO_DIR}/bin" "${PUBLIC_DIR}/binaries" 31 (cd "${BUILD_DIR}" && pwd && stagit -u /releases/git "${REPO_DIR}") 32 cp -r "${BUILD_DIR}/." "${RELEASES_DIR}" 33 34 # Render README.md to HTML and replace the stagit-generated content 35 README_SRC="${REPO_DIR}/README.md" 36 README_DST="${RELEASES_DIR}/file/README.md.html" 37 if [[ -f "${README_SRC}" && -f "${README_DST}" ]]; then 38 echo "Rendering README.md to HTML via lowdown..." 39 README_RENDERED="$(mktemp)" 40 lowdown -o "${README_RENDERED}" "${README_SRC}" 41 echo "Injecting rendered README into ${README_DST}" 42 README_TMP_OUTPUT="$(mktemp)" 43 awk -v rendered="${README_RENDERED}" ' 44 BEGIN { 45 in_content = 0 46 inserted = 0 47 } 48 { 49 if (!inserted && $0 ~ /<div id="content">/) { 50 print 51 while ((getline line < rendered) > 0) { 52 print line 53 } 54 close(rendered) 55 in_content = 1 56 inserted = 1 57 next 58 } 59 if (in_content) { 60 if ($0 ~ /<\/div>/) { 61 print $0 62 in_content = 0 63 } 64 next 65 } 66 print 67 } 68 END { 69 if (!inserted) { 70 print "Failed to inject rendered README: <div id=\"content\"> not found" > "/dev/stderr" 71 exit 1 72 } 73 } 74 ' "${README_DST}" > "${README_TMP_OUTPUT}" 75 mv "${README_TMP_OUTPUT}" "${README_DST}" 76 rm -f "${README_RENDERED}" 77 fi 78 79 # Clean up the temporary description file 80 rm -f "${REPO_DIR}/description" 81 rm -rf "${REPO_DIR}/binaries" 82 83 cp "${ASSETS_DIR}/git.style.css" "${RELEASES_DIR}/style.css" 84 cp "${ASSETS_DIR}/logo.png" "${RELEASES_DIR}/logo.png" 85 cp "${ASSETS_DIR}/logo.png" "${RELEASES_DIR}/favicon.png" 86 87 echo "Site generated at ${RELEASES_DIR}"