|
13 | 13 |
|
14 | 14 | # Check `aaz-dev` is available or not |
15 | 15 | if ! command -v aaz-dev &> /dev/null; then |
16 | | - GREEN="\033[0;32m" |
17 | | - YELLOW="\033[1;33m" |
18 | | - NC="\033[0m" # no color |
19 | | - |
20 | | - set_or_add_remote() { |
21 | | - local REMOTE_NAME=$1 |
22 | | - local REMOTE_URL=$2 |
23 | | - local REPO_PATH="/workspaces/$REPO_NAME" |
24 | | - |
25 | | - git -C "$REPO_PATH" remote get-url "$REMOTE_NAME" &>/dev/null || git -C "$REPO_PATH" remote add "$REMOTE_NAME" "$REMOTE_URL" |
26 | | - git -C "$REPO_PATH" remote set-url "$REMOTE_NAME" "$REMOTE_URL" |
27 | | - } |
28 | | - |
29 | | - setup_repo() { |
30 | | - local DIR_NAME="$1" |
31 | | - local DIR_PATH="/workspaces/$DIR_NAME" |
32 | | - local REPO="Azure/$DIR_NAME" |
33 | | - |
34 | | - if [ -d "$DIR_PATH" ]; then |
35 | | - echo -e "\n${YELLOW}($DIR_NAME) Pulling the latest changes from upstream...${NC}" |
36 | | - gh repo fork "$REPO" --clone=false |
37 | | - else |
38 | | - echo -e "\n${GREEN}($DIR_NAME) Forking and cloning the repository...${NC}" |
39 | | - gh repo fork "$REPO" --clone=true |
40 | | - fi |
41 | | - |
42 | | - # `git` doesn't work well with private repository |
43 | | - if [ "$(gh repo view "$REPO" --json visibility --jq '.visibility')" == "PRIVATE" ]; then |
44 | | - cd "$DIR_PATH" |
45 | | - gh repo sync --source "$REPO" |
46 | | - cd /workspaces |
47 | | - else |
48 | | - DEFAULT_BRANCH=$(git -C "$DIR_PATH" remote show upstream | grep "HEAD branch" | awk '{print $NF}') |
49 | | - git -C "$DIR_PATH" pull -r upstream "$DEFAULT_BRANCH" |
50 | | - fi |
51 | | - } |
52 | | - |
53 | | - SECONDS=0 |
54 | | - |
55 | | - REPO_NAME=$(basename "$GITHUB_REPOSITORY") |
56 | | - set_or_add_remote origin "https://github.com/$GITHUB_USER/$REPO_NAME.git" |
57 | | - set_or_add_remote upstream "https://github.com/Azure/$REPO_NAME.git" |
58 | | - |
59 | | - uv pip install aaz-dev |
60 | | - |
61 | | - # azdev repositories |
62 | | - setup_repo "azure-cli" |
63 | | - setup_repo "azure-cli-extensions" |
64 | | - |
65 | | - azdev setup -c -r ./azure-cli-extensions |
66 | | - |
67 | | - # aaz-dev repositories |
68 | | - setup_repo "aaz" |
69 | | - setup_repo "azure-rest-api-specs" |
70 | | - setup_repo "azure-rest-api-specs-pr" |
71 | | - |
72 | | - ELAPSED_TIME=$SECONDS |
73 | | - echo -e "\n${YELLOW}Elapsed time: $((ELAPSED_TIME / 60))m $((ELAPSED_TIME % 60))s.${NC}" |
74 | | - echo -e "\n${GREEN}Finished setup! Please launch the codegen tool via \`aaz-dev run -c azure-cli -e azure-cli-extensions -s azure-rest-api-specs -a aaz\`.${NC}\n" |
| 16 | + GREEN="\033[0;32m" |
| 17 | + YELLOW="\033[0;33m" |
| 18 | + NC="\033[0m" # no color |
| 19 | + |
| 20 | + set_or_add_remote() { |
| 21 | + local REMOTE_NAME=$1 |
| 22 | + local REMOTE_URL=$2 |
| 23 | + local REPO_PATH="/workspaces/$REPO_NAME" |
| 24 | + |
| 25 | + git -C "$REPO_PATH" remote get-url "$REMOTE_NAME" &>/dev/null || git -C "$REPO_PATH" remote add "$REMOTE_NAME" "$REMOTE_URL" |
| 26 | + git -C "$REPO_PATH" remote set-url "$REMOTE_NAME" "$REMOTE_URL" |
| 27 | + } |
| 28 | + |
| 29 | + setup_repo() { |
| 30 | + local DIR_NAME="$1" |
| 31 | + local DIR_PATH="/workspaces/$DIR_NAME" |
| 32 | + local REPO="Azure/$DIR_NAME" |
| 33 | + |
| 34 | + if [ -d "$DIR_PATH" ]; then |
| 35 | + echo -e "\n${YELLOW}($DIR_NAME) Pulling the latest changes from upstream...${NC}" |
| 36 | + gh repo fork "$REPO" --clone=false |
| 37 | + else |
| 38 | + echo -e "\n${GREEN}($DIR_NAME) Forking and cloning the repository...${NC}" |
| 39 | + gh repo fork "$REPO" --clone -- --depth=1 |
| 40 | + fi |
| 41 | + |
| 42 | + # `git` doesn't work well with private repository |
| 43 | + if [ "$(gh repo view "$REPO" --json visibility --jq '.visibility')" == "PRIVATE" ]; then |
| 44 | + cd "$DIR_PATH" |
| 45 | + gh repo sync --source "$REPO" |
| 46 | + cd /workspaces |
| 47 | + else |
| 48 | + DEFAULT_BRANCH=$(git -C "$DIR_PATH" remote show upstream | grep "HEAD branch" | awk '{print $NF}') |
| 49 | + git -C "$DIR_PATH" pull -r upstream "$DEFAULT_BRANCH" |
| 50 | + fi |
| 51 | + } |
| 52 | + |
| 53 | + echo -e "\n${GREEN}Welcome to the dev environment setup wizard.${NC}\n" |
| 54 | + |
| 55 | + SECONDS=0 |
| 56 | + |
| 57 | + REPO_NAME=$(basename "$GITHUB_REPOSITORY") |
| 58 | + set_or_add_remote origin "https://github.com/$GITHUB_USER/$REPO_NAME.git" |
| 59 | + set_or_add_remote upstream "https://github.com/Azure/$REPO_NAME.git" |
| 60 | + |
| 61 | + uv pip install aaz-dev |
| 62 | + |
| 63 | + # `azdev` repositories |
| 64 | + setup_repo "azure-cli" |
| 65 | + setup_repo "azure-cli-extensions" |
| 66 | + |
| 67 | + azdev setup -c -r ./azure-cli-extensions |
| 68 | + |
| 69 | + # `aaz-dev` repositories |
| 70 | + setup_repo "aaz" |
| 71 | + setup_repo "azure-rest-api-specs" |
| 72 | + setup_repo "azure-rest-api-specs-pr" |
| 73 | + |
| 74 | + ELAPSED_TIME=$SECONDS |
| 75 | + echo -e "\n${YELLOW}Elapsed time: $((ELAPSED_TIME / 60))m $((ELAPSED_TIME % 60))s.${NC}" |
| 76 | + echo -e "\n${GREEN}Finished setup! Please launch the codegen tool via:${NC}" |
| 77 | + echo -e "${GREEN}aaz-dev run -c azure-cli -e azure-cli-extensions -s azure-rest-api-specs -a aaz${NC}\n" |
75 | 78 | fi |
0 commit comments