From dc6e53d806b779f5251cc76a984e1b27c6f23246 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Tue, 24 Sep 2024 09:00:12 +0200 Subject: [PATCH] Replace place holders when publishing to readthedocs --- .readthedocs.yaml | 3 +++ docs/prebuild.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 docs/prebuild.sh diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 3306c6ce4..945e7efc7 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,6 +9,9 @@ build: os: ubuntu-20.04 tools: python: "3.9" + jobs: + pre_build: + - bash docs/prebuild.sh # Build documentation in the docs/ directory with Sphinx sphinx: diff --git a/docs/prebuild.sh b/docs/prebuild.sh new file mode 100755 index 000000000..48c8de6ec --- /dev/null +++ b/docs/prebuild.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# +# Replace place holders for http_archive attrs for rules_haskell with actual values +# + +function die() { + echo "error: $*" + exit 1 +} >&2 + +set -euo pipefail || die "cannot set options" + +function get_sha256() { + curl -L "$1" | python -uc 'import hashlib, sys; print(hashlib.sha256(sys.stdin.buffer.read()).hexdigest())' +} + +if [[ "${READTHEDOCS_VERSION_TYPE}" == branch && "${READTHEDOCS_VERSION_NAME}" == master ]]; then + # a commit was pushed to the master branch + url="https://github.com/tweag/rules_haskell/archive/${READTHEDOCS_GIT_COMMIT_HASH}.tar.gz" + hash=$( get_sha256 "$url" ) + sed -i \ + -e '/name = "rules_haskell"/,/url = "/{' \ + -e ' s%x\{64\}%'"${hash}"'%; ' \ + -e ' s%/releases/download/vM[.]NN/rules_haskell-%/archive/%' \ + -e ' s%M[.]NN%'"${READTHEDOCS_GIT_COMMIT_HASH}"'%g ' \ + -e '}' \ + docs/haskell-use-cases.rst +elif [[ "${READTHEDOCS_VERSION_TYPE}" == tag && "${READTHEDOCS_GIT_IDENTIFIER}" == v[0-9]* ]]; then + # a version tag was pushed + version="${READTHEDOCS_GIT_IDENTIFIER#v}" + url="https://github.com/tweag/rules_haskell/releases/download/v${version}/rules_haskell-${version}.tar.gz" + hash=$( get_sha256 "$url" ) + + sed -i \ + -e '/name = "rules_haskell"/,/url = "/{' \ + -e ' s%x\{64\}%'"${hash}"'%; ' \ + -e ' s%M[.]NN%'"${version}"'%g ' \ + -e '}' \ + docs/haskell-use-cases.rst +else + die "cannot handle version type ${READTHEDOCS_VERSION_TYPE} / ${READTHEDOCS_VERSION_NAME}" +fi