Skip to content

Commit 5c0eaa6

Browse files
authored
chore: add local preview make target (#53)
1 parent 73fb38b commit 5c0eaa6

File tree

6 files changed

+56
-19
lines changed

6 files changed

+56
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.vscode
22
*.out
3-
cover.txt
3+
cover-test
44
cover.html
5+
cover.txt

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
1+
LOCAL_COVER_DIR := cover-test
2+
13
.PHONY: release
24
release:
35
git tag -d v1
46
git tag v1 HEAD
57
git push -f origin v1
8+
9+
$(LOCAL_COVER_DIR)/revisions:
10+
@mkdir -p "$(LOCAL_COVER_DIR)/revisions"
11+
12+
$(LOCAL_COVER_DIR)/revisions/local.html: $(LOCAL_COVER_DIR)/revisions
13+
@cd go-test-app-01; make test
14+
@cd go-test-app-01; go tool cover -html=cover.out -o "../$(LOCAL_COVER_DIR)/revisions/local.html"
15+
@cp $(LOCAL_COVER_DIR)/revisions/local.html $(LOCAL_COVER_DIR)/revisions/local-inc.html
16+
@for file in assets/*; do ln -s "$$PWD/$$file" "$(LOCAL_COVER_DIR)/$(shell basename "$$file")"; done
17+
@cd $(LOCAL_COVER_DIR); REVISION=local ../scripts/beautify-html.sh
18+
19+
preview: clean $(LOCAL_COVER_DIR)/revisions/local.html
20+
@echo ""
21+
@echo preview live at: http://localhost:8000?hash=local
22+
@echo " ctrl+c to stop"
23+
@echo ""
24+
@cd $(LOCAL_COVER_DIR); python3 -m http.server 8000 > /dev/null
25+
26+
clean:
27+
@rm -rf "$(LOCAL_COVER_DIR)"
28+
@cd go-test-app-01; make clean

assets/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ body {
8181
transform: translateY(-50%);
8282
pointer-events: none;
8383
font-size: 0.75em;
84+
color: var(--select-color);
8485
}
8586

8687
select {

assets/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ function main() {
3434

3535
configureCodeBlocks()
3636
configureSyntaxHighlight('pre .code .editor')
37-
addCoverageSpans('pre .coverage span')
37+
addCoverageSpans('pre .coverage .editor')
3838
addLineNumbers()
3939

4040
// setup complete, restore the page visibility
4141
document.documentElement.style.setProperty('opacity', '1')
4242
}
4343

4444
function addCoverageSpans(cssSelector) {
45-
let spans = Array.from(document.querySelectorAll(cssSelector))
45+
let spans = Array.from(document.querySelectorAll(`${cssSelector} span`))
4646

4747
spans.forEach((span) => {
4848
let html = span.innerHTML

scripts/beautify-html.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
if [ "${REVISION}" = "local" ]; then
4+
set -eo pipefail
5+
else
6+
set -xeo pipefail
7+
fi
8+
9+
if [ -z "${REVISION}" ]; then
10+
echo "REVISION is not set"
11+
exit 1
12+
fi
13+
14+
# this is useful for browser caching
15+
hash=$(cat index.css index.js | md5sum | awk '{print $1}')
16+
17+
for file in "revisions/${REVISION}.html" "revisions/${REVISION}-inc.html"; do
18+
ex -sc '%s/\n\t\t<style>\_.\{-}<\/style>//' -c 'x' "${file}"
19+
ex -sc '%s/\n\t<script>\_.\{-}<\/script>//' -c 'x' "${file}"
20+
ex -sc '%s/<title>/<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" \/>\r\t\t<title>/' -c 'x' "${file}"
21+
ex -sc '%s/<title>/<meta http-equiv="Pragma" content="no-cache" \/>\r\t\t<title>/' -c 'x' "${file}"
22+
ex -sc '%s/<title>/<meta http-equiv="Expires" content="0" \/>\r\t\t<title>/' -c 'x' "${file}"
23+
ex -sc '%s/<\/title>/<\/title>\r\t\t<script src="..\/index.js?'"${hash}"'"><\/script>/' -c 'x' "${file}"
24+
done

scripts/push.sh

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,20 @@ cp cover.out "${cover_dir}/revisions/${REVISION}.out"
2020

2121
echo "mode: set" > incremental.out
2222
# grep exits with 1 if no lines are found, so we need to ignore that
23+
# incremental = cover - head
2324
grep -F -v -x -f "${cover_dir}/head/head.out" cover.out >> incremental.out || true
2425
go tool cover -html=incremental.out -o "${cover_dir}/revisions/${REVISION}-inc.html"
2526
go tool cover -func=incremental.out -o "${cover_dir}/revisions/${REVISION}-inc.txt"
2627
cp incremental.out "${cover_dir}/revisions/${REVISION}-inc.out"
2728

2829
cd "${cover_dir}"
2930

30-
# copy assets
31+
# prepare assets
3132

3233
cp "${GITHUB_ACTION_PATH}"/assets/* .
34+
"${GITHUB_ACTION_PATH}"/scripts/beautify-html.sh
3335

34-
# beautify html
35-
36-
# this is useful for browser caching
37-
hash=$(cat index.css index.js | md5sum | awk '{print $1}')
38-
39-
for file in "revisions/${REVISION}.html" "revisions/${REVISION}-inc.html"; do
40-
ex -sc '%s/\n\t\t<style>\_.\{-}<\/style>//' -c 'x' "${file}"
41-
ex -sc '%s/\n\t<script>\_.\{-}<\/script>//' -c 'x' "${file}"
42-
ex -sc '%s/<title>/<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" \/>\r\t\t<title>/' -c 'x' "${file}"
43-
ex -sc '%s/<title>/<meta http-equiv="Pragma" content="no-cache" \/>\r\t\t<title>/' -c 'x' "${file}"
44-
ex -sc '%s/<title>/<meta http-equiv="Expires" content="0" \/>\r\t\t<title>/' -c 'x' "${file}"
45-
ex -sc '%s/<\/title>/<\/title>\r\t\t<script src="..\/index.js?'"${hash}"'"><\/script>/' -c 'x' "${file}"
46-
done
47-
48-
# if we are on the main branch, copy files to main.*
36+
# if we are on the main branch, copy files to head.*
4937

5038
if [ "${REF_NAME}" = "main" ]; then
5139
cp "revisions/${REVISION}.html" "${cover_dir}/head/head.html"

0 commit comments

Comments
 (0)