Fixed empty project bug | Fixed wrong URL for documentation | Added branch selector | Main Font modified #11
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 | ||
| pull-requests: 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: Comment on PR with artifact link | ||
| if: ${{ github.event_name == 'pull_request' }} | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const artifactName = '${{ env.OUT }}'; | ||
| const runId = context.runId; | ||
| const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`; | ||
| const artifactUrl = `${repoUrl}/actions/runs/${runId}`; | ||
| const comment = `## 🎯 JAR Artifact Ready | ||
| The executable JAR has been built and is available for download: | ||
| **Artifact Name:** \`${artifactName}\` | ||
| 📥 [**Download from workflow run**](${artifactUrl}) | ||
| _The artifact will be available for 14 days._`; | ||
| // Check if we already commented | ||
| const comments = await github.rest.issues.listComments({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| }); | ||
| const botComment = comments.data.find(comment => | ||
| comment.user.type === 'Bot' && | ||
| comment.body.includes('🎯 JAR Artifact Ready') | ||
| ); | ||
| if (botComment) { | ||
| // Update existing comment | ||
| await github.rest.issues.updateComment({ | ||
| comment_id: botComment.id, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: comment | ||
| }); | ||
| console.log('✓ Comment updated'); | ||
| } else { | ||
| // Create new comment | ||
| await github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: comment | ||
| }); | ||
| console.log('✓ Comment created'); | ||
| } | ||
| - 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 }} | ||
| - name: Delete existing 'latest' release and tag | ||
| if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | ||
| continue-on-error: true | ||
| run: | | ||
| gh release delete latest --yes || true | ||
| git push origin :refs/tags/latest || true | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Create 'latest' pre-release for main branch | ||
| if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| tag_name: latest | ||
| name: Latest Development Build | ||
| prerelease: true | ||
| body: | | ||
| Automated pre-release from the latest commit on main branch. | ||
| **Commit:** ${{ github.sha }} | ||
| **Build:** ${{ github.run_number }} | ||
| files: ${{ env.OUT }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||