|
| 1 | + |
| 2 | +source .venv/bin/activate |
| 3 | + |
| 4 | +# Logout default account |
| 5 | +export GITHUB_TOKEN= |
| 6 | + |
| 7 | +# Check `repo` scope exists or not |
| 8 | +if gh auth status -a 2>/dev/null | grep "Token scopes: " | grep -q "repo"; then |
| 9 | + echo "You now have access to GitHub." |
| 10 | +else |
| 11 | + gh auth login -p https -w |
| 12 | +fi |
| 13 | + |
| 14 | +# Check `aaz-dev` is available or not |
| 15 | +if ! command -v aaz-dev &> /dev/null; then |
| 16 | + GREEN="\033[0;32m" |
| 17 | + YELLOW="\033[0;33m" |
| 18 | + NC="\033[0m" # no color |
| 19 | + |
| 20 | + set_or_add_remote() { |
| 21 | + local REPO=$1 |
| 22 | + local REMOTE=$2 |
| 23 | + local DIR="/workspaces/$REPO" |
| 24 | + local OWNER=$([ "$REMOTE" = "origin" ] && echo "$GITHUB_USER" || echo "Azure") |
| 25 | + local URL="https://github.com/$OWNER/$REPO.git" |
| 26 | + |
| 27 | + git -C "$DIR" remote get-url "$REMOTE" &>/dev/null || git -C "$DIR" remote add "$REMOTE" "$URL" |
| 28 | + git -C "$DIR" remote set-url "$REMOTE" "$URL" |
| 29 | + } |
| 30 | + |
| 31 | + setup_repo() { |
| 32 | + local REPO=$1 |
| 33 | + local DIR="/workspaces/$REPO" |
| 34 | + |
| 35 | + echo |
| 36 | + gh repo fork "Azure/$REPO" --clone=false --default-branch-only |
| 37 | + |
| 38 | + if [ -d "$DIR" ]; then |
| 39 | + set_or_add_remote "$REPO" origin |
| 40 | + set_or_add_remote "$REPO" upstream |
| 41 | + else |
| 42 | + git clone "https://github.com/$GITHUB_USER/$REPO.git" --single-branch --no-tags |
| 43 | + set_or_add_remote "$REPO" upstream |
| 44 | + |
| 45 | + # Synchronize with upstream |
| 46 | + BRANCH=$(git -C "$DIR" remote show upstream | grep "HEAD branch" | awk '{print $NF}') |
| 47 | + git -C "$DIR" pull -r upstream "$BRANCH" |
| 48 | + fi |
| 49 | + } |
| 50 | + |
| 51 | + SECONDS=0 |
| 52 | + |
| 53 | + echo |
| 54 | + uv pip install aaz-dev --link-mode=copy |
| 55 | + |
| 56 | + # `azdev` repositories |
| 57 | + setup_repo "azure-cli" |
| 58 | + setup_repo "azure-cli-extensions" |
| 59 | + |
| 60 | + azdev setup -c -r ./azure-cli-extensions |
| 61 | + |
| 62 | + # `aaz-dev` repositories |
| 63 | + setup_repo "aaz" |
| 64 | + setup_repo "azure-rest-api-specs" |
| 65 | + |
| 66 | + ELAPSED_TIME=$SECONDS |
| 67 | + |
| 68 | + echo -e "\n${YELLOW}Elapsed time: $((ELAPSED_TIME / 60))m $((ELAPSED_TIME % 60))s.${NC}" |
| 69 | + echo -e "\n${GREEN}Finished setup! Please launch the codegen tool via:${NC}" |
| 70 | + echo -e "${GREEN}\$ aaz-dev run -c azure-cli -e azure-cli-extensions -s azure-rest-api-specs -a aaz${NC}\n" |
| 71 | +else |
| 72 | + echo -e "\nPlease launch the codegen tool via:" |
| 73 | + echo -e "$ aaz-dev run -c azure-cli -e azure-cli-extensions -s azure-rest-api-specs -a aaz\n" |
| 74 | +fi |
0 commit comments