SONAR-14822 Write an IT
This commit is contained in:
parent
71de302835
commit
8ba0f61ef0
|
@ -0,0 +1,18 @@
|
||||||
|
name: QA
|
||||||
|
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
run_qa:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- run: ./test/run-qa.sh
|
||||||
|
timeout-minutes: 5
|
||||||
|
services:
|
||||||
|
sonarqube:
|
||||||
|
image: sonarqube:8.9-community
|
||||||
|
ports:
|
||||||
|
- 9000:9000
|
|
@ -0,0 +1,2 @@
|
||||||
|
sonar.projectKey=foo
|
||||||
|
sonar.sources=src/
|
|
@ -0,0 +1,5 @@
|
||||||
|
function main() {
|
||||||
|
console.log("Hello World");
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
|
@ -0,0 +1,68 @@
|
||||||
|
#!/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 "Build scanner action..."
|
||||||
|
docker build --no-cache -t sonarsource/sonarqube-scan-action .
|
||||||
|
if [[ ! $? -eq 0 ]]; then
|
||||||
|
error "Failed to build the scanner action."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
success "Scanner action built."
|
||||||
|
|
||||||
|
info "Find the network SonarQube is running on..."
|
||||||
|
network=$(docker network ls -f 'name=github_network' --format "{{.Name}}")
|
||||||
|
if [[ $network != "github_network_"* ]]; then
|
||||||
|
error "Failed to find the local Docker network."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
success "Found the network ($network)."
|
||||||
|
|
||||||
|
info "Wait until SonarQube is up..."
|
||||||
|
sleep 10
|
||||||
|
isUp=$(check_sq_is_up)
|
||||||
|
until [[ "$isUp" == "UP" ]]; do
|
||||||
|
sleep 1
|
||||||
|
isUp=$(check_sq_is_up)
|
||||||
|
done
|
||||||
|
success "SonarQube is up and running."
|
||||||
|
|
||||||
|
info "Generate a new token..."
|
||||||
|
tokenCall=$(curl --silent --user admin:admin -d "name=token" http://127.0.0.1:9000/api/user_tokens/generate)
|
||||||
|
token="$(jq -r '.token' <<< "$tokenCall")"
|
||||||
|
if [[ -z "$token" ]]; then
|
||||||
|
error "Failed to generate a new token."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
success "New token generated."
|
||||||
|
|
||||||
|
info "Analyze project..."
|
||||||
|
cd test/example-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 "Couldn't run the analysis."
|
||||||
|
exit 1
|
||||||
|
elif [[ ! -f ".scannerwork/report-task.txt" ]]; then
|
||||||
|
error "Couldn't find the report task file. Analysis failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
success "Analysis successful."
|
||||||
|
|
||||||
|
echo "" # new line
|
||||||
|
echo "============================"
|
||||||
|
echo "" # new line
|
||||||
|
success "QA successful!"
|
Loading…
Reference in New Issue