diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index d130897..fe67d72 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -20,16 +20,25 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Build the Docker image + - name: Build the container image run: docker build --build-arg="IMAGE_EDITION=${{ matrix.env.IMAGE_EDITION }}" -t ci . - - name: Run the Docker image - run: docker run -d --name ci ci + - name: Run the container with tests volume + run: docker run -v $(pwd)/tests:/tests -d --name ci ci - - name: Verify the Docker image + - name: Wait for Sonar instance to start # profile for language 'web' is the last; assume everything is working if we got this far run: docker logs -f ci |& sed "/Current profile for language 'web' is 'Sonar way'/ q" timeout-minutes: 3 - - name: Stop the Docker image + - name: Install python and pip packages + run: | + docker exec -u 0:0 ci apt-get update + docker exec -u 0:0 ci apt-get install -y python3 python3-pip + docker exec -u 0:0 ci pip3 install -Ur /tests/requirements.txt + + - name: Run tests + run: docker exec -u 0:0 ci python3 /tests/test.py + + - name: Stop the container run: docker stop ci diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 0000000..45713d5 --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,2 @@ +python-sonarqube-api >= 2.0 +requests >= 2.31 diff --git a/tests/test.py b/tests/test.py new file mode 100644 index 0000000..0b32c4e --- /dev/null +++ b/tests/test.py @@ -0,0 +1,13 @@ +from os import getenv + +from sonarqube import SonarQubeClient + +sonar_port = getenv("SONAR_PORT", "9000") +sonar_base_url = f"http://localhost:{sonar_port}" +sonar_pass = getenv("SONARQUBE_PASSWORD", "admin") + +sonar = SonarQubeClient(sonarqube_url=sonar_base_url, username="admin", password=sonar_pass) +java_quality_profiles = sonar.qualityprofiles.search_quality_profiles(language="java") +java_profile_names = [profile["name"] for profile in java_quality_profiles["profiles"]] + +assert "Sonar way" in java_profile_names