diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f4ae5ea..563318a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -20,12 +20,12 @@ jobs: run: go test -v ./... - name: Build run: go build -v -o ghorg . - - name: Run GitHub Integration Tests - run: scripts/github_integration_tests.sh + - name: Run GitHub Cloud Integration Tests + run: scripts/github_cloud_integration_tests.sh env: GITHUB_TOKEN: ${{ secrets.GHORG_GITHUB_TOKEN }} - - name: Run Bitbucket Integration Tests - run: scripts/bitbucket_integration_tests.sh + - name: Run Bitbucket Cloud Integration Tests + run: scripts/bitbucket_cloud_integration_tests.sh env: BITBUCKET_TOKEN: ${{ secrets.GHORG_BITBUCKET_APP_PASSWORD }} BITBUCKET_USERNAME: ${{ secrets.GHORG_BITBUCKET_USERNAME }} @@ -53,7 +53,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GHORG_GITHUB_TOKEN }} - name: Run Bitbucket Integration Tests - run: scripts/bitbucket_integration_tests.sh + run: scripts/bitbucket_cloud_integration_tests.sh env: BITBUCKET_TOKEN: ${{ secrets.GHORG_BITBUCKET_APP_PASSWORD }} BITBUCKET_USERNAME: ${{ secrets.GHORG_BITBUCKET_USERNAME }} diff --git a/scripts/bitbucket_integration_tests.sh b/scripts/bitbucket_cloud_integration_tests.sh similarity index 100% rename from scripts/bitbucket_integration_tests.sh rename to scripts/bitbucket_cloud_integration_tests.sh diff --git a/scripts/github_integration_tests.sh b/scripts/github_cloud_integration_tests.sh similarity index 100% rename from scripts/github_integration_tests.sh rename to scripts/github_cloud_integration_tests.sh diff --git a/scripts/local-gitlab/clone.sh b/scripts/local-gitlab/clone.sh index 94198c6..35d25ef 100755 --- a/scripts/local-gitlab/clone.sh +++ b/scripts/local-gitlab/clone.sh @@ -1,16 +1,31 @@ #!/bin/bash -BASE_URL="http://gitlab.example.com" -TOKEN=${1:-'yYPQd9zVy3hvMqsuK13-'} +set -ex -ghorg clone all-groups --scm=gitlab --base-url=${BASE_URL} --token=$TOKEN --preserve-dir --output-dir=local-gitlab-v15-repos +TOKEN=$1 +GITLAB_URL=$2 -ghorg clone all-groups --scm=gitlab --base-url=${BASE_URL} --token=$TOKEN --output-dir=local-gitlab-v15-repos-flat +# run twice, once for clone then pull -ghorg clone root --clone-type=user --scm=gitlab --base-url=${BASE_URL} --token=$TOKEN --output-dir=local-gitlab-v15-root-user-repos --prune --prune-no-confirm +ghorg clone all-groups --scm=gitlab --base-url="${GITLAB_URL}" --token="$TOKEN" --preserve-dir --output-dir=local-gitlab-v15-repos +ghorg clone all-groups --scm=gitlab --base-url="${GITLAB_URL}" --token="$TOKEN" --preserve-dir --output-dir=local-gitlab-v15-repos -ghorg clone all-groups --scm=gitlab --base-url=${BASE_URL} --token=$TOKEN --backup --clone-wiki --output-dir=local-gitlab-v15-backup +ghorg clone all-groups --scm=gitlab --base-url="${GITLAB_URL}" --token="${TOKEN}" --output-dir=local-gitlab-v15-repos-flat +ghorg clone all-groups --scm=gitlab --base-url="${GITLAB_URL}" --token="${TOKEN}" --output-dir=local-gitlab-v15-repos-flat -ghorg clone group1 --scm=gitlab --base-url=${BASE_URL} --token=$TOKEN --backup --output-dir=local-gitlab-v15-group1-backup +ghorg clone root --clone-type=user --scm=gitlab --base-url="${GITLAB_URL}" --token="${TOKEN}" --output-dir=local-gitlab-v15-root-user-repos --prune --prune-no-confirm +ghorg clone root --clone-type=user --scm=gitlab --base-url="${GITLAB_URL}" --token="${TOKEN}" --output-dir=local-gitlab-v15-root-user-repos --prune --prune-no-confirm -ghorg clone group1 --scm=gitlab --base-url=${BASE_URL} --token=$TOKEN --output-dir=local-gitlab-v15-group1 +ghorg clone all-groups --scm=gitlab --base-url="${GITLAB_URL}" --token="${TOKEN}" --backup --clone-wiki --output-dir=local-gitlab-v15-backup +ghorg clone all-groups --scm=gitlab --base-url="${GITLAB_URL}" --token="${TOKEN}" --backup --clone-wiki --output-dir=local-gitlab-v15-backup + +ghorg clone group1 --scm=gitlab --base-url="${GITLAB_URL}" --token="${TOKEN}" --backup --output-dir=local-gitlab-v15-group1-backup +ghorg clone group1 --scm=gitlab --base-url="${GITLAB_URL}" --token="${TOKEN}" --backup --output-dir=local-gitlab-v15-group1-backup + +ghorg clone group1 --scm=gitlab --base-url="${GITLAB_URL}" --token="${TOKEN}" --output-dir=local-gitlab-v15-group1 +ghorg clone group1 --scm=gitlab --base-url="${GITLAB_URL}" --token="${TOKEN}" --output-dir=local-gitlab-v15-group1 + +if [ "${STOP_GITLAB_WHEN_FINISHED}" == "true" ];then + docker stop gitlab + docker rm gitlab +fi diff --git a/scripts/local-gitlab/get_credentials.sh b/scripts/local-gitlab/get_credentials.sh new file mode 100755 index 0000000..c69f967 --- /dev/null +++ b/scripts/local-gitlab/get_credentials.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +set -e + +# poll until gitlab has started + +GITLAB_URL=$1 +started="0" +counter=0 + +until [ $started -eq "1" ] +do + resp=$(curl -I -s -L "${GITLAB_URL}"/user/sign_in | grep "HTTP/1.1 200 OK" | cut -d$' ' -f2) + + if [ $counter -gt 100 ]; then + echo "GitLab isn't starting properly, exiting" + exit 1 + fi + + if [ "${resp}" = "200" ]; then + started="1" + echo "GitLab is fully up and running..." + fi + sleep 10 + ((counter++)) + echo "GitLab has not started, sleeping...count: ${counter}" +done + +set -x + +# Once running get pw with +pw=$(docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password | awk '{print $2}') + +echo "grant_type=password&username=root&password=${pw}" > auth.txt + +BEARER_TOKEN=$(curl -s --data "@auth.txt" --request POST "${GITLAB_URL}/oauth/token" | jq -r '.access_token' | tr -d '\n') + +rm auth.txt + +TOKEN_NUMS=$(echo $RANDOM) + +API_TOKEN=$(curl --request POST --header "Authorization: Bearer ${BEARER_TOKEN}" --data "name=admintoken-${TOKEN_NUMS}" --data "expires_at=2050-04-04" --data "scopes[]=api" "${GITLAB_URL}/api/v4/users/1/personal_access_tokens" | jq -r '.token' | tr -d '\n') + +# seed new instance using +./scripts/local-gitlab/seed.sh "${API_TOKEN}" "${GITLAB_URL}" diff --git a/scripts/local-gitlab/run-ee.sh b/scripts/local-gitlab/run-ee.sh index f57683e..6bf417f 100755 --- a/scripts/local-gitlab/run-ee.sh +++ b/scripts/local-gitlab/run-ee.sh @@ -9,29 +9,23 @@ # make sure 127.0.0.1 gitlab.example.com is added to your /etc/hosts -export GITLAB_IMAGE_TAG=latest -export GITLAB_HOME=$HOME/Desktop/ghorg/local-gitlab-ee-data-$GITLAB_IMAGE_TAG +GITLAB_IMAGE_TAG=$1 +GITLAB_HOME=$2 +GITLAB_HOST=$3 + +echo "" +echo "Starting fresh install of GitLab Enterprise Edition, using tag: ${GITLAB_IMAGE_TAG}" +echo "Removing any previous install at path: ${GITLAB_HOME}" +echo "" + +rm -rf "${GITLAB_HOME}" docker run \ - --hostname gitlab.example.com \ + -d=true \ + --hostname "${GITLAB_HOST}" \ --publish 443:443 --publish 80:80 --publish 22:22 \ --name gitlab \ - --restart always \ - --volume $GITLAB_HOME/config:/etc/gitlab \ - --volume $GITLAB_HOME/logs:/var/log/gitlab \ - --volume $GITLAB_HOME/data:/var/opt/gitlab \ - gitlab/gitlab-ee:$GITLAB_IMAGE_TAG - -# Once running get pw with -docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password - -# Login at - -# http://gitlab.example.com/users/sign_in -# username: root - -# Create an api token -# http://gitlab.example.com/-/profile/personal_access_tokens - -# seed new instance using -# ./scripts/local-gitlab/seed.sh $TOKEN + --volume "${GITLAB_HOME}"/config:/etc/gitlab \ + --volume "${GITLAB_HOME}"/logs:/var/log/gitlab \ + --volume "${GITLAB_HOME}"/data:/var/opt/gitlab \ + gitlab/gitlab-ee:"${GITLAB_IMAGE_TAG}" diff --git a/scripts/local-gitlab/seed.sh b/scripts/local-gitlab/seed.sh index a42bcb2..461e914 100755 --- a/scripts/local-gitlab/seed.sh +++ b/scripts/local-gitlab/seed.sh @@ -2,56 +2,58 @@ # https://docs.gitlab.com/ee/install/docker.html#install-gitlab-using-docker-engine -TOKEN=${1:-'yYPQd9zVy3hvMqsuK13-'} -BASE_URL="http://gitlab.example.com" +TOKEN=$1 +GITLAB_URL=$2 # Create 3 groups, namespace_id will start at 4 curl --request POST --header "PRIVATE-TOKEN: $TOKEN" \ --header "Content-Type: application/json" \ --data '{"path": "group1", "name": "group1" }' \ - "${BASE_URL}/api/v4/groups" + "${GITLAB_URL}/api/v4/groups" curl --request POST --header "PRIVATE-TOKEN: $TOKEN" \ --header "Content-Type: application/json" \ --data '{"path": "group2", "name": "group2" }' \ - "${BASE_URL}/api/v4/groups" + "${GITLAB_URL}/api/v4/groups" curl --request POST --header "PRIVATE-TOKEN: $TOKEN" \ --header "Content-Type: application/json" \ --data '{"path": "group3", "name": "group3" }' \ - "${BASE_URL}/api/v4/groups" + "${GITLAB_URL}/api/v4/groups" curl --request POST --header "PRIVATE-TOKEN: $TOKEN" \ --header "Content-Type: application/json" \ --data '{"path": "group4", "name": "group4" }' \ - "${BASE_URL}/api/v4/groups" + "${GITLAB_URL}/api/v4/groups" # create repos for user for ((a=0; a <= 10 ; a++)) do - curl --header "PRIVATE-TOKEN: $TOKEN" -X POST "${BASE_URL}/api/v4/projects?name=baz${a}&initialize_with_readme=true" + curl --header "PRIVATE-TOKEN: $TOKEN" -X POST "${GITLAB_URL}/api/v4/projects?name=baz${a}&initialize_with_readme=true" done # create repos in group1 for ((a=0; a <= 10 ; a++)) do - curl --header "PRIVATE-TOKEN: $TOKEN" -X POST "${BASE_URL}/api/v4/projects?name=baz${a}&namespace_id=4&initialize_with_readme=true" + curl --header "PRIVATE-TOKEN: $TOKEN" -X POST "${GITLAB_URL}/api/v4/projects?name=baz${a}&namespace_id=4&initialize_with_readme=true" done # create repos in group2 for ((a=0; a <= 10 ; a++)) do - curl --header "PRIVATE-TOKEN: $TOKEN" -X POST "${BASE_URL}/api/v4/projects?name=baz${a}&namespace_id=5&initialize_with_readme=true" + curl --header "PRIVATE-TOKEN: $TOKEN" -X POST "${GITLAB_URL}/api/v4/projects?name=baz${a}&namespace_id=5&initialize_with_readme=true" done # create repos in group3 for ((a=0; a <= 10 ; a++)) do - curl --header "PRIVATE-TOKEN: $TOKEN" -X POST "${BASE_URL}/api/v4/projects?name=baz${a}&namespace_id=6&initialize_with_readme=true" + curl --header "PRIVATE-TOKEN: $TOKEN" -X POST "${GITLAB_URL}/api/v4/projects?name=baz${a}&namespace_id=6&initialize_with_readme=true" done # create repos in group3 for ((a=0; a <= 10 ; a++)) do - curl --header "PRIVATE-TOKEN: $TOKEN" -X POST "${BASE_URL}/api/v4/projects?name=baz${a}&namespace_id=7&initialize_with_readme=true&wiki_enabled=true" + curl --header "PRIVATE-TOKEN: $TOKEN" -X POST "${GITLAB_URL}/api/v4/projects?name=baz${a}&namespace_id=7&initialize_with_readme=true&wiki_enabled=true" done + +./scripts/local-gitlab/clone.sh "${TOKEN}" "${GITLAB_URL}" diff --git a/scripts/local-gitlab/start-ee.sh b/scripts/local-gitlab/start-ee.sh new file mode 100755 index 0000000..5de6515 --- /dev/null +++ b/scripts/local-gitlab/start-ee.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +STOP_GITLAB_WHEN_FINISHED=${1:-'true'} +GITLAB_IMAGE_TAG=${2:-'latest'} +GITLAB_HOME=${3:-"$HOME/Desktop/ghorg/local-gitlab-ee-data-${GITLAB_IMAGE_TAG}"} +GITLAB_HOST=${4:-'gitlab.example.com'} +GITLAB_URL=${5:-'http://gitlab.example.com'} + +if [ "${ENV}" == "ci" ];then + echo "127.0.0.1 gitlab.example.com" >> /etc/hosts +fi + +if [ "${STOP_GITLAB_WHEN_FINISHED}" == "true" ];then + export STOP_GITLAB_WHEN_FINISHED=true +fi + +docker stop gitlab +docker rm gitlab + +echo "" +echo "To follow gitlab container logs use the following command in a new window" +echo "$ docker logs -f gitlab" +echo "" +./scripts/local-gitlab/run-ee.sh "${GITLAB_IMAGE_TAG}" "${GITLAB_HOME}" "${GITLAB_HOST}" +./scripts/local-gitlab/get_credentials.sh "${GITLAB_URL}"