Skip to content

Commit

Permalink
add the scripts to boostrap a ADO repo
Browse files Browse the repository at this point in the history
  • Loading branch information
legomushroom committed Aug 20, 2020
1 parent 526e71a commit e62caea
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 25 deletions.
111 changes: 90 additions & 21 deletions script/bootstrap → .codespaces/init-ado-repo.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@

clear

source ~/.bashrc
cp -Ru . ~/ado-in-codespaces

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CACHE_FILE_PATH=~/.ado-in-codespaces-cache

if [ -f $CACHE_FILE_PATH ]; then
source $CACHE_FILE_PATH
fi

if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi

source "$SCRIPT_DIR/lib/colors.sh"

if [ -f ~/.cs-envirnment ]; then
source ~/.cs-envirnment
Expand Down Expand Up @@ -33,6 +46,51 @@ echo -e $PALETTE_PURPLE"\n🏃 Lets setup the Codespace"$PALETTE_RESET

sleep 0.25s








if [ -z "$ADO_REPO_URL" ]; then

unset ADO_REPO_URL_SUFFIX;
if [ -z "$ADO_REPO_URL" ]; then
ADO_REPO_URL_SUFFIX=""
else
ADO_REPO_URL_SUFFIX=$PALETTE_CYAN"(➥ to reuse *$ADO_REPO_URL*)"$PALETTE_RESET
fi

echo -e $PALETTE_CYAN"\n- Please provide your AzDO repo URL\n"$PALETTE_RESET

printf " ↳ AzDO repo URL$ADO_REPO_URL_SUFFIX: $PALETTE_PURPLE"

read ADO_REPO_URL_INPUT

echo -e " $PALETTE_RESET"

if [ -z "$ADO_REPO_URL_INPUT" ]; then
if [ -z "$ADO_REPO_URL" ]; then
echo -e $PALETTE_RED" 🧱 No link - no {tbd}"$PALETTE_RESET
exit 1
else
ADO_REPO_URL_INPUT=$ADO_REPO_URL
echo -e $PALETTE_DIM" * reusing *$ADO_REPO_URL_INPUT* as AzDO repo URL.\n"$PALETTE_RESET
fi
fi

if [ "$ADO_REPO_URL" != "$ADO_REPO_URL_INPUT" ]; then
export ADO_REPO_URL=$ADO_REPO_URL_INPUT

echo "export ADO_REPO_URL=$ADO_REPO_URL" >> $CACHE_FILE_PATH
fi

fi




unset AZ_DO_USERNAME_SUFFIX;
if [ -z "$AZ_DO_USERNAME" ]; then
AZ_DO_USERNAME_SUFFIX=""
Expand Down Expand Up @@ -67,9 +125,16 @@ fi
if [ "$AZ_DO_USERNAME" != "$AZ_DO_USERNAME_INPUT" ]; then
export AZ_DO_USERNAME=$AZ_DO_USERNAME_INPUT

echo "export AZ_DO_USERNAME=$AZ_DO_USERNAME" >> ~/.bashrc
echo "export AZ_DO_USERNAME=$AZ_DO_USERNAME" >> $CACHE_FILE_PATH
fi








echo -e $PALETTE_CYAN"- Thanks, *$AZ_DO_USERNAME*! Please provide your AzDO PAT\n"$PALETTE_RESET

unset AZ_DO_PASSWORD_SUFFIX;
Expand All @@ -82,7 +147,7 @@ fi
# reading the PAT
unset CHARCOUNT
unset AZ_DO_PAT_INPUT
PROMPT=" ↳ PAT code[R/W] + packaging[R]$AZ_DO_PASSWORD_SUFFIX: $PALETTE_PURPLE"
PROMPT=" ↳ PAT code[R/W] + packaging[R]$AZ_DO_PASSWORD_SUFFIX: "

stty -echo

Expand Down Expand Up @@ -124,8 +189,16 @@ if [ -z ${AZ_DO_PAT_INPUT} ]; then
fi
fi

git remote remove azdo
git remote add azdo https://$AZ_DO_USERNAME:$AZ_DO_PAT_INPUT@devdiv.visualstudio.com/OnlineServices/_git/vsclk-core
EMPTY_STRING=""
CLEAN_ADO_ORIGIN="${ADO_REPO_URL/https\:\/\//$EMPTY_STRING}"

git remote remove github-origin &>/dev/null
git remote rename origin github-origin &>/dev/null

#git remote remove origin
git remote add origin https://$AZ_DO_USERNAME:$AZ_DO_PAT_INPUT@$CLEAN_ADO_ORIGIN

GIT_DEFAULT_BRANCH_NAME=$(git remote show origin | grep "HEAD branch\: " | sed 's/HEAD branch\: //g' | xargs)

echo -e $PALETTE_LIGHT_YELLOW"\n ⌬ Fetching the repo\n"$PALETTE_RESET

Expand All @@ -135,7 +208,9 @@ git checkout main
git branch --track github-main

# clone the AzDO repo
git pull azdo master:main --force --no-tags
git pull origin $GIT_DEFAULT_BRANCH_NAME:$GIT_DEFAULT_BRANCH_NAME --force --no-tags

git checkout $GIT_DEFAULT_BRANCH_NAME &>/dev/null

if [ "$AZ_DO_PAT" != "$AZ_DO_PAT_INPUT" ]; then
export AZ_DO_PAT=$AZ_DO_PAT_INPUT
Expand All @@ -146,25 +221,19 @@ if [ "$AZ_DO_PAT" != "$AZ_DO_PAT_INPUT" ]; then
echo -e "export AZ_DO_PAT=$AZ_DO_PAT" >> ~/.cs-envirnment
fi

if [ ! -d $CSCLIENT ]; then
echo -e $PALETTE_RED"\n ❗ Could not clone the \`vsclk-core\` repo, are the credentials correct?\n"$PALETTE_RESET
if [ ! -d $CODESPACE_DEFAULT_PATH ]; then
echo -e $PALETTE_RED"\n ❗ Could not clone the \`$ADO_REPO_URL\` repo, are the credentials correct?\n"$PALETTE_RESET
exit 1
fi

# setup NuGet feeds
FEED_NAME="vssaas-sdk"
dotnet nuget remove source $FEED_NAME
dotnet nuget add source "https://devdiv.pkgs.visualstudio.com/_packaging/vssaas-sdk/nuget/v3/index.json" -n $FEED_NAME -u "devdiv" -p "$AZ_DO_PAT" --store-password-in-clear-text
cd $CODESPACE_DEFAULT_PATH

FEED_NAME="Cascade"
dotnet nuget remove source $FEED_NAME
dotnet nuget add source "https://devdiv.pkgs.visualstudio.com/_packaging/Cascade/nuget/v3/index.json" -n $FEED_NAME -u "devdiv" -p "$AZ_DO_PAT" --store-password-in-clear-text
USER_POST_CREATE_COMMAND_FILE=~/ado-in-codespaces/.devcontainer/post-create-command.sh
if [ -f $USER_POST_CREATE_COMMAND_FILE ]; then
echo -e $PALETTE_CYAN"\n Executing the post create command..\n"$PALETTE_RESET

# go to `Website`
cd $CSCLIENT
# initialize the codespace
yarn setup:codespace
# go to `Website`
cd $CSCLIENT
. $USER_POST_CREATE_COMMAND_FILE
fi

exec bash

43 changes: 43 additions & 0 deletions .codespaces/lib/colors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

## Color variables

# Dimmed text
export PALETTE_DIM='\e[2m'

# Bold Text
export PALETTE_BOLD='\e[1m'

# Underlined Text
export PALETTE_UNDERLINED='\e[4m'

# Blinking
export PALETTE_BLINK='\e[5m'

# Reverse
export PALETTE_REVERSE='\e[7m'

# Foreground Color
export PALETTE_BLACK='\e[30m'
export PALETTE_WHITE='\e[97m'
export PALETTE_RED='\e[31m'
export PALETTE_GREEN='\e[32m'
export PALETTE_BROWN='\e[33m'
export PALETTE_BLUE='\e[34m'
export PALETTE_PURPLE='\e[35m'
export PALETTE_CYAN='\e[36m'
export PALETTE_LIGHTGRAY='\e[37m'
export PALETTE_LIGHT_YELLOW='\e[93m'

# Background Color
export PALETTE_BLACK_U='\e[40m'
export PALETTE_RED_U='\e[41m'
export PALETTE_GREEN_U='\e[42m'
export PALETTE_BROWN_U='\e[43m'
export PALETTE_BLUE_U='\e[44m'
export PALETTE_PURPLE_U='\e[45m'
export PALETTE_CYAN_U='\e[46m'
export PALETTE_LIGHTGRAY_U='\e[47m'

# Normal Text
export PALETTE_RESET='\e[0m'
139 changes: 139 additions & 0 deletions .codespaces/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# add oh-my-bash
wget https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh -O - | sh -C

# connect AzDO npm feeds
echo "
; begin auth token
//devdiv.pkgs.visualstudio.com/_packaging/VS/npm/registry/:username=devdiv
//devdiv.pkgs.visualstudio.com/_packaging/VS/npm/registry/:_password=\${AZ_DO_PAT_BASE64}
//devdiv.pkgs.visualstudio.com/_packaging/VS/npm/registry/:email=npm requires email to be set but doesn't use the value
//devdiv.pkgs.visualstudio.com/_packaging/VS/npm/:username=devdiv
//devdiv.pkgs.visualstudio.com/_packaging/VS/npm/:_password=\${AZ_DO_PAT_BASE64}
//devdiv.pkgs.visualstudio.com/_packaging/VS/npm/:email=npm requires email to be set but doesn't use the value
; end auth token
; begin auth token
//devdiv.pkgs.visualstudio.com/_packaging/NodeRepos/npm/registry/:username=devdiv
//devdiv.pkgs.visualstudio.com/_packaging/NodeRepos/npm/registry/:_password=\${AZ_DO_PAT_BASE64}
//devdiv.pkgs.visualstudio.com/_packaging/NodeRepos/npm/registry/:email=npm requires email to be set but doesn't use the value
//devdiv.pkgs.visualstudio.com/_packaging/NodeRepos/npm/:username=devdiv
//devdiv.pkgs.visualstudio.com/_packaging/NodeRepos/npm/:_password=\${AZ_DO_PAT_BASE64}
//devdiv.pkgs.visualstudio.com/_packaging/NodeRepos/npm/:email=npm requires email to be set but doesn't use the value
; end auth token
; begin auth token
//devdiv.pkgs.visualstudio.com/_packaging/Cascade/npm/registry/:username=devdiv
//devdiv.pkgs.visualstudio.com/_packaging/Cascade/npm/registry/:_password=\${AZ_DO_PAT_BASE64}
//devdiv.pkgs.visualstudio.com/_packaging/Cascade/npm/registry/:email=npm requires email to be set but doesn't use the value
//devdiv.pkgs.visualstudio.com/_packaging/Cascade/npm/:username=devdiv
//devdiv.pkgs.visualstudio.com/_packaging/Cascade/npm/:_password=\${AZ_DO_PAT_BASE64}
//devdiv.pkgs.visualstudio.com/_packaging/Cascade/npm/:email=npm requires email to be set but doesn't use the value
; end auth token
; begin auth token
//devdiv.pkgs.visualstudio.com/DevDiv/_packaging/playwright/npm/registry/:username=devdiv
//devdiv.pkgs.visualstudio.com/DevDiv/_packaging/playwright/npm/registry/:_password=\${AZ_DO_PAT_BASE64}
//devdiv.pkgs.visualstudio.com/DevDiv/_packaging/playwright/npm/registry/:email=npm requires email to be set but doesn't use the value
//devdiv.pkgs.visualstudio.com/DevDiv/_packaging/playwright/npm/:username=devdiv
//devdiv.pkgs.visualstudio.com/DevDiv/_packaging/playwright/npm/:_password=\${AZ_DO_PAT_BASE64}
//devdiv.pkgs.visualstudio.com/DevDiv/_packaging/playwright/npm/:email=npm requires email to be set but doesn't use the value
; end auth token
" >> ~/.npmrc

BASH_RC_FILE=~/.bashrc

PRE_OMB_BASH_CONFIG=~/.bashrc.pre-oh-my-bash
if [ -f $PRE_OMB_BASH_CONFIG ]; then
cat $PRE_OMB_BASH_CONFIG >> $BASH_RC_FILE
rm $PRE_OMB_BASH_CONFIG
fi

# add .bashrc config
echo "
## Color variables
# Dimmed text
export PALETTE_DIM='\e[2m'
# Bold Text
export PALETTE_BOLD='\e[1m'
# Underlined Text
export PALETTE_UNDERLINED='\e[4m'
# Blinking
export PALETTE_BLINK='\e[5m'
# Reverse
export PALETTE_REVERSE='\e[7m'
# Foreground Color
export PALETTE_BLACK='\e[30m'
export PALETTE_WHITE='\e[97m'
export PALETTE_RED='\e[31m'
export PALETTE_GREEN='\e[32m'
export PALETTE_BROWN='\e[33m'
export PALETTE_BLUE='\e[34m'
export PALETTE_PURPLE='\e[35m'
export PALETTE_CYAN='\e[36m'
export PALETTE_LIGHTGRAY='\e[37m'
export PALETTE_LIGHT_YELLOW='\e[93m'
# Background Color
export PALETTE_BLACK_U='\e[40m'
export PALETTE_RED_U='\e[41m'
export PALETTE_GREEN_U='\e[42m'
export PALETTE_BROWN_U='\e[43m'
export PALETTE_BLUE_U='\e[44m'
export PALETTE_PURPLE_U='\e[45m'
export PALETTE_CYAN_U='\e[46m'
export PALETTE_LIGHTGRAY_U='\e[47m'
# Normal Text
export PALETTE_RESET='\e[0m'
# workspace
export CODESPACE_ROOT=$(pwd)
export CODESPACE_DEFAULT_PATH="\$CODESPACE_ROOT\$ADO_REPO_DEFAULT_PATH"
alias cdroot='cd \$CODESPACE_ROOT'
alias cddefault='cd \$CODESPACE_DEFAULT_PATH'
alias do='dotnet'
alias ya='yarn'
# misc
alias code='f() {
if code-insiders -v &> /dev/null; then
code-insiders \$@;
else
code \$@;
fi
};f'
alias ls='ls --color=auto'
alias ww='watch -n 1 \"date && echo -e \ &&\"'
alias refresh='exec bash'
alias bashconfig=\"code $BASH_RC_FILE\"
alias ports='lsof -n -i -P | grep TCP'
# git
alias push='git push -u azdo HEAD'
alias pull='git pull azdo'
alias sync='pull && push'
alias fetch='git fetch azdo'
alias pullmaster='git pull azdo master'
alias branch='f() {
BRANCH_NAME=\"dev/\$AZ_DO_USERNAME/\$1\";
git pull azdo master:main --no-tags;
git branch \$BRANCH_NAME main --color;
git checkout \$BRANCH_NAME;
git push -u azdo \$BRANCH_NAME;
};f'
# change dir to the repo default folder if present (codespace is initialized),
# otherwise show the hint
if ! [ -z \$CODESPACE_DEFAULT_PATH ] 2> /dev/null && [ -d \$CODESPACE_DEFAULT_PATH ]; then
cd \$CODESPACE_DEFAULT_PATH
elif [ \$(basename \"\$0\") != 'init' ]
then
clear
echo -e \"\$PALETTE_DIM\n💡 Run\$PALETTE_BLUE ./init\$PALETTE_RESET\$PALETTE_DIM when ready.\n\$PALETTE_RESET\"
fi
" >> $BASH_RC_FILE
19 changes: 19 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

{
"$schema": "https://raw.githubusercontent.com/microsoft/vscode/master/extensions/configuration-editing/schemas/devContainer.schema.json",
"name": "ADO in GitHub Codespaces",
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [],
"remoteEnv": {
"ADO_REPO_URL": "https://devdiv.visualstudio.com/DefaultCollection/OnlineServices/_git/ado-in-codespaces-test",
"ADO_REPO_DEFAULT_PATH": "/apps/node-app",
},
/*
* Please don't change! create your own `post-create-command.sh`
* file in this folder instead, it will be called automatically
* once the Codespace is fully set up.
*/
"postCreateCommand": "/bin/sh .codespaces/post-create.sh"
}
2 changes: 2 additions & 0 deletions .devcontainer/post-create-command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# install yarn dependencies
yarn install
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Codespaces in Codespaces
# Azure DevOps in Codespaces

[<img title="Run in Codespace in one click" src="https://cdn.jsdelivr.net/gh/bookish-potato/codespaces-in-codespaces@f097ccddfc401ab6b09d233dc47c3efa3f9513f6/images/badge.svg">](https://github.com/features/codespaces)

Bootstrap script to run Codespaces Workbench in a GitHub Codespace.
Bootstrap script to run Azure DevOps repo in a GitHub Codespace.

### Use

Please follow instructions on the [vscs wiki page](https://github.com/microsoft/vssaas-planning/wiki/Codespaces-Workbench-in-a-GitHub-Codespace). Don't have access? Join the [vscode-vssaas team](https://repos.opensource.microsoft.com/microsoft/teams/vscode-vssaas) on [opensource.microsoft.com](https://repos.opensource.microsoft.com/microsoft/teams/vscode-vssaas).
TBD

### Issues/Feedback

- Feedback appreciated, create issues on [vscs planning](https://github.com/microsoft/vssaas-planning) repo if anything 🤗
- Feedback appreciated, create issues on this repo if anything 🤗
- Ping [@legomushroom](https://github.com/legomushroom) if cannot get desired support in the GitHub issues (`olsolomk` if inside Microsoft) 🏓
Loading

0 comments on commit e62caea

Please sign in to comment.