Skip to content

Commit 749db23

Browse files
committed
Handle branch deletion
1 parent 63baedd commit 749db23

File tree

4 files changed

+50
-41
lines changed

4 files changed

+50
-41
lines changed

.github/workflows/branch-deleted.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ jobs:
1313
ref: hakyll
1414

1515
- name: Remove stale deployments
16-
run: ./.github/workflows/deployment/delete.sh ${{ github.event.ref }}
16+
run: |
17+
./.github/workflows/deployment/delete.sh ${{ github.event.ref }}
18+
./.github/workflows/deployment/update-deployments-list.sh

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@ jobs:
4848
stack exec --system-ghc site rebuild
4949
5050
- name: Deploy site
51-
run: ./.github/workflows/deployment/deploy.sh
51+
run: |
52+
./.github/workflows/deployment/deploy.sh
53+
./.github/workflows/deployment/update-deployments-list.sh

.github/workflows/deployment/deploy.sh

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -55,43 +55,4 @@ deploy() {
5555
echo "Deployment finished."
5656
}
5757

58-
update_deployments_list() {
59-
github_project_url=$(git remote get-url origin)
60-
if [[ $github_project_url == git@github.com:* ]]; then
61-
github_repo=$(echo ${github_project_url#"git@github.com:"} | sed 's/\.git$//g')
62-
elif [[ $github_project_url == https://github.com/* ]]; then
63-
github_repo=$(echo ${github_project_url#"https://github.com/"} | sed 's/\.git$//g' | sed 's/^\/\///g')
64-
fi
65-
66-
github_repo_owner=$(echo "${github_repo}" | sed 's/\/.*$//g')
67-
github_repo_name=$(echo "${github_repo}" | sed 's/^.*\///g')
68-
69-
deployments_list="DEPLOYMENTS.md"
70-
echo "Updating ${deployments_list}"
71-
rm $deployments_list
72-
73-
# Create a markdown table
74-
touch $deployments_list
75-
echo "# Deployments" >>$deployments_list
76-
echo "" >>$deployments_list
77-
echo "| Branch | Link |" >>$deployments_list
78-
echo "| --- | --- |" >>$deployments_list
79-
80-
main_deployment_url="https://${github_repo_owner}.github.io/${github_repo_name}/"
81-
echo "| [${main_git_branch}](https://github.com/${github_repo_owner}/${github_repo_name}/tree/${branch}) | [Open](${main_deployment_url}) |" >>$deployments_list
82-
83-
remote_branches=$(git ls-remote --heads origin | sed 's?.*refs/heads/??' | grep -v "gh-pages" | grep -v "${main_git_branch}")
84-
echo "$remote_branches" | while IFS= read -r branch; do
85-
branch_slug=$(slugify $branch)
86-
deployment_url="https://${github_repo_owner}.github.io/${github_repo_name}/branches/${branch_slug}"
87-
echo "| [${branch}](https://github.com/${github_repo_owner}/${github_repo_name}/tree/${branch}) | [Open](${deployment_url}) |" >>$deployments_list
88-
done
89-
90-
# Update gh-pages branch
91-
git add --all
92-
git commit --allow-empty -m "Update ${deployments_list} [ci skip]"
93-
git push --force origin gh-pages
94-
}
95-
9658
deploy
97-
update_deployments_list
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
3+
# Updates deployments markdown table.
4+
5+
set -eo pipefail
6+
7+
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
8+
source $script_dir/commons.sh
9+
10+
github_project_url=$(git remote get-url origin)
11+
if [[ $github_project_url == git@github.com:* ]]; then
12+
github_repo=$(echo ${github_project_url#"git@github.com:"} | sed 's/\.git$//g')
13+
elif [[ $github_project_url == https://github.com/* ]]; then
14+
github_repo=$(echo ${github_project_url#"https://github.com/"} | sed 's/\.git$//g' | sed 's/^\/\///g')
15+
fi
16+
17+
github_repo_owner=$(echo "${github_repo}" | sed 's/\/.*$//g')
18+
github_repo_name=$(echo "${github_repo}" | sed 's/^.*\///g')
19+
20+
deployments_list="DEPLOYMENTS.md"
21+
echo "Updating ${deployments_list}"
22+
rm $deployments_list
23+
24+
# Create a markdown table
25+
touch $deployments_list
26+
echo "# Deployments" >>$deployments_list
27+
echo "" >>$deployments_list
28+
echo "| Branch | Link |" >>$deployments_list
29+
echo "| --- | --- |" >>$deployments_list
30+
31+
main_deployment_url="https://${github_repo_owner}.github.io/${github_repo_name}/"
32+
echo "| [${main_git_branch}](https://github.com/${github_repo_owner}/${github_repo_name}/tree/${branch}) | [Open](${main_deployment_url}) |" >>$deployments_list
33+
34+
remote_branches=$(git ls-remote --heads origin | sed 's?.*refs/heads/??' | grep -v "gh-pages" | grep -v "${main_git_branch}")
35+
echo "$remote_branches" | while IFS= read -r branch; do
36+
branch_slug=$(slugify $branch)
37+
deployment_url="https://${github_repo_owner}.github.io/${github_repo_name}/branches/${branch_slug}"
38+
echo "| [${branch}](https://github.com/${github_repo_owner}/${github_repo_name}/tree/${branch}) | [Open](${deployment_url}) |" >>$deployments_list
39+
done
40+
41+
# Update gh-pages branch
42+
git add --all
43+
git commit --allow-empty -m "Update ${deployments_list} [ci skip]"
44+
git push --force origin gh-pages

0 commit comments

Comments
 (0)