1
1
#! /bin/bash
2
2
set -e
3
3
4
+ # IMPORTANT:a valid GITHUB_TOKEN is required to run this script
5
+
4
6
GITHUB_REPOSITORY=" Azure-Samples/contoso-real-estate"
5
7
BRANCH=" codespaces-ci"
6
8
CODESPACE_NAME=" ci-nightly-build-$( date +%s) "
7
9
CODESPACE_ID=" "
8
- RED=' \033[0;31m '
10
+ RED=' \033[0;35m ' // this is not red, it ' s purple!
9
11
GREEN=' \0 33[0; 32m'
10
12
NC=' \0 33[0m' # No Color
11
13
12
14
# login to GitHub CLI
13
15
function gh_login() {
14
16
echo "Loging in with GitHub CLI as admin..."
15
- echo $X_GITHUB_TOKEN | gh auth login --with-token
17
+ echo $X_GITHUB_TOKEN | gh auth login --with-token
16
18
17
19
echo "Checking auth status..."
18
20
gh auth status
@@ -33,7 +35,7 @@ function gh_create_codespace() {
33
35
}
34
36
function api_create_codespace() {
35
37
echo "Creating a codespace $CODESPACE_NAME for $GITHUB_REPOSITORY on branch $BRANCH (w/ api)..."
36
- CODESPACE_ID =$( gh api \
38
+ response =$(gh api \
37
39
/repos/$GITHUB_REPOSITORY/codespaces \
38
40
-X POST \
39
41
-H ' Accept: application/vnd.github+json' \
@@ -46,9 +48,14 @@ function api_create_codespace() {
46
48
-f idleTimeout=' 5min' \
47
49
-f machineType=l' argePremiumLinux' \
48
50
-f status=' true' \
49
- -f defaultPermissions=' true' \
50
- -q ' .name' )
51
- echo " Codespace created and started: $CODESPACE_ID "
51
+ -f defaultPermissions=' true' )
52
+ CODESPACE_ID=$(echo "$response" | jq ' .name' )
53
+ CODESPACE_URL=$(echo "$response" | jq ' .web_url' )
54
+ CODESPACE_API=$(echo "$response" | jq ' .url' )
55
+ echo "Codespace created and started:"
56
+ echo " - ID: $CODESPACE_ID"
57
+ echo " - Web: $CODESPACE_URL"
58
+ echo " - API: $CODESPACE_API"
52
59
}
53
60
54
61
# fetch the codespace ID
@@ -81,7 +88,7 @@ function gh_codespace_check_services_status() {
81
88
fi
82
89
83
90
nb_services_down=0
84
- echo " ---------------------------------------------------------------------------------------------------------"
91
+ echo "---------------------------------------------------------------------------------------------------------"
85
92
for service in $services; do
86
93
echo -ne "Inspecting: $service ... "
87
94
status=$(curl -H "X-Github-Token: $GITHUB_TOKEN" -s -o /dev/null -w "%{http_code}" $service)
@@ -112,12 +119,15 @@ function gh_codespace_check_services_status() {
112
119
done
113
120
}
114
121
115
- # Wait for the services to start
122
+ # Wait for all services to start
116
123
function wait_for_services() {
117
- echo -ne " Waiting 6 mintues for all dependencies to be installed and starting all services... "
118
- for i in {1..360 }; do
124
+ echo "Waiting 10 mintues for all dependencies to be installed and starting all services"
125
+ for i in {1..600 }; do
119
126
echo -ne "."
120
127
sleep 1
128
+ if ! ((i % 60)); then
129
+ echo ""
130
+ fi
121
131
done
122
132
echo ""
123
133
}
@@ -152,4 +162,4 @@ api_create_codespace;
152
162
wait_for_services;
153
163
gh_codespace_check_services_status;
154
164
gh_codespace_stop_and_delete;
155
- print_report_and_exit;
165
+ print_report_and_exit;
0 commit comments