Skip to content

Commit 3d13927

Browse files
committed
haskellfoundation#23 Deploy site for each git branch
1 parent f1134af commit 3d13927

10 files changed

+141
-31
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs.
2+
# More: https://editorconfig.org/
3+
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
charset = utf-8
12+
end_of_line = lf
13+
14+
[Makefile]
15+
indent_style = tab

.github/workflows/deploy.sh

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env bash
2+
3+
# Deploy static site to the GitHub pages.
4+
5+
set -eo pipefail
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+
deploy() {
21+
if [[ ! -z "$GITHUB_REF_NAME" ]]; then
22+
# The GITHUB_REF_NAME env variable is available in github actions.
23+
git_branch=$GITHUB_REF_NAME
24+
else
25+
git_branch=$(git branch --show-current)
26+
fi
27+
echo "Current git branch is '${git_branch}'."
28+
29+
git config user.name github-actions
30+
git config user.email [email protected]
31+
32+
git checkout gh-pages
33+
git pull origin gh-pages
34+
35+
if [ "$git_branch" == "$main_git_branch" ]; then
36+
site_dest="${gh_pages_root}"
37+
38+
# Create temporary backup for other branches content.
39+
mv "${gh_pages_root}/branches" .
40+
41+
# Replace site files.
42+
rm -rf "${site_dest}"
43+
mkdir -p "${site_dest}"
44+
cp -a -v ${site_src}/* ${site_dest}/
45+
46+
# Restore temporary backup for other branches content.
47+
mv ./branches "${gh_pages_root}/"
48+
else
49+
site_dest="${gh_pages_root}/branches/$(slugify ${git_branch})"
50+
51+
# Replace site files.
52+
rm -rf "${site_dest}"
53+
mkdir -p "${site_dest}"
54+
cp -a -v ${site_src}/* ${site_dest}/
55+
fi
56+
57+
echo "Updating gh-pages branch."
58+
git add --all
59+
git commit --allow-empty -m "[$(date '+%F %T %Z')] Updated site for the '${git_branch}' branch [ci skip]"
60+
git push --force origin gh-pages
61+
echo "Deployment finished."
62+
}
63+
64+
update_deployments_list() {
65+
github_project_url=$(git remote get-url origin)
66+
if [[ $github_project_url == [email protected]:* ]]; then
67+
github_repo=$(echo ${github_project_url#"[email protected]:"} | sed 's/\.git$//g')
68+
elif [[ $github_project_url == https://github.com/* ]]; then
69+
github_repo=$(echo ${github_project_url#"https://github.com/"} | sed 's/\.git$//g' | sed 's/^\/\///g')
70+
fi
71+
72+
github_repo_owner=$(echo "${github_repo}" | sed 's/\/.*$//g')
73+
github_repo_name=$(echo "${github_repo}" | sed 's/^.*\///g')
74+
75+
deployments_list="DEPLOYMENTS.md"
76+
echo "Updating ${deployments_list}"
77+
rm $deployments_list
78+
79+
# Create a markdown table
80+
touch $deployments_list
81+
echo "# Deployments" >>$deployments_list
82+
echo "" >>$deployments_list
83+
echo "| Branch | Link |" >>$deployments_list
84+
echo "| --- | --- |" >>$deployments_list
85+
86+
main_deployment_url="https://${github_repo_owner}.github.io/${github_repo_name}/"
87+
echo "| [main](https://github.com/${github_repo_owner}/${github_repo_name}/tree/${branch}) | [Open](${main_deployment_url}) |" >>$deployments_list
88+
89+
remote_branches=$(git ls-remote --heads origin | sed 's?.*refs/heads/??')
90+
echo "$remote_branches" | while IFS= read -r branch; do
91+
safe_branch=$(slugify $branch)
92+
deployment_url="https://${github_repo_owner}.github.io/${github_repo_name}/branches/${safe_branch}"
93+
echo "| [${branch}](https://github.com/${github_repo_owner}/${github_repo_name}/tree/${branch}) | [Open](${deployment_url}) |" >>$deployments_list
94+
done
95+
96+
# Update gh-pages branch
97+
git add --all
98+
git commit --allow-empty -m "Update ${deployments_list}"
99+
git push --force origin gh-pages
100+
}
101+
102+
deploy
103+
update_deployments_list

.github/workflows/main.yml

+10-18
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ name: CI
66
on:
77
# Triggers the workflow on push or pull request events but only for the hakyll branch
88
push:
9-
branches: [ hakyll ]
9+
# branches:
10+
branches-ignore:
11+
- gh-pages
1012
pull_request:
11-
branches: [ hakyll ]
13+
branches-ignore:
14+
- gh-pages
1215

1316
# Allows you to run this workflow manually from the Actions tab
1417
workflow_dispatch:
@@ -48,21 +51,10 @@ jobs:
4851
- name: Build dependencies
4952
run: stack build --system-ghc --only-dependencies
5053

51-
- name: Build site executable
52-
run: stack build --system-ghc
54+
- name: Build
55+
run: |
56+
stack build --system-ghc
57+
stack exec --system-ghc site build
5358
54-
# Runs a set of commands using the runners shell
5559
- name: Deploy
56-
run: |
57-
git config user.name github-actions
58-
git config user.email [email protected]
59-
stack exec --system-ghc site rebuild
60-
git checkout main
61-
git pull --rebase
62-
# Overwrite existing files with new files
63-
cp -a -v _site/. .
64-
# Commit
65-
git add --all
66-
git commit -m "[`date '+%F %T %Z'`] New release [ci skip]"
67-
# Push
68-
git push origin main:main
60+
run: ./.github/workflows/deploy.sh

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This repository is for the [haskell.foundation](https://haskell.foundation) webs
1515
- [Building](#building)
1616
- [CI](#ci)
1717
- [License](#license)
18-
18+
- [Dev Deployments List](https://github.com/haskellfoundation/haskellfoundation.github.io/blob/gh-pages/DEPLOYMENTS.md)
1919

2020
## Building
2121

donations/sponsors/flipstone.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: FlipStone
3-
logo: /assets/images/sponsors/flipstone/flipstone-683.png
4-
srcset: /assets/images/sponsors/flipstone/flipstone-200.png 200w, /assets/images/sponsors/flipstone/flipstone-400.png 400w, /assets/images/sponsors/flipstone/flipstone-683.png 683w
3+
logo: ./assets/images/sponsors/flipstone/flipstone-683.png
4+
srcset: ./assets/images/sponsors/flipstone/flipstone-200.png 200w, ./assets/images/sponsors/flipstone/flipstone-400.png 400w, ./assets/images/sponsors/flipstone/flipstone-683.png 683w
55
externalUrl: https://flipstone.com/
66
level: Functor
77
---

donations/sponsors/github.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: GitHub
3-
logo: /assets/images/sponsors/github/github-683.png
4-
srcset: /assets/images/sponsors/github/github-200.png 200w, /assets/images/sponsors/github/github-400.png 400w, /assets/images/sponsors/github/github-683.png 683w
3+
logo: ./assets/images/sponsors/github/github-683.png
4+
srcset: ./assets/images/sponsors/github/github-200.png 200w, ./assets/images/sponsors/github/github-400.png 400w, ./assets/images/sponsors/github/github-683.png 683w
55
externalUrl: https://github.com/
66
level: Monad
77
---

donations/sponsors/iohk.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: IOHK
3-
logo: /assets/images/sponsors/iohk/iohk-683.png
4-
srcset: /assets/images/sponsors/iohk/iohk-200.png 200w, /assets/images/sponsors/iohk/iohk-400.png 400w, /assets/images/sponsors/iohk/iohk-683.png 683w
3+
logo: ./assets/images/sponsors/iohk/iohk-683.png
4+
srcset: ./assets/images/sponsors/iohk/iohk-200.png 200w, ./assets/images/sponsors/iohk/iohk-400.png 400w, ./assets/images/sponsors/iohk/iohk-683.png 683w
55
externalUrl: https://iohk.io/
66
level: Monad
77
---

donations/sponsors/obsidian.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Obsidian Systems
3-
logo: /assets/images/sponsors/obsidian-systems/obsidian-systems-683.png
4-
srcset: /assets/images/sponsors/obsidian-systems/obsidian-systems-200.png 200w, /assets/images/sponsors/obsidian-systems/obsidian-systems-400.png 400w, /assets/images/sponsors/obsidian-systems/obsidian-systems-683.png 683w
3+
logo: ./assets/images/sponsors/obsidian-systems/obsidian-systems-683.png
4+
srcset: ./assets/images/sponsors/obsidian-systems/obsidian-systems-200.png 200w, ./assets/images/sponsors/obsidian-systems/obsidian-systems-400.png 400w, ./assets/images/sponsors/obsidian-systems/obsidian-systems-683.png 683w
55
externalUrl: https://obsidian.systems/
66
level: Applicative
77
---

donations/sponsors/tweag.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Tweag
3-
logo: /assets/images/sponsors/tweag/tweag-683.png
4-
srcset: /assets/images/sponsors/tweag/tweag-200.png 200w, /assets/images/sponsors/tweag/tweag-400.png 400w, /assets/images/sponsors/tweag/tweag-683.png 683w
3+
logo: ./assets/images/sponsors/tweag/tweag-683.png
4+
srcset: ./assets/images/sponsors/tweag/tweag-200.png 200w, ./assets/images/sponsors/tweag/tweag-400.png 400w, ./assets/images/sponsors/tweag/tweag-683.png 683w
55
externalUrl: https://tweag.io/
66
level: Applicative
77
---

donations/sponsors/welltyped.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Well-Typed
3-
logo: /assets/images/sponsors/well-typed/well-typed-683.png
4-
srcset: /assets/images/sponsors/well-typed/well-typed-200.png 200w, /assets/images/sponsors/well-typed/well-typed-400.png 400w, /assets/images/sponsors/well-typed/well-typed-683.png 683w
3+
logo: ./assets/images/sponsors/well-typed/well-typed-683.png
4+
srcset: ./assets/images/sponsors/well-typed/well-typed-200.png 200w, ./assets/images/sponsors/well-typed/well-typed-400.png 400w, ./assets/images/sponsors/well-typed/well-typed-683.png 683w
55
externalUrl: https://well-typed.com/
66
level: Applicative
77
---

0 commit comments

Comments
 (0)