Skip to content

Commit cec5061

Browse files
committed
Handle branch deletion
1 parent 302f897 commit cec5061

File tree

6 files changed

+43
-46
lines changed

6 files changed

+43
-46
lines changed

.github/workflows/branch-deleted.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ jobs:
1515
- name: Remove deployment for deleted branch
1616
run: |
1717
./.github/workflows/deployment/delete.sh ${{ github.event.ref }}
18-
./.github/workflows/deployment/update-deployments-list.sh

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,3 @@ jobs:
5050
- name: Deploy site
5151
run: |
5252
./.github/workflows/deployment/deploy.sh
53-
./.github/workflows/deployment/update-deployments-list.sh

.github/workflows/deployment/commons.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,43 @@ export -f slugify
1717

1818
git config user.name github-actions
1919
git config user.email github-actions@github.com
20+
21+
update_deployments_list() {
22+
github_project_url=$(git remote get-url origin)
23+
if [[ $github_project_url == git@github.com:* ]]; then
24+
github_repo=$(echo ${github_project_url#"git@github.com:"} | 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

.github/workflows/deployment/delete.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ git add --all
1818
git commit --allow-empty -m "Delete '$1' branch deployment [ci skip]"
1919
git push --force origin gh-pages
2020
echo "Deployment for branch '$1' has been deleted."
21+
22+
update_deployments_list

.github/workflows/deployment/deploy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ deploy() {
5454
}
5555

5656
deploy
57+
update_deployments_list

.github/workflows/deployment/update-deployments-list.sh

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)