Skip to content

Commit

Permalink
Merge pull request #279 from aztfmod/patch.local
Browse files Browse the repository at this point in the history
Add support for Rover ignite bootstrap from local git clone
  • Loading branch information
arnaudlh authored Aug 2, 2022
2 parents 897d553 + 222480c commit 4432c52
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
3 changes: 1 addition & 2 deletions scripts/lib/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ assert_gitops_session() {

case "${1}" in
"github")
GITOPS_SERVER_URL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}
AGENT_TOKEN=$(gh api --method POST -H "Accept: application/vnd.github.v3+json" /repos/${GITHUB_REPOSITORY}/actions/runners/registration-token | jq -r .token)
check_github_session
AGENT_TOKEN=$(gh api --method POST -H "Accept: application/vnd.github.v3+json" /repos/${git_org_project}/actions/runners/registration-token | jq -r .token)
;;
"tfcloud")
GITOPS_SERVER_URL="https://${TF_VAR_tf_cloud_hostname}"
Expand Down
44 changes: 42 additions & 2 deletions scripts/lib/github.com.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,55 @@
check_github_session() {
debug "github"
set -e
information "@call check_github_session"
url=$(git config --get remote.origin.url)
export git_org_project=$(echo "$url" | sed -e 's#^https://github.com/##; s#^[email protected]:##; s#.git$##')
export git_project=$(basename -s .git $(git config --get remote.origin.url))
success "Connected to GiHub: repos/${git_org_project}"
project=$(/usr/bin/gh api "repos/${git_org_project}" 2>/dev/null | jq -r .id)
export GITOPS_SERVER_URL=$(/usr/bin/gh api "repos/${git_org_project}" 2>/dev/null | jq -r .svn_url)
debug "${project}"

verify_github_secret "actions" "BOOTSTRAP_TOKEN"

if [ ! -v ${CODESPACES} ]; then
verify_github_secret "codespaces" "GH_TOKEN"
fi

verify_git_settings "git config --global user.name"
verify_git_settings "git config --global user.email"

/usr/bin/gh auth status
}

verify_git_settings(){
information "@call verify_git_settings for ${1}"

command=${1}
eval ${command}

RETURN_CODE=$?
if [ $RETURN_CODE != 0 ]; then
error ${LINENO} "You need to set a value for ${command} before running the rover bootstrap." $RETURN_CODE
fi
}

verify_github_secret() {
information "@call verify_github_secret for ${1}/${2}"

application=${1}
secret_name=${2}

/usr/bin/gh secret list -a ${application} | grep "${secret_name}"

RETURN_CODE=$?

echo "return code ${RETURN_CODE}"

set -e
if [ $RETURN_CODE != 0 ]; then
error ${LINENO} "You need to set the ${application}/${secret_name} in your project as per instructions in the documentation." $RETURN_CODE
fi
}

register_github_secret() {
debug "@call register_github_secret for ${1}"

Expand Down

0 comments on commit 4432c52

Please sign in to comment.