diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index f72e636..d49bf50 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -69,4 +69,78 @@ jobs: if: ${{ steps.runTest.outcome == 'success'}} run: | echo "Expected previous step to fail" - exit 1 \ No newline at end of file + exit 1 + failFastGradleTest: + name: > + Fail fast on Gradle project + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Run action on Gradle project + id: runTest + uses: ./ + continue-on-error: true + env: + SONAR_HOST_URL: http://not_actually_used + with: + projectBaseDir: ./test/gradle-project + - name: Previous should have failed + if: ${{ steps.runTest.outcome == 'success'}} + run: | + echo "Expected previous step to fail" + exit 1 + failFastMavenTest: + name: > + Fail fast on Maven project + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Run action on Maven project + id: runTest + uses: ./ + continue-on-error: true + env: + SONAR_HOST_URL: http://not_actually_used + with: + projectBaseDir: ./test/maven-project + - name: Previous should have failed + if: ${{ steps.runTest.outcome == 'success'}} + run: | + echo "Expected previous step to fail" + exit 1 + runAnalysisTest: + runs-on: ubuntu-latest + services: + sonarqube: + image: sonarqube:lts-community + ports: + - 9000:9000 + options: >- + --health-cmd "curl --fail --user admin:admin http://127.0.0.1:9000/api/system/status || exit 1" + --health-interval 10s + --health-timeout 5s + --health-retries 1000 + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - run: ./test/waitForSonarQubeUp.sh + timeout-minutes: 3 + - name: Run action on sample project + id: runTest + uses: ./ + env: + SONAR_HOST_URL: http://sonarqube:9000 + with: + args: -Dsonar.login=admin -Dsonar.password=admin + projectBaseDir: ./test/example-project + - name: Assert + run: | + if [ ! -f ./test/example-project/.scannerwork/report-task.txt ]; then + echo "Couldn't find the report task file. Analysis failed." + exit 1 + fi diff --git a/entrypoint.sh b/entrypoint.sh index 36873d1..d0b4e1e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -20,12 +20,12 @@ if [[ -n "${SONAR_ROOT_CERT}" ]]; then keytool -keystore /etc/ssl/certs/java/cacerts -storepass changeit -noprompt -trustcacerts -importcert -alias sonarqube -file /tmp/tmpcert.pem fi -if [[ -f "${INPUT_PROJECTBASEDIR%/}pom.xml" ]]; then +if [[ -f "${INPUT_PROJECTBASEDIR%/}/pom.xml" ]]; then echo "Maven project detected. You should run the goal 'org.sonarsource.scanner.maven:sonar' during build rather than using this GitHub Action." exit 1 fi -if [[ -f "${INPUT_PROJECTBASEDIR%/}build.gradle" ]]; then +if [[ -f "${INPUT_PROJECTBASEDIR%/}/build.gradle" ]]; then echo "Gradle project detected. You should use the SonarQube plugin for Gradle during build rather than using this GitHub Action." exit 1 fi diff --git a/test/run-qa.sh b/test/run-qa.sh index bf1300a..252a20e 100755 --- a/test/run-qa.sh +++ b/test/run-qa.sh @@ -60,26 +60,6 @@ if [[ $? -eq 0 ]]; then fi success "Correctly failed fast." -info "Test fail-fast on Gradle project..." -pushd test/gradle-project/ -docker run -v `pwd`:/github/workspace/ --workdir /github/workspace --network $network --env SONAR_TOKEN=$token --env SONAR_HOST_URL='http://sonarqube:9000' sonarsource/sonarqube-scan-action -if [[ $? -eq 0 ]]; then - error "Should have failed fast." - exit 1 -fi -popd -success "Correctly failed fast." - -info "Test fail-fast on Maven project..." -pushd test/maven-project/ -docker run -v `pwd`:/github/workspace/ --workdir /github/workspace --network $network --env SONAR_TOKEN=$token --env SONAR_HOST_URL='http://sonarqube:9000' sonarsource/sonarqube-scan-action -if [[ $? -eq 0 ]]; then - error "Should have failed fast." - exit 1 -fi -popd -success "Correctly failed fast." - info "Analyze project..." cd test/example-project/ docker run -v `pwd`:/github/workspace/ --workdir /github/workspace --network $network --env INPUT_PROJECTBASEDIR=/github/workspace --env SONAR_TOKEN=$token --env SONAR_HOST_URL='http://sonarqube:9000' sonarsource/sonarqube-scan-action diff --git a/test/waitForSonarQubeUp.sh b/test/waitForSonarQubeUp.sh new file mode 100755 index 0000000..8ba486b --- /dev/null +++ b/test/waitForSonarQubeUp.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Helper functions for coloring output. +info() { echo -e "\\e[36m$*\\e[0m"; } +error() { echo -e "\\e[31m✗ $*\\e[0m"; } +success() { echo -e "\\e[32m✔ $*\\e[0m"; } + +# Helper function to check if SonarQube is up and running. +check_sq_is_up() { + local statusCall="$(curl --silent --user admin:admin http://127.0.0.1:9000/api/system/status)" + local status="$(jq -r '.status' <<< "$statusCall")" + if [[ ! $? -eq 0 ]]; then + error "Failed to check if SonarQube is up and running." + exit 1 + fi + echo $status; +} + +info "Wait until SonarQube is up..." +sleep 5 +isUp=$(check_sq_is_up) +until [[ "$isUp" == "UP" ]]; do + echo $isUp + ls ./sonarqube_data + cat ./sonarqube_data/logs/sonar.log + sleep 1 + isUp=$(check_sq_is_up) +done +success "SonarQube is up and running."