Skip to content

Commit dc6e53d

Browse files
committed
Replace place holders when publishing to readthedocs
1 parent a361943 commit dc6e53d

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

.readthedocs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ build:
99
os: ubuntu-20.04
1010
tools:
1111
python: "3.9"
12+
jobs:
13+
pre_build:
14+
- bash docs/prebuild.sh
1215

1316
# Build documentation in the docs/ directory with Sphinx
1417
sphinx:

docs/prebuild.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Replace place holders for http_archive attrs for rules_haskell with actual values
4+
#
5+
6+
function die() {
7+
echo "error: $*"
8+
exit 1
9+
} >&2
10+
11+
set -euo pipefail || die "cannot set options"
12+
13+
function get_sha256() {
14+
curl -L "$1" | python -uc 'import hashlib, sys; print(hashlib.sha256(sys.stdin.buffer.read()).hexdigest())'
15+
}
16+
17+
if [[ "${READTHEDOCS_VERSION_TYPE}" == branch && "${READTHEDOCS_VERSION_NAME}" == master ]]; then
18+
# a commit was pushed to the master branch
19+
url="https://github.com/tweag/rules_haskell/archive/${READTHEDOCS_GIT_COMMIT_HASH}.tar.gz"
20+
hash=$( get_sha256 "$url" )
21+
sed -i \
22+
-e '/name = "rules_haskell"/,/url = "/{' \
23+
-e ' s%x\{64\}%'"${hash}"'%; ' \
24+
-e ' s%/releases/download/vM[.]NN/rules_haskell-%/archive/%' \
25+
-e ' s%M[.]NN%'"${READTHEDOCS_GIT_COMMIT_HASH}"'%g ' \
26+
-e '}' \
27+
docs/haskell-use-cases.rst
28+
elif [[ "${READTHEDOCS_VERSION_TYPE}" == tag && "${READTHEDOCS_GIT_IDENTIFIER}" == v[0-9]* ]]; then
29+
# a version tag was pushed
30+
version="${READTHEDOCS_GIT_IDENTIFIER#v}"
31+
url="https://github.com/tweag/rules_haskell/releases/download/v${version}/rules_haskell-${version}.tar.gz"
32+
hash=$( get_sha256 "$url" )
33+
34+
sed -i \
35+
-e '/name = "rules_haskell"/,/url = "/{' \
36+
-e ' s%x\{64\}%'"${hash}"'%; ' \
37+
-e ' s%M[.]NN%'"${version}"'%g ' \
38+
-e '}' \
39+
docs/haskell-use-cases.rst
40+
else
41+
die "cannot handle version type ${READTHEDOCS_VERSION_TYPE} / ${READTHEDOCS_VERSION_NAME}"
42+
fi

0 commit comments

Comments
 (0)