@@ -17,11 +17,7 @@ slugify() {
17
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
18
}
19
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
20
+ git_branch=$( git branch --show-current)
25
21
echo " Current git branch is '${git_branch} '."
26
22
27
23
git config user.name github-actions
@@ -44,7 +40,7 @@ if [ "$git_branch" == "$main_git_branch" ]; then
44
40
# Restore temporary backup for other branches content.
45
41
mv ./branches " ${gh_pages_root} /"
46
42
else
47
- site_dest=" ${gh_pages_root} /branches/${git_branch} "
43
+ site_dest=" ${gh_pages_root} /branches/$( slugify $ {git_branch}) "
48
44
49
45
# Replace site files.
50
46
rm -rf " ${site_dest} "
@@ -58,12 +54,6 @@ git commit --allow-empty -m "[$(date '+%F %T %Z')] Updated site for the '${git_b
58
54
git push --force origin gh-pages
59
55
echo " Deployment finished."
60
56
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
66
-
67
57
github_project_url=$( git remote get-url origin)
68
58
if [[
$github_project_url == [email protected] :
* ]]
; then
69
59
github_repo=
$( echo ${github_project_url# " [email protected] :" } | sed ' s/\.git$//g' )
73
63
74
64
github_repo_owner=$( echo " ${github_repo} " | sed ' s/\/.*$//g' )
75
65
github_repo_name=$( echo " ${github_repo} " | sed ' s/^.*\///g' )
76
- git_head_sha=$( git rev-parse --verify HEAD)
77
-
78
- if [ " $git_branch " == " $main_git_branch " ]; then
79
- deployment_url=" https://${github_repo_owner} .github.io/${github_repo_name} /"
80
- else
81
- deployment_url=" https://${github_repo_owner} .github.io/${github_repo_name} /branches/${git_branch} "
82
- fi
83
66
84
- update_github_deployment_req_data () {
85
- cat << EOF
86
- {
87
- "name": "deployment",
88
- "ref": "${git_branch} ",
89
- "environment": "github-pages",
90
- "payload": "some payload https://xyz.abc",
91
- "description": "some description https://abc.xyz"
67
+ update_deployments_list () {
68
+ deployments_list=" DEPLOYMENTS.md"
69
+ echo " Updating ${deployments_list} "
70
+ rm $deployments_list
71
+
72
+ touch $deployments_list
73
+ echo " # Deployments" >> $deployments_list
74
+ echo " " >> $deployments_list
75
+ echo " | Branch | Link |" >> $deployments_list
76
+ echo " | --- | --- |" >> $deployments_list
77
+
78
+ main_deployment_url=" https://${github_repo_owner} .github.io/${github_repo_name} /"
79
+ echo " | [main](https://github.com/${github_repo_owner} /${github_repo_name} /tree/${branch} ) | [Open](${main_deployment_url} ) |"
80
+
81
+ remote_branches=$( git ls-remote --heads origin | sed ' s?.*refs/heads/??' )
82
+ echo " $remote_branches " | while IFS= read -r branch; do
83
+ safe_branch=$( slugify $branch )
84
+ deployment_url=" https://${github_repo_owner} .github.io/${github_repo_name} /branches/${safe_branch} "
85
+ echo " | [${branch} ](https://github.com/${github_repo_owner} /${github_repo_name} /tree/${branch} ) | [Open](${deployment_url} ) |"
86
+ done
87
+
88
+ # Update gh-pages branch
89
+ git add --all
90
+ git commit --allow-empty -m " Update ${deployments_list} "
91
+ git push --force origin gh-pages
92
92
}
93
- EOF
94
- }
95
-
96
- curl -i \
97
- --header " Authorization: Bearer ${GITHUB_TOKEN} " \
98
- --header " Accept: application/vnd.github.v3+json" \
99
- --header " User-Agent: github-actions" \
100
- --header " Content-Type: application/json" \
101
- --data " $( update_github_deployment_req_data) " \
102
- --fail \
103
- https://api.github.com/repos/${github_repo_owner} /${github_repo_name} /deployments
104
93
105
- echo " Deployment is available at: ' ${deployment_url} ' "
94
+ update_deployments_list
0 commit comments