From 30ca6dd5d0b3dcae9fec153e9f7312a9306fd838 Mon Sep 17 00:00:00 2001 From: gabrie30 Date: Tue, 9 Jul 2024 18:07:00 -0700 Subject: [PATCH] Add gitlab integration tests (#434) --- .../workflows/gitlab-ee-integration-tests.yml | 28 +++ .github/workflows/go-build-test.yml | 107 +++++---- scripts/gitlab_cloud_integration_tests.sh | 19 ++ scripts/local-gitlab/get_credentials.sh | 4 +- scripts/local-gitlab/integration-tests.sh | 213 ++++++++++++++++-- scripts/local-gitlab/run-ee.sh | 12 +- scripts/local-gitlab/seed.sh | 166 ++++++++++++-- scripts/local-gitlab/start-ee.sh | 2 +- 8 files changed, 449 insertions(+), 102 deletions(-) create mode 100644 .github/workflows/gitlab-ee-integration-tests.yml diff --git a/.github/workflows/gitlab-ee-integration-tests.yml b/.github/workflows/gitlab-ee-integration-tests.yml new file mode 100644 index 00000000..7cf46336 --- /dev/null +++ b/.github/workflows/gitlab-ee-integration-tests.yml @@ -0,0 +1,28 @@ +name: Run GitLab EE Integration Tests +on: [pull_request] +jobs: + gitlab_ee_integration_tests: + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: "^1.20" + - name: Check out code + uses: actions/checkout@v2 + - name: Install Go dependencies and build the project + run: | + go mod download + go install . + - name: Add Go binaries to PATH + run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH + - name: Set up Docker + uses: docker-practice/actions-setup-docker@master + - name: Add hosts to /etc/hosts + run: | + sudo echo "127.0.0.1 gitlab.example.com" | sudo tee -a /etc/hosts + - name: Run GitLab Integration Test + run: | + echo "Using ghorg version: $(ghorg version)" + export GHORG_GHA_CI=true + ./scripts/local-gitlab/start-ee.sh diff --git a/.github/workflows/go-build-test.yml b/.github/workflows/go-build-test.yml index 28796fdf..7ad085e6 100644 --- a/.github/workflows/go-build-test.yml +++ b/.github/workflows/go-build-test.yml @@ -1,6 +1,6 @@ # Running locally https://yonatankra.com/how-to-test-github-actions-locally-using-act/ name: Go -on: [push, pull_request] +on: pull_request jobs: build_and_test: environment: actions @@ -10,61 +10,60 @@ jobs: matrix: os: [macos-latest, ubuntu-latest] steps: - - name: Set up Go 1.22 - uses: actions/setup-go@v1 - with: - go-version: 1.22 - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - name: Test - run: go test -v ./... - - name: Build - run: go build -v -o ghorg . - - name: Run GitHub Cloud Integration Tests - run: scripts/github_cloud_integration_tests.sh - env: - GITHUB_TOKEN: ${{ secrets.GHORG_GITHUB_TOKEN }} - - 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 }} - - name: Run GitLab Cloud Integration Tests - run: scripts/gitlab_cloud_integration_tests.sh - env: - GITLAB_TOKEN: ${{ secrets.GHORG_GITLAB_TOKEN }} - + - name: Set up Go 1.22 + uses: actions/setup-go@v1 + with: + go-version: 1.22 + id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + - name: Test + run: go test -v ./... + - name: Build + run: go build -v -o ghorg . + - name: Run GitHub Cloud Integration Tests + run: scripts/github_cloud_integration_tests.sh + env: + GITHUB_TOKEN: ${{ secrets.GHORG_GITHUB_TOKEN }} + - 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 }} + - name: Run GitLab Cloud Integration Tests + run: scripts/gitlab_cloud_integration_tests.sh + env: + GITLAB_TOKEN: ${{ secrets.GHORG_GITLAB_TOKEN }} build_and_test_windows: environment: actions name: Build and Test Windows runs-on: windows-latest steps: - - name: Set up Go 1.22 - uses: actions/setup-go@v1 - with: - go-version: 1.22 - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - name: Set configuration file - run: | - mkdir C:\Users\runneradmin\.config\ghorg - copy sample-conf.yaml C:\Users\runneradmin\.config\ghorg\conf.yaml - - name: Build - run: env GOOS=windows GOARCH=386 go build -v -o ghorg.exe . - - name: Test - run: go test -v ./... - - name: Run GitHub Integration Tests - run: scripts/windows_github_integration_tests.bat - env: - GITHUB_TOKEN: ${{ secrets.GHORG_GITHUB_TOKEN }} - - name: Run Bitbucket Integration Tests - run: scripts/bitbucket_cloud_integration_tests.sh - env: - BITBUCKET_TOKEN: ${{ secrets.GHORG_BITBUCKET_APP_PASSWORD }} - BITBUCKET_USERNAME: ${{ secrets.GHORG_BITBUCKET_USERNAME }} - - name: Run GitLab Cloud Integration Tests - run: scripts/gitlab_cloud_integration_tests.sh - env: - GITLAB_TOKEN: ${{ secrets.GHORG_GITLAB_TOKEN }} + - name: Set up Go 1.22 + uses: actions/setup-go@v1 + with: + go-version: 1.22 + id: go + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + - name: Set configuration file + run: | + mkdir C:\Users\runneradmin\.config\ghorg + copy sample-conf.yaml C:\Users\runneradmin\.config\ghorg\conf.yaml + - name: Build + run: env GOOS=windows GOARCH=386 go build -v -o ghorg.exe . + - name: Test + run: go test -v ./... + - name: Run GitHub Integration Tests + run: scripts/windows_github_integration_tests.bat + env: + GITHUB_TOKEN: ${{ secrets.GHORG_GITHUB_TOKEN }} + - name: Run Bitbucket Integration Tests + run: scripts/bitbucket_cloud_integration_tests.sh + env: + BITBUCKET_TOKEN: ${{ secrets.GHORG_BITBUCKET_APP_PASSWORD }} + BITBUCKET_USERNAME: ${{ secrets.GHORG_BITBUCKET_USERNAME }} + - name: Run GitLab Cloud Integration Tests + run: scripts/gitlab_cloud_integration_tests.sh + env: + GITLAB_TOKEN: ${{ secrets.GHORG_GITLAB_TOKEN }} \ No newline at end of file diff --git a/scripts/gitlab_cloud_integration_tests.sh b/scripts/gitlab_cloud_integration_tests.sh index e95640c8..83122c2b 100755 --- a/scripts/gitlab_cloud_integration_tests.sh +++ b/scripts/gitlab_cloud_integration_tests.sh @@ -95,6 +95,25 @@ else exit 1 fi +# SNIPPETS +# ghorg clone $GITLAB_GROUP_2 --token="${GITLAB_TOKEN}" --scm=gitlab --clone-snippets --preserve-dir + +# if [ -e "${HOME}"/ghorg/"${GITLAB_GROUP_2}"/subgroup-2/foobar.snippets/test-snippet-2-3711655 ] +# then +# echo "Pass: gitlab group clone snippet 2 with preserve dir" +# else +# echo "Fail: gitlab group clone snippet 2 with preserve dir" +# exit 1 +# fi + +# if [ -e "${HOME}"/ghorg/"${GITLAB_GROUP_2}"/subgroup-2/foobar.snippets/test-snippet-1-3711654 ] +# then +# echo "Pass: gitlab group clone snippet 1 with preserve dir" +# else +# echo "Fail: gitlab group clone snippet 1 with preserve dir" +# exit 1 +# fi + # # SUBGROUP TESTS # diff --git a/scripts/local-gitlab/get_credentials.sh b/scripts/local-gitlab/get_credentials.sh index 4df85ab6..3f2a5a4c 100755 --- a/scripts/local-gitlab/get_credentials.sh +++ b/scripts/local-gitlab/get_credentials.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -xv # poll until gitlab has started @@ -29,7 +29,7 @@ done set -x -docker exec -it gitlab gitlab-rails runner "token = User.find_by_username('root').personal_access_tokens.create(scopes: [:api, :read_api, :sudo], name: 'CI Test Token'); token.set_token('password'); token.save!" +docker exec gitlab gitlab-rails runner "token = User.find_by_username('root').personal_access_tokens.create(scopes: [:api, :read_api, :sudo], name: 'CI Test Token', expires_at: 365.days.from_now); token.set_token('password'); token.save!" API_TOKEN="password" diff --git a/scripts/local-gitlab/integration-tests.sh b/scripts/local-gitlab/integration-tests.sh index d03bcd9a..0749f462 100755 --- a/scripts/local-gitlab/integration-tests.sh +++ b/scripts/local-gitlab/integration-tests.sh @@ -1,12 +1,22 @@ #!/bin/bash -set -ex +set -xv + +LOCAL_GITLAB_GHORG_DIR=${1:-"${HOME}/ghorg"} +TOKEN=${2:-'password'} +GITLAB_URL=${3:-'http://gitlab.example.com'} + + +# Delete all folders that start with local-gitlab-v15- in the LOCAL_GITLAB_GHORG_DIR +for dir in "${LOCAL_GITLAB_GHORG_DIR}"/local-gitlab-*; do + if [ -d "$dir" ]; then + rm -rf "$dir" + fi +done -TOKEN=${1:-'password'} -GITLAB_URL=${2:-'http://gitlab.example.com'} -LOCAL_GITLAB_GHORG_DIR=${3:-"${HOME}/ghorg"} export GHORG_INSECURE_GITLAB_CLIENT=true +# export GHORG_DEBUG=true # NOTE run all clones twice to test once for clone then pull @@ -36,7 +46,7 @@ EOF if [ "${WANT}" != "${GOT}" ] then -echo "CLONE AND TEST ALL-GROUPS, PRESERVE DIR, OUTPUT DIR TEST FAILED" +echo "CLONE AND TEST ALL-GROUPS, PRESERVE DIR, OUTPUT DIR TEST FAILED local-gitlab-group1" exit 1 fi @@ -51,7 +61,7 @@ EOF if [ "${WANT}" != "${GOT}" ] then -echo "CLONE AND TEST ALL-GROUPS, PRESERVE DIR, OUTPUT DIR TEST FAILED" +echo "CLONE AND TEST ALL-GROUPS, PRESERVE DIR, OUTPUT DIR TEST FAILED local-gitlab-group2" exit 1 fi @@ -67,7 +77,7 @@ EOF if [ "${WANT}" != "${GOT}" ] then -echo "CLONE AND TEST ALL-GROUPS, PRESERVE DIR, OUTPUT DIR TEST FAILED" +echo "CLONE AND TEST ALL-GROUPS, PRESERVE DIR, OUTPUT DIR TEST FAILED local-gitlab-group3/subgroup-a" exit 1 fi @@ -77,7 +87,6 @@ ghorg clone all-groups --scm=gitlab --base-url="${GITLAB_URL}" --token="${TOKEN} GOT=$( ghorg ls local-gitlab-v15-repos-flat | grep -o 'local-gitlab-v15-repos-flat.*') WANT=$(cat <