|
4 | 4 |
|
5 | 5 | set -eo pipefail
|
6 | 6 |
|
7 |
| -# git_repo_root=$(git rev-parse --show-toplevel) |
8 |
| -# site_src="${git_repo_root}/_site" |
9 |
| -# gh_pages_root="${git_repo_root}/docs" |
10 |
| - |
11 |
| -# # Site built from the main branch will be available at 'https://<domain_name>/'. |
12 |
| -# # Sites built from other branchs will be available at 'https://<domain_name>/branches/<branch_name>'. |
13 |
| -# main_git_branch="hakyll" |
14 |
| - |
15 |
| -# # replace "/", "#", etc with "-". |
16 |
| -# slugify() { |
17 |
| -# echo "$1" | iconv -c -t ascii//TRANSLIT | sed -E 's/[~^]+/-/g' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+|-+$/-/g' | tr A-Z a-z |
18 |
| -# } |
19 |
| - |
20 |
| -# if [[ ! -z "$GITHUB_ACTIONS" ]]; then |
21 |
| -# git_branch=$(slugify "$GITHUB_REF_NAME") |
22 |
| -# else |
23 |
| -# git_branch=$(slugify $(git branch --show-current)) |
24 |
| -# fi |
25 |
| -# echo "Current git branch is '${git_branch}'." |
26 |
| - |
27 |
| -# git config user.name github-actions |
28 |
| -# git config user.email [email protected] |
29 |
| - |
30 |
| -# git checkout gh-pages |
31 |
| -# git pull origin gh-pages |
32 |
| - |
33 |
| -# if [ "$git_branch" == "$main_git_branch" ]; then |
34 |
| -# site_dest="${gh_pages_root}" |
35 |
| - |
36 |
| -# # Create temporary backup for other branches content. |
37 |
| -# mv "${gh_pages_root}/branches" . |
38 |
| - |
39 |
| -# # Replace site files. |
40 |
| -# rm -rf "${site_dest}" |
41 |
| -# mkdir -p "${site_dest}" |
42 |
| -# cp -a -v ${site_src}/* ${site_dest}/ |
43 |
| - |
44 |
| -# # Restore temporary backup for other branches content. |
45 |
| -# mv ./branches "${gh_pages_root}/" |
46 |
| -# else |
47 |
| -# site_dest="${gh_pages_root}/branches/${git_branch}" |
48 |
| - |
49 |
| -# # Replace site files. |
50 |
| -# rm -rf "${site_dest}" |
51 |
| -# mkdir -p "${site_dest}" |
52 |
| -# cp -a -v ${site_src}/* ${site_dest}/ |
53 |
| -# fi |
54 |
| - |
55 |
| -# echo "Updating gh-pages branch." |
56 |
| -# git add --all |
57 |
| -# git commit --allow-empty -m "[$(date '+%F %T %Z')] Updated site for the '${git_branch}' branch [ci skip]" |
58 |
| -# git push --force origin gh-pages |
59 |
| -# echo "Deployment finished." |
60 |
| - |
61 |
| -# echo "Publishing an URL to the deployment. It will be visible as a link at GitHub in the red/green commit checks, near CI jobs result." |
62 |
| -# if [[ -z GITHUB_TOKEN ]]; then |
63 |
| -# echo "GITHUB_TOKEN env variable must be provided." |
64 |
| -# exit 1 |
65 |
| -# fi |
| 7 | +git_repo_root=$(git rev-parse --show-toplevel) |
| 8 | +site_src="${git_repo_root}/_site" |
| 9 | +gh_pages_root="${git_repo_root}/docs" |
| 10 | + |
| 11 | +# Site built from the main branch will be available at 'https://<domain_name>/'. |
| 12 | +# Sites built from other branchs will be available at 'https://<domain_name>/branches/<branch_name>'. |
| 13 | +main_git_branch="hakyll" |
| 14 | + |
| 15 | +# replace "/", "#", etc with "-". |
| 16 | +slugify() { |
| 17 | + echo "$1" | iconv -c -t ascii//TRANSLIT | sed -E 's/[~^]+/-/g' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+|-+$/-/g' | tr A-Z a-z |
| 18 | +} |
| 19 | + |
| 20 | +if [[ ! -z "$GITHUB_ACTIONS" ]]; then |
| 21 | + git_branch=$(slugify "$GITHUB_REF_NAME") |
| 22 | +else |
| 23 | + git_branch=$(slugify $(git branch --show-current)) |
| 24 | +fi |
| 25 | +echo "Current git branch is '${git_branch}'." |
| 26 | + |
| 27 | +git config user.name github-actions |
| 28 | +git config user.email [email protected] |
| 29 | + |
| 30 | +git checkout gh-pages |
| 31 | +git pull origin gh-pages |
| 32 | + |
| 33 | +if [ "$git_branch" == "$main_git_branch" ]; then |
| 34 | + site_dest="${gh_pages_root}" |
| 35 | + |
| 36 | + # Create temporary backup for other branches content. |
| 37 | + mv "${gh_pages_root}/branches" . |
| 38 | + |
| 39 | + # Replace site files. |
| 40 | + rm -rf "${site_dest}" |
| 41 | + mkdir -p "${site_dest}" |
| 42 | + cp -a -v ${site_src}/* ${site_dest}/ |
| 43 | + |
| 44 | + # Restore temporary backup for other branches content. |
| 45 | + mv ./branches "${gh_pages_root}/" |
| 46 | +else |
| 47 | + site_dest="${gh_pages_root}/branches/${git_branch}" |
| 48 | + |
| 49 | + # Replace site files. |
| 50 | + rm -rf "${site_dest}" |
| 51 | + mkdir -p "${site_dest}" |
| 52 | + cp -a -v ${site_src}/* ${site_dest}/ |
| 53 | +fi |
| 54 | + |
| 55 | +echo "Updating gh-pages branch." |
| 56 | +git add --all |
| 57 | +git commit --allow-empty -m "[$(date '+%F %T %Z')] Updated site for the '${git_branch}' branch [ci skip]" |
| 58 | +git push --force origin gh-pages |
| 59 | +echo "Deployment finished." |
| 60 | + |
| 61 | +echo "Publishing an URL to the deployment. It will be visible as a link at GitHub in the red/green commit checks, near CI jobs result." |
| 62 | +if [[ -z GITHUB_TOKEN ]]; then |
| 63 | + echo "GITHUB_TOKEN env variable must be provided." |
| 64 | + exit 1 |
| 65 | +fi |
66 | 66 |
|
67 | 67 | github_project_url=$(git remote get-url origin)
|
68 | 68 | if [[ $github_project_url == [email protected]: * ]] ; then
|
|
0 commit comments