feat: Add branch option to PDF report generation and update documenta… #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build JAR | |
| on: | |
| release: | |
| types: [published] # Solo al publicar una release | |
| pull_request: | |
| branches: | |
| - '**' | |
| push: | |
| branches: | |
| - '**' | |
| 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: | | |
| if [ "${{ github.event_name }}" == "release" ]; then | |
| TAG="${{ github.event.release.tag_name }}" | |
| OUT="sonar-report-${TAG}.jar" | |
| elif [ "${{ github.event_name }}" == "pull_request" ]; then | |
| PR_NUM="${{ github.event.pull_request.number }}" | |
| SHORT_SHA="${GITHUB_SHA:0:7}" | |
| OUT="sonar-report-pr${PR_NUM}-${SHORT_SHA}.jar" | |
| else | |
| # push or workflow_dispatch | |
| BRANCH="${GITHUB_REF_NAME}" | |
| SHORT_SHA="${GITHUB_SHA:0:7}" | |
| SAFE_BRANCH=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9_-]/_/g') | |
| OUT="sonar-report-${SAFE_BRANCH}-${SHORT_SHA}.jar" | |
| fi | |
| cp "$ARTIFACT_PATH" "$OUT" | |
| echo "OUT=${OUT}" >> "$GITHUB_ENV" | |
| - name: Upload workflow artifact | |
| 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 }} |