Skip to content

Commit 5ef2e27

Browse files
committed
haskellfoundation#23 Make a site deployment per branch
1 parent 6e9e627 commit 5ef2e27

File tree

2 files changed

+78
-78
lines changed

2 files changed

+78
-78
lines changed

.github/workflows/deploy.sh

+59-59
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,65 @@
44

55
set -eo pipefail
66

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
6666

6767
github_project_url=$(git remote get-url origin)
6868
if [[ $github_project_url == [email protected]:* ]]; then

.github/workflows/main.yml

+19-19
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,25 @@ jobs:
3636
fetch-depth: 0
3737
ref: hakyll
3838

39-
# - uses: haskell/actions/setup@v1
40-
# name: Setup Haskell Stack
41-
# with:
42-
# ghc-version: ${{ matrix.ghc }}
43-
# stack-version: ${{ matrix.stack }}
44-
45-
# - uses: actions/cache@v1
46-
# name: Cache ~/.stack
47-
# with:
48-
# path: ~/.stack
49-
# key: ${{ runner.os }}-${{ matrix.ghc }}-stack
50-
51-
# - name: Build dependencies
52-
# run: stack build --system-ghc --only-dependencies
53-
54-
# - name: Build
55-
# run: |
56-
# stack build --system-ghc
57-
# stack exec --system-ghc site build
39+
- uses: haskell/actions/setup@v1
40+
name: Setup Haskell Stack
41+
with:
42+
ghc-version: ${{ matrix.ghc }}
43+
stack-version: ${{ matrix.stack }}
44+
45+
- uses: actions/cache@v1
46+
name: Cache ~/.stack
47+
with:
48+
path: ~/.stack
49+
key: ${{ runner.os }}-${{ matrix.ghc }}-stack
50+
51+
- name: Build dependencies
52+
run: stack build --system-ghc --only-dependencies
53+
54+
- name: Build
55+
run: |
56+
stack build --system-ghc
57+
stack exec --system-ghc site build
5858
5959
- name: Deploy
6060
env:

0 commit comments

Comments
 (0)