From 8d4e0706784273402dfda1e01515f6e250c9f98c Mon Sep 17 00:00:00 2001 From: "antoine.vinot" Date: Mon, 13 May 2024 11:23:03 +0200 Subject: [PATCH] WIP - Add QA --- .github/workflows/qa.yml | 100 +++++++++++++++++++++++++++++++ Dockerfile | 2 +- test/assertFileContains | 10 ++++ test/assertFileExists | 8 +++ test/gradle-project/build.gradle | 1 + test/maven-project/pom.xml | 1 + test/run-qa.sh | 8 +++ 7 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/qa.yml create mode 100644 test/assertFileContains create mode 100644 test/assertFileExists create mode 100644 test/gradle-project/build.gradle create mode 100644 test/maven-project/pom.xml create mode 100644 test/run-qa.sh diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml new file mode 100644 index 0000000..ccaddd5 --- /dev/null +++ b/.github/workflows/qa.yml @@ -0,0 +1,100 @@ +name: QA + +on: [push, pull_request] + +jobs: + argsInputTest: + name: > + 'args' input + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Run action with args + uses: ./ + with: + args: -Dsonar.someArg=aValue -Dsonar.scanner.dumpToFile=./output.properties + env: + SONAR_TOKEN: FAKE_TOKEN + - name: Assert + run: | + ./test/assertFileContains ./output.properties "sonar.someArg=aValue" + projectBaseDirInputTest: + name: > + 'projectBaseDir' input + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - run: mkdir -p ./baseDir + - name: Run action with projectBaseDir + uses: ./ + with: + args: -Dsonar.scanner.dumpToFile=./output.properties + projectBaseDir: ./baseDir + env: + SONAR_TOKEN: FAKE_TOKEN + - name: Assert + run: | + ./test/assertFileContains ./output.properties "sonar.projectBaseDir=.*/baseDir" +# sonarHostUrlRequiredTest: +# name: > +# 'SONAR_HOST_URL' is required +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v4 +# with: +# token: ${{ secrets.GITHUB_TOKEN }} +# - name: Run action without SONAR_HOST_URL +# id: runTest +# uses: ./ +# continue-on-error: true +# - name: Previous should have failed +# if: ${{ steps.runTest.outcome == 'success'}} +# run: | +# echo "Expected previous step to fail" +# 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_TOKEN: FAKE_TOKEN + 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_TOKEN: FAKE_TOKEN + with: + projectBaseDir: ./test/maven-project + - name: Previous should have failed + if: ${{ steps.runTest.outcome == 'success'}} + run: | + echo "Expected previous step to fail" + exit 1 diff --git a/Dockerfile b/Dockerfile index 7f0d45f..634634f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM sonarsource/sonar-scanner-cli:5.0 +FROM sonarsource/sonar-scanner-cli:5.0.1 LABEL version="0.0.1" \ repository="https://github.com/sonarsource/sonarcloud-github-action" \ diff --git a/test/assertFileContains b/test/assertFileContains new file mode 100644 index 0000000..69380e1 --- /dev/null +++ b/test/assertFileContains @@ -0,0 +1,10 @@ +#!/bin/bash + +error() { echo -e "\\e[31m✗ $*\\e[0m"; } + +assertFileExists $1 + +if ! grep -q $2 $1; then + error "'$2' not found in '$1'" + exit 1 +fi \ No newline at end of file diff --git a/test/assertFileExists b/test/assertFileExists new file mode 100644 index 0000000..8f04686 --- /dev/null +++ b/test/assertFileExists @@ -0,0 +1,8 @@ +#!/bin/bash + +error() { echo -e "\\e[31m✗ $*\\e[0m"; } + +if [ ! -f $1 ]; then + error "File '$1' not found" + exit 1 +fi \ No newline at end of file diff --git a/test/gradle-project/build.gradle b/test/gradle-project/build.gradle new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/gradle-project/build.gradle @@ -0,0 +1 @@ + diff --git a/test/maven-project/pom.xml b/test/maven-project/pom.xml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/maven-project/pom.xml @@ -0,0 +1 @@ + diff --git a/test/run-qa.sh b/test/run-qa.sh new file mode 100644 index 0000000..25d0240 --- /dev/null +++ b/test/run-qa.sh @@ -0,0 +1,8 @@ +#!/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"; } + +info "Work in progress..."