|
| 1 | +# SPDX-FileCopyrightText: 2006 Istituto Nazionale di Fisica Nucleare |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +name: Dependency Updates |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + paths: |
| 10 | + - "pom.xml" |
| 11 | + pull_request: |
| 12 | + paths: |
| 13 | + - "pom.xml" |
| 14 | + workflow_dispatch: |
| 15 | + schedule: |
| 16 | + - cron: "0 6 * * 1" # weekly fallback (Monday) |
| 17 | + |
| 18 | +jobs: |
| 19 | + check-dependencies: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout repo |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Set up Java |
| 27 | + uses: actions/setup-java@v4 |
| 28 | + with: |
| 29 | + distribution: temurin |
| 30 | + java-version: 17 |
| 31 | + |
| 32 | + - name: Check if pom.xml changed |
| 33 | + id: changes |
| 34 | + uses: dorny/paths-filter@v3 |
| 35 | + with: |
| 36 | + filters: | |
| 37 | + pom: |
| 38 | + - 'pom.xml' |
| 39 | +
|
| 40 | + - name: Run Maven (minor updates only) |
| 41 | + if: steps.changes.outputs.pom == 'true' |
| 42 | + run: | |
| 43 | + mvn versions:display-dependency-updates \ |
| 44 | + -DallowMajorUpdates=false \ |
| 45 | + -DprocessDependencyManagement=true \ |
| 46 | + | tee minor-updates.txt |
| 47 | +
|
| 48 | + - name: Run Maven (all updates) |
| 49 | + if: steps.changes.outputs.pom == 'true' |
| 50 | + run: | |
| 51 | + mvn versions:display-dependency-updates \ |
| 52 | + -DallowMajorUpdates=true \ |
| 53 | + -DprocessDependencyManagement=true \ |
| 54 | + | tee all-updates.txt |
| 55 | +
|
| 56 | + - name: Generate HTML report |
| 57 | + if: steps.changes.outputs.pom == 'true' |
| 58 | + run: | |
| 59 | + echo "<html><head><style> |
| 60 | + body { font-family: Arial, sans-serif; } |
| 61 | + table { border-collapse: collapse; width: 100%; } |
| 62 | + th, td { border: 1px solid #ddd; padding: 8px; } |
| 63 | + th { background-color: #f2f2f2; text-align: left; } |
| 64 | + tr:nth-child(even) { background-color: #f9f9f9; } |
| 65 | + </style></head><body>" > report.html |
| 66 | +
|
| 67 | + echo "<h1>Dependency Updates</h1>" >> report.html |
| 68 | +
|
| 69 | + # Also prepare summary (GitHub UI) |
| 70 | + echo "# Dependency Updates" >> $GITHUB_STEP_SUMMARY |
| 71 | +
|
| 72 | + parse_file () { |
| 73 | + FILE=$1 |
| 74 | + TITLE=$2 |
| 75 | +
|
| 76 | + # HTML |
| 77 | + echo "<h2>$TITLE</h2>" >> report.html |
| 78 | + echo "<table>" >> report.html |
| 79 | + echo "<tr><th>GroupId</th><th>ArtifactId</th><th>Current</th><th>Latest</th></tr>" >> report.html |
| 80 | +
|
| 81 | + # Summary (Markdown) |
| 82 | + echo "## $TITLE" >> $GITHUB_STEP_SUMMARY |
| 83 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 84 | + echo "| GroupId | ArtifactId | Current | Latest |" >> $GITHUB_STEP_SUMMARY |
| 85 | + echo "|---------|------------|---------|--------|" >> $GITHUB_STEP_SUMMARY |
| 86 | +
|
| 87 | + grep "->" $FILE \ |
| 88 | + | sed 's/^\[INFO\]\s*//' \ |
| 89 | + | grep ":" \ |
| 90 | + | while read line; do |
| 91 | +
|
| 92 | + GROUP_ARTIFACT=$(echo $line | awk '{print $1}') |
| 93 | + CURRENT=$(echo $line | awk '{print $(NF-2)}') |
| 94 | + LATEST=$(echo $line | awk '{print $NF}') |
| 95 | +
|
| 96 | + GROUP=$(echo $GROUP_ARTIFACT | cut -d: -f1) |
| 97 | + ARTIFACT=$(echo $GROUP_ARTIFACT | cut -d: -f2) |
| 98 | +
|
| 99 | + # HTML row |
| 100 | + echo "<tr><td>$GROUP</td><td>$ARTIFACT</td><td>$CURRENT</td><td>$LATEST</td></tr>" >> report.html |
| 101 | +
|
| 102 | + # Markdown row (for summary) |
| 103 | + echo "| $GROUP | $ARTIFACT | $CURRENT | $LATEST |" >> $GITHUB_STEP_SUMMARY |
| 104 | + done |
| 105 | +
|
| 106 | + echo "</table>" >> report.html |
| 107 | + echo "" >> report.html |
| 108 | +
|
| 109 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 110 | + } |
| 111 | +
|
| 112 | + parse_file minor-updates.txt "Minor / Patch Updates Only" |
| 113 | + parse_file all-updates.txt "All Updates (Including Major)" |
| 114 | +
|
| 115 | + echo "</body></html>" >> report.html |
| 116 | +
|
| 117 | + - name: Upload report |
| 118 | + if: steps.changes.outputs.pom == 'true' |
| 119 | + uses: actions/upload-artifact@v4 |
| 120 | + with: |
| 121 | + name: dependency-update-report |
| 122 | + path: report.html |
0 commit comments