-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Taucher2003/integration-test
Implement Integration test
- Loading branch information
Showing
6 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Run Integration test | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
integration-test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
gitlab_version: | ||
- 16.5.2-ce.0 | ||
- 16.4.2-ce.0 | ||
- 16.3.6-ce.0 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: GITLAB_CE_VERSION=${{ matrix.gitlab_version }} docker compose up -d | ||
working-directory: test | ||
- run: test/await_healthy.sh | ||
- uses: ./ | ||
name: Run test | ||
with: | ||
GL_SERVER_URL: http://172.17.0.1:8080 | ||
GL_PROJECT_ID: '1000' | ||
GL_RUNNER_TOKEN: some_long_runner_token | ||
GL_API_TOKEN: TEST1234567890123456 | ||
- run: 'curl --silent --header "Private-Token: TEST1234567890123456" "http://127.17.0.1:8080/api/v4/projects/1000/jobs/1/trace"' | ||
if: always() | ||
- run: docker compose down | ||
if: always() | ||
working-directory: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
job: | ||
script: | ||
- echo $CI_COMMIT_SHA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
CONTAINER_ENGINE="${CONTAINER_ENGINE:-docker}" | ||
GITLAB_BASE_URL="${GITLAB_BASE_URL:-http://127.0.0.1:8080}" | ||
|
||
set -e | ||
|
||
if [ "$CONTAINER_ENGINE" != "docker" ]; then | ||
echo "Using container engine $CONTAINER_ENGINE" | ||
fi | ||
|
||
printf 'Waiting for GitLab container to become healthy' | ||
|
||
until test -n "$($CONTAINER_ENGINE ps --quiet --filter label=gitlab-pipeline-action/owned --filter health=healthy)"; do | ||
printf '.' | ||
sleep 5 | ||
done | ||
|
||
echo | ||
echo "GitLab is healthy at $GITLAB_BASE_URL" | ||
|
||
# Print the version, since it is useful debugging information. | ||
curl --silent --show-error --header "Private-Token: TEST1234567890123456" "$GITLAB_BASE_URL/api/v4/version" | ||
|
||
echo | ||
printf 'Waiting for Test project to be imported' | ||
|
||
import_status="" | ||
while [[ "$import_status" != "finished" ]]; do | ||
printf '.' | ||
import_status=$(curl --silent --show-error --header "Private-Token: TEST1234567890123456" "$GITLAB_BASE_URL/api/v4/projects/1000" | jq -r .import_status) | ||
sleep 5 | ||
done | ||
|
||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
services: | ||
gitlab-ce: | ||
image: gitlab/gitlab-ce:${GITLAB_CE_VERSION:-latest} | ||
restart: always | ||
ports: | ||
- 8080:80 | ||
environment: | ||
GITLAB_ROOT_PASSWORD: routrout | ||
GITLAB_OMNIBUS_CONFIG: | | ||
external_url 'http://127.0.0.1:8080' | ||
nginx[:listen_port] = 80 | ||
labels: | ||
gitlab-pipeline-action/owned: '' | ||
volumes: | ||
- ./healthcheck_and_setup.sh:/healthcheck_and_setup.sh:Z | ||
healthcheck: | ||
test: /healthcheck_and_setup.sh | ||
interval: 10s | ||
timeout: 3m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env sh | ||
|
||
# This script is intended to be used as a Docker HEALTHCHECK for the GitLab container. | ||
# It prepares GitLab prior to running tests. | ||
# | ||
# This is a known workaround for docker-compose lacking lifecycle hooks. | ||
# See: https://github.com/docker/compose/issues/1809#issuecomment-657815188 | ||
|
||
set -e | ||
|
||
# Check for a successful HTTP status code from GitLab. | ||
curl --silent --show-error --fail --output /dev/null 127.0.0.1:80 | ||
|
||
# Because this script runs on a regular health check interval, | ||
# this file functions as a marker that tells us if initialization already finished. | ||
done=/var/gitlab-test-initialized | ||
|
||
test -f $done || { | ||
echo 'Initializing GitLab for tests' | ||
|
||
echo 'Creating access token' | ||
( | ||
printf 'token = PersonalAccessToken.create(' | ||
printf 'user_id: 1, ' | ||
printf 'scopes: [:api, :write_repository], ' | ||
printf 'expires_at: Time.now + 30.days, ' | ||
printf 'name: :token);' | ||
printf "token.set_token('TEST1234567890123456');" | ||
printf 'token.save!;' | ||
|
||
printf 'settings = ApplicationSetting.current;' | ||
printf 'settings.import_sources << "git";' | ||
printf 'settings.save!;' | ||
|
||
printf 'Projects::CreateService.new(User.find(1), {' | ||
printf 'namespace_id: User.first.namespace.id,' | ||
printf 'name: "Test",' | ||
printf 'path: "test",' | ||
printf 'ci_config_path: "test/.gitlab-ci.yml",' | ||
printf 'id: 1000,' | ||
printf 'import_type: "git",' | ||
printf 'import_url: "https://github.com/Taucher2003/Gitlab-Pipeline-Action.git"' | ||
printf '}).execute;' | ||
|
||
printf 'Ci::Runners::CreateRunnerService.new(' | ||
printf 'user: User.first,' | ||
printf 'params: {' | ||
printf 'runner_type: "instance_type",' | ||
printf 'token: "some_long_runner_token"' | ||
printf '}' | ||
printf ').execute;' | ||
|
||
printf 'Ci::ChangeVariableService.new(' | ||
printf 'container: Project.find(1000),' | ||
printf 'current_user: User.first,' | ||
printf 'params: { action: :create, variable_params: { key: "GIT_STRATEGY", value: "none", protected: false } }' | ||
printf ').execute;' | ||
) | gitlab-rails console | ||
|
||
touch $done | ||
} | ||
|
||
echo 'GitLab is ready for tests' |