Skip to content

Commit

Permalink
WIP - Add QA
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine-vinot-sonarsource committed May 15, 2024
1 parent 1988863 commit 4808ae2
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 2 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
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"
run: |
if ! grep -q "sonar.someArg=aValue" ./output.properties; then
error "'sonar.someArg=aValue' not found in '/output.properties'"
exit 1
fi
projectBaseDirInputTest:
name: >
'projectBaseDir' input
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- run: |
mkdir -p ./baseDir
ls -la
- name: Run action with projectBaseDir
uses: ./
with:
args: -Dsonar.scanner.dumpToFile=./output.properties
projectBaseDir: ./baseDir
env:
SONAR_TOKEN: FAKE_TOKEN
- name: Assert
run: |
ls -la ./test
./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
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" \
Expand All @@ -25,4 +25,3 @@ RUN chmod +x /entrypoint.sh
COPY cleanup.sh /cleanup.sh
RUN chmod +x /cleanup.sh
ENTRYPOINT ["/entrypoint.sh"]

10 changes: 10 additions & 0 deletions test/assertFileContains
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test/assertFileExists
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/gradle-project/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions test/maven-project/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

8 changes: 8 additions & 0 deletions test/run-qa.sh
Original file line number Diff line number Diff line change
@@ -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..."

0 comments on commit 4808ae2

Please sign in to comment.