/
publish-csvws-to-github-pages.sh
executable file
·60 lines (51 loc) · 1.54 KB
/
publish-csvws-to-github-pages.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
echo "--Publishing Output to GitHub Pages"
# Fail on errors (and other things)
set -euo pipefail
if [[ "$DEBUG" == true ]]
then
set -x
fi
git checkout gh-pages
# Get the uncommitted changes we've been making to this branch throughout this action.
if [[ -d "$RUNNER_TEMP/out" ]]
then
cp -r "$RUNNER_TEMP/out" .
fi
# Pick up any file deletions stored in the stash
git stash pop || true
repo_name=${GITHUB_REPOSITORY#*/}
username=${GITHUB_REPOSITORY_OWNER}
commit_id=${GITHUB_SHA}
mapfile -t out_files < <(printf '%s\n' $(find out -type f -name '*'))
processed_out_files=$(printf "|||%s" "${out_files[@]}")
touch .nojekyll
touch index.html
cat > index.html <<EOL
<!doctype html>
<html>
<head>
</head>
<body>
<h3>CSV-Ws generated are as below. The latest commit id is ${commit_id}.</h3>
<div id="files-container"></div>
<script type="text/javascript">
var html_str = "<ul>";
var files = "${processed_out_files}".split('|||');
files.shift()
files.sort()
files.forEach(function(file) {
file = file.replace("./","")
link = "https://${username}.github.io/${repo_name}/"+file
html_str += "<li>"+"<a href='"+ link + "'>"+file+"</a></li>";
});
html_str += "</ul>";
document.getElementById("files-container").innerHTML = html_str;
</script>
</body>
</html>
EOL
git add .nojekyll
git add index.html
git add out/
git commit -a -m "Updating outputs in GitHub Pages - $(date +'%d-%m-%Y at %H:%M:%S')"
git push --set-upstream origin gh-pages -f