Skip to content

Commit c8bb50f

Browse files
committed
haskellfoundation#23 Make a site deployment per branch
1 parent 60c5820 commit c8bb50f

File tree

1 file changed

+40
-37
lines changed

1 file changed

+40
-37
lines changed

.github/workflows/deploy.sh

+40-37
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,56 @@ slugify() {
1717
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
1818
}
1919

20-
git_branch=$(git branch --show-current)
21-
echo "Current git branch is '${git_branch}'."
20+
deploy() {
21+
git_branch=$(git branch --show-current)
22+
echo "Current git branch is '${git_branch}'."
2223

23-
git config user.name github-actions
24-
git config user.email [email protected]
24+
git config user.name github-actions
25+
git config user.email [email protected]
2526

26-
git checkout gh-pages
27-
git pull origin gh-pages
27+
git checkout gh-pages
28+
git pull origin gh-pages
2829

29-
if [ "$git_branch" == "$main_git_branch" ]; then
30-
site_dest="${gh_pages_root}"
30+
if [ "$git_branch" == "$main_git_branch" ]; then
31+
site_dest="${gh_pages_root}"
3132

32-
# Create temporary backup for other branches content.
33-
mv "${gh_pages_root}/branches" .
33+
# Create temporary backup for other branches content.
34+
mv "${gh_pages_root}/branches" .
3435

35-
# Replace site files.
36-
rm -rf "${site_dest}"
37-
mkdir -p "${site_dest}"
38-
cp -a -v ${site_src}/* ${site_dest}/
36+
# Replace site files.
37+
rm -rf "${site_dest}"
38+
mkdir -p "${site_dest}"
39+
cp -a -v ${site_src}/* ${site_dest}/
3940

40-
# Restore temporary backup for other branches content.
41-
mv ./branches "${gh_pages_root}/"
42-
else
43-
site_dest="${gh_pages_root}/branches/$(slugify ${git_branch})"
41+
# Restore temporary backup for other branches content.
42+
mv ./branches "${gh_pages_root}/"
43+
else
44+
site_dest="${gh_pages_root}/branches/$(slugify ${git_branch})"
4445

45-
# Replace site files.
46-
rm -rf "${site_dest}"
47-
mkdir -p "${site_dest}"
48-
cp -a -v ${site_src}/* ${site_dest}/
49-
fi
46+
# Replace site files.
47+
rm -rf "${site_dest}"
48+
mkdir -p "${site_dest}"
49+
cp -a -v ${site_src}/* ${site_dest}/
50+
fi
5051

51-
echo "Updating gh-pages branch."
52-
git add --all
53-
git commit --allow-empty -m "[$(date '+%F %T %Z')] Updated site for the '${git_branch}' branch [ci skip]"
54-
git push --force origin gh-pages
55-
echo "Deployment finished."
52+
echo "Updating gh-pages branch."
53+
git add --all
54+
git commit --allow-empty -m "[$(date '+%F %T %Z')] Updated site for the '${git_branch}' branch [ci skip]"
55+
git push --force origin gh-pages
56+
echo "Deployment finished."
57+
}
5658

57-
github_project_url=$(git remote get-url origin)
58-
if [[ $github_project_url == [email protected]:* ]]; then
59-
github_repo=$(echo ${github_project_url#"[email protected]:"} | sed 's/\.git$//g')
60-
elif [[ $github_project_url == https://github.com/* ]]; then
61-
github_repo=$(echo ${github_project_url#"https://github.com/"} | sed 's/\.git$//g' | sed 's/^\/\///g')
62-
fi
59+
update_deployments_list() {
60+
github_project_url=$(git remote get-url origin)
61+
if [[ $github_project_url == [email protected]:* ]]; then
62+
github_repo=$(echo ${github_project_url#"[email protected]:"} | sed 's/\.git$//g')
63+
elif [[ $github_project_url == https://github.com/* ]]; then
64+
github_repo=$(echo ${github_project_url#"https://github.com/"} | sed 's/\.git$//g' | sed 's/^\/\///g')
65+
fi
6366

64-
github_repo_owner=$(echo "${github_repo}" | sed 's/\/.*$//g')
65-
github_repo_name=$(echo "${github_repo}" | sed 's/^.*\///g')
67+
github_repo_owner=$(echo "${github_repo}" | sed 's/\/.*$//g')
68+
github_repo_name=$(echo "${github_repo}" | sed 's/^.*\///g')
6669

67-
update_deployments_list() {
6870
deployments_list="DEPLOYMENTS.md"
6971
echo "Updating ${deployments_list}"
7072
rm $deployments_list
@@ -92,4 +94,5 @@ update_deployments_list() {
9294
git push --force origin gh-pages
9395
}
9496

97+
deploy
9598
update_deployments_list

0 commit comments

Comments
 (0)