Skip to content

Commit 2f9fa45

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

14 files changed

+256
-81
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/branch-deleted.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Branch Deleted
2+
3+
on: delete
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
with:
12+
fetch-depth: 0
13+
ref: hakyll
14+
15+
- name: Remove deployment for deleted branch
16+
run: |
17+
./.github/workflows/deployment/delete.sh ${{ github.event.ref }}

.github/workflows/build.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- gh-pages
7+
pull_request:
8+
branches-ignore:
9+
- gh-pages
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
19+
strategy:
20+
matrix:
21+
stack: ["2.7.3"]
22+
ghc: ["8.10.7"]
23+
24+
steps:
25+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
26+
- uses: actions/checkout@v2
27+
with:
28+
fetch-depth: 0
29+
30+
- uses: haskell/actions/setup@v1
31+
name: Setup Haskell Stack
32+
with:
33+
ghc-version: ${{ matrix.ghc }}
34+
stack-version: ${{ matrix.stack }}
35+
36+
- uses: actions/cache@v1
37+
name: Cache ~/.stack
38+
with:
39+
path: ~/.stack
40+
key: ${{ runner.os }}-${{ matrix.ghc }}-stack
41+
42+
- name: Build dependencies
43+
run: stack build --system-ghc --only-dependencies
44+
45+
- name: Build site
46+
run: |
47+
stack build --system-ghc
48+
stack exec --system-ghc site rebuild
49+
50+
- name: Deploy site
51+
run: |
52+
./.github/workflows/deployment/deploy.sh
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
3+
export repo_root_dir=$(git rev-parse --show-toplevel)
4+
export site_src="${repo_root_dir}/_site"
5+
export gh_pages_dir="${repo_root_dir}/docs"
6+
export deployments_dir="${gh_pages_dir}/branches"
7+
8+
# Site built from the main branch will be available at 'https://<domain_name>/'.
9+
# Sites built from other branchs will be available at 'https://<domain_name>/branches/<branch_name>'.
10+
export main_git_branch="hakyll"
11+
12+
# replace "/", "#", etc with "-".
13+
slugify() {
14+
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
15+
}
16+
export -f slugify
17+
18+
git config user.name github-actions
19+
git config user.email [email protected]
20+
21+
update_deployments_list() {
22+
github_project_url=$(git remote get-url origin)
23+
if [[ $github_project_url == [email protected]:* ]]; then
24+
github_repo=$(echo ${github_project_url#"[email protected]:"} | sed 's/\.git$//g')
25+
elif [[ $github_project_url == https://github.com/* ]]; then
26+
github_repo=$(echo ${github_project_url#"https://github.com/"} | sed 's/\.git$//g' | sed 's/^\/\///g')
27+
fi
28+
29+
github_repo_owner=$(echo "${github_repo}" | sed 's/\/.*$//g')
30+
github_repo_name=$(echo "${github_repo}" | sed 's/^.*\///g')
31+
32+
deployments_list="DEPLOYMENTS.md"
33+
echo "Updating ${deployments_list}"
34+
rm $deployments_list
35+
36+
# Create a markdown table
37+
touch $deployments_list
38+
echo "# Deployments" >>$deployments_list
39+
echo "" >>$deployments_list
40+
echo "| Branch | Link |" >>$deployments_list
41+
echo "| --- | --- |" >>$deployments_list
42+
43+
main_deployment_url="https://${github_repo_owner}.github.io/${github_repo_name}/"
44+
echo "| [${main_git_branch}](https://github.com/${github_repo_owner}/${github_repo_name}/tree/${branch}) | [Open](${main_deployment_url}) |" >>$deployments_list
45+
46+
remote_branches=$(git ls-remote --heads origin | sed 's?.*refs/heads/??' | grep -v "gh-pages" | grep -v "${main_git_branch}")
47+
echo "$remote_branches" | while IFS= read -r branch; do
48+
branch_slug=$(slugify $branch)
49+
deployment_url="https://${github_repo_owner}.github.io/${github_repo_name}/branches/${branch_slug}"
50+
echo "| [${branch}](https://github.com/${github_repo_owner}/${github_repo_name}/tree/${branch}) | [Open](${deployment_url}) |" >>$deployments_list
51+
done
52+
53+
# Update gh-pages branch
54+
git add --all
55+
git commit --allow-empty -m "Update ${deployments_list} [ci skip]"
56+
git push --force origin gh-pages
57+
}
58+
59+
export -f update_deployments_list
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
# Remove deployment by specified git branch name.
4+
5+
set -eo pipefail
6+
7+
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
8+
source $script_dir/commons.sh
9+
10+
git checkout gh-pages
11+
git pull origin gh-pages
12+
13+
branch_slug=$(slugify $1)
14+
rm -rf "$deployments_dir/$branch_slug"
15+
16+
echo "Updating gh-pages branch."
17+
git add --all
18+
git commit --allow-empty -m "Delete '$1' branch deployment [ci skip]"
19+
git push --force origin gh-pages
20+
echo "Deployment for branch '$1' has been deleted."
21+
22+
update_deployments_list
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
3+
# Deploy static site to the GitHub pages.
4+
5+
set -eo pipefail
6+
7+
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
8+
source $script_dir/commons.sh
9+
10+
deploy() {
11+
if [[ ! -z "$GITHUB_REF_NAME" ]]; then
12+
# The GITHUB_REF_NAME env variable is available in github actions.
13+
git_branch=$GITHUB_REF_NAME
14+
else
15+
git_branch=$(git branch --show-current)
16+
fi
17+
echo "Current git branch is '${git_branch}'."
18+
19+
git checkout gh-pages
20+
git pull origin gh-pages
21+
22+
if [ "$git_branch" == "$main_git_branch" ]; then
23+
site_dest="${gh_pages_dir}"
24+
25+
# Create temporary backup for other branches content.
26+
mv "${deployments_dir}" .
27+
28+
# Replace site files.
29+
rm -rf "${site_dest}"
30+
mkdir -p "${site_dest}"
31+
cp -a -v ${site_src}/* ${site_dest}/
32+
33+
# Restore temporary backup for other branches content.
34+
mv ./branches "${gh_pages_dir}/"
35+
else
36+
# Patch html files to tell search engine bots like google-bot not to index this content.
37+
# More info: https://developers.google.com/search/docs/advanced/crawling/block-indexing
38+
find $site_src -name '*.html' -exec sed -i 's/<head>/<head><meta name="robots" content="noindex, nofollow">/g' {} \;
39+
40+
branch_slug=$(slugify $git_branch)
41+
site_dest="${gh_pages_dir}/branches/${branch_slug}"
42+
43+
# Replace site files.
44+
rm -rf "${site_dest}"
45+
mkdir -p "${site_dest}"
46+
cp -a -v ${site_src}/* ${site_dest}/
47+
fi
48+
49+
echo "Updating gh-pages branch."
50+
git add --all
51+
git commit --allow-empty -m "Update '${git_branch}' branch deployment [ci skip]"
52+
git push --force origin gh-pages
53+
echo "Deployment finished."
54+
}
55+
56+
deploy
57+
update_deployments_list

.github/workflows/main.yml

-68
This file was deleted.

README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ This repository is for the [haskell.foundation](https://haskell.foundation) webs
1414
- [Table Of Contents](#table-of-contents)
1515
- [Building](#building)
1616
- [CI](#ci)
17+
- [Deployment](#deployment)
18+
- [PRs deployment](#prs-deployment)
1719
- [License](#license)
1820

19-
2021
## Building
2122

2223
To build the project:
@@ -50,6 +51,26 @@ The general steps are:
5051
7. Copy the `_site` directory over the `main` branch contents
5152
8. Commit and push the site contents to the `main` branch.
5253

54+
## Deployment
55+
56+
[Available Deployments](https://github.com/haskellfoundation/haskellfoundation.github.io/blob/gh-pages/DEPLOYMENTS.md)
57+
58+
Deployment is automated for branches in the original repository.
59+
60+
### PRs deployment
61+
62+
When you are submitting a PR, it's a good practice to provide a link to a running website demo.
63+
64+
First you should enable GitHub pages for you forked repository.
65+
66+
<img width="949" alt="Screen Shot 2021-12-29 at 10 28 32 PM" src="https://user-images.githubusercontent.com/9302460/147704755-d9bc8c08-7272-4c55-b88f-34b3aefd0c1e.png">
67+
68+
Then you should manually trigger a build for your branch in your forker repository.
69+
70+
<img width="988" alt="Screen Shot 2021-12-29 at 10 25 19 PM" src="https://user-images.githubusercontent.com/9302460/147704589-8bce2b51-cedc-4e8a-9aec-33574b2d2c02.png">
71+
72+
At first time it can take a while because there is no cache for Hakyll dependencies at your GitHub actions runner yet. You can attach a link to running CI job to the PR and go drink coffee.
73+
5374
## License
5475

5576
This site is open source, and covered under the Apache 2.0 license.

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)