Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/build_jar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Build JAR on Release

on:
release:
types: [published] # Solo al publicar una release
workflow_dispatch:

jobs:
build:
name: Build and Attach Executable JAR
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- name: Checkout
uses: actions/checkout@v4
- id: detect-java
name: Detect Java from pom.xml
run: |
set -euo pipefail
FILE=pdf-generator/pom.xml
# Intenta leer las propiedades estándar del compiler plugin
REL=$(mvn -f "$FILE" -q -DforceStdout help:evaluate -Dexpression=maven.compiler.release || true)
SRC=$(mvn -f "$FILE" -q -DforceStdout help:evaluate -Dexpression=maven.compiler.source || true)
TGT=$(mvn -f "$FILE" -q -DforceStdout help:evaluate -Dexpression=maven.compiler.target || true)

clean() { echo "$1" | grep -E '^[0-9]+$' || true; }
REL=$(clean "$REL"); SRC=$(clean "$SRC"); TGT=$(clean "$TGT")

VER="${REL:-${TGT:-${SRC:-17}}}"
echo "version=$VER" >> "$GITHUB_OUTPUT"
echo "Detected Java version: $VER"

- name: Set up Temurin JDK (auto)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ steps.detect-java.outputs.version }}
cache: maven

- name: Build with Maven (pdf-generator)
run: |
set -euo pipefail
mvn -f pdf-generator/pom.xml -B -DskipTests clean package
JAR_WITH_DEPS=$(ls -1 pdf-generator/target/*-jar-with-dependencies.jar | head -n 1)
if [ -z "${JAR_WITH_DEPS:-}" ]; then
echo "No se encontró el JAR con dependencias (sufijo -jar-with-dependencies.jar)"; exit 1
fi
echo "ARTIFACT_PATH=${JAR_WITH_DEPS}" >> "$GITHUB_ENV"

- name: Rename artifact using release tag (or manual)
run: |
TAG="${{ github.event.release.tag_name || 'manual' }}"
OUT="sonar-report-${TAG}.jar"
cp "$ARTIFACT_PATH" "$OUT"
echo "OUT=${OUT}" >> "$GITHUB_ENV"

- name: Upload workflow artifact (optional)
uses: actions/upload-artifact@v4
with:
name: ${{ env.OUT }}
path: ${{ env.OUT }}
if-no-files-found: error
retention-days: 14

- name: Attach JAR to GitHub Release
if: ${{ github.event_name == 'release' }}
uses: softprops/action-gh-release@v2
with:
files: ${{ env.OUT }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
222 changes: 222 additions & 0 deletions .github/workflows/check_calls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
name: SonarQube API health check

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
workflow_dispatch:

jobs:
sonarqube-api:
runs-on: ubuntu-latest
services:
sonarqube:
image: sonarqube:latest
ports:
- 9000:9000
options: >-
--health-cmd="curl -f http://localhost:9000/api/system/status || exit 1"
--health-interval=10s
--health-timeout=5s
--health-retries=60

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Wait for sonar to be up
run: |
for i in {1..120}; do
STATUS=$(curl -s http://localhost:9000/api/system/status | jq -r '.status' || true)
if [ "$STATUS" = "UP" ]; then echo "SonarQube UP"; break; fi
echo "Status: $STATUS..."
sleep 5
done

- name: Create temporal admin token
run: |
export TOKEN_NAME="ci-token-$(date +%s)"
AUTH="-u admin:admin"
curl -sS $AUTH -X POST "http://localhost:9000/api/user_tokens/generate?name=$TOKEN_NAME" | jq -r '.token' > token.txt
echo "SONAR_TOKEN=$(cat token.txt)" >> $GITHUB_ENV

- name: Prepare Dummy Project
run: |
mkdir -p dummy
echo 'console.log(eval("1+1"))' > dummy/index.js
cat > dummy/sonar-project.properties << 'EOF'
sonar.projectKey=dummy.project
sonar.projectName=Dummy Project
sonar.sources=.
sonar.exclusions=**/*
sonar.token=${SONAR_TOKEN}
sonar.host.url=http://localhost:9000
EOF

- name: Install Sonar Scanner
run: |
sudo apt-get update -y
sudo apt-get install -y unzip default-jre
curl -L -o scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip
unzip scanner.zip
SCANNER_DIR=$(find . -type d -name "sonar-scanner-*" | head -n 1)
echo "$SCANNER_DIR/bin" >> $GITHUB_PATH

- name: Run Sonar Scanner
run: |
./sonar-scanner-*/bin/sonar-scanner \
-Dsonar.projectKey=dummy.project \
-Dsonar.sources=. \
-Dsonar.exclusions=**/* \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=${{ env.SONAR_TOKEN }}

- name: API Testing
env:
SONAR_TOKEN: ${{ env.SONAR_TOKEN }}
run: |
set -euo pipefail
AUTH="Authorization: Basic $(echo -n ${SONAR_TOKEN}: | base64 -w0)"
response=$(mktemp)

#/api/navigation/component?component=
url="http://localhost:9000/api/navigation/component?component=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"

#/api/measures/component?metricKeys=reliability_rating,software_quality_maintainability_rating,security_rating,security_review_rating&component=
url="http://localhost:9000/api/measures/component?metricKeys=reliability_rating,software_quality_maintainability_rating,security_rating,security_review_rating&component=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"

#/api/qualitygates/project_status?projectKey=
url="http://localhost:9000/api/qualitygates/project_status?projectKey=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"

#/api/measures/component?metricKeys=duplicated_lines_density,comment_lines_density,ncloc,complexity,cognitive_complexity,coverage&component=
url="http://localhost:9000/api/measures/component?metricKeys=duplicated_lines_density,comment_lines_density,ncloc,complexity,cognitive_complexity,coverage&component=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"

#/api/measures/component?metricKeys=duplicated_lines_density,comment_lines_density,ncloc,complexity,cognitive_complexity,coverage&component=
url="http://localhost:9000/api/measures/component?metricKeys=duplicated_lines_density,comment_lines_density,ncloc,complexity,cognitive_complexity,coverage&component=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"

#/api/measures/component?metricKeys=reliability_remediation_effort,security_remediation_effort,sqale_index&component=
url="http://localhost:9000/api/measures/component?metricKeys=reliability_remediation_effort,security_remediation_effort,sqale_index&component=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
exit 1
fi
echo "$url OK (HTTP $code)"

#/api/measures/component?metricKeys=ncloc_language_distribution&component=
url="http://localhost:9000/api/measures/component?metricKeys=ncloc_language_distribution&component=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"

#/api/hotspots/search?status=TO_REVIEW&ps=500&pageIndex=0&project=
url="http://localhost:9000/api/hotspots/search?status=TO_REVIEW&ps=500&pageIndex=0&project=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"

#/api/issues/search?types=BUG&facets=severities&componentKeys=
url="http://localhost:9000/api/issues/search?types=BUG&facets=severities&componentKeys=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"

#/api/issues/search?types=VULNERABILITY&facets=severities&componentKeys=
url="http://localhost:9000/api/issues/search?types=VULNERABILITY&facets=severities&componentKeys=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"

#/api/issues/search?types=CODE_SMELL&facets=severities&componentKeys=
url="http://localhost:9000/api/issues/search?types=CODE_SMELL&facets=severities&componentKeys=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"

#/api/issues/search?issueStatuses=OPEN&ps=500&pageIndex=0&componentKeys=
url="http://localhost:9000/api/issues/search?issueStatuses=OPEN&ps=500&pageIndex=0&componentKeys=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"
Binary file removed GenerateCNESReport.class
Binary file not shown.
10 changes: 5 additions & 5 deletions pdf-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.bi</groupId>
<artifactId>pdf-generator</artifactId>
<version>1.0-SNAPSHOT</version>
<groupId>com.opendevstack</groupId>
<artifactId>sonar-report</artifactId>
<version>1.0</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down Expand Up @@ -44,7 +44,7 @@
<configuration>
<archive>
<manifest>
<mainClass>GenerateCNESReport</mainClass>
<mainClass>GenerateSonarReport</mainClass>
</manifest>
</archive>
<descriptorRefs>
Expand All @@ -62,4 +62,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Empty file.
Empty file.
Loading