|
| 1 | +name: Package Score |
| 2 | +description: | |
| 3 | + Run pana (pub.dev package analyzer) to compute the package score, |
| 4 | + print a readable report to the workflow log, and upload the raw |
| 5 | + markdown report as a workflow artifact (score_report.md). |
| 6 | + The score is compared against the currently published version on |
| 7 | + pub.dev — the build fails if the score regresses. If the package |
| 8 | + has never been published, no threshold is enforced. |
| 9 | +
|
| 10 | +inputs: |
| 11 | + working-directory: |
| 12 | + description: The working directory of the package (relative to repo root) |
| 13 | + required: true |
| 14 | + package-name: |
| 15 | + description: The name of the package being scored |
| 16 | + required: true |
| 17 | + |
| 18 | +runs: |
| 19 | + using: "composite" |
| 20 | + steps: |
| 21 | + - name: Install pana |
| 22 | + shell: bash |
| 23 | + run: dart pub global activate pana |
| 24 | + |
| 25 | + - name: Fetch published score from pub.dev |
| 26 | + id: published |
| 27 | + shell: bash |
| 28 | + run: | |
| 29 | + PACKAGE_NAME="${{ inputs.package-name }}" |
| 30 | + HTTP_CODE=$(curl -s -o "$RUNNER_TEMP/pubdev_score.json" -w "%{http_code}" \ |
| 31 | + "https://pub.dev/api/packages/${PACKAGE_NAME}/score") |
| 32 | +
|
| 33 | + if [ "$HTTP_CODE" = "200" ]; then |
| 34 | + GRANTED=$(python3 -c "import json; d=json.load(open('$RUNNER_TEMP/pubdev_score.json')); print(d.get('grantedPoints', 0))") |
| 35 | + MAX=$(python3 -c "import json; d=json.load(open('$RUNNER_TEMP/pubdev_score.json')); print(d.get('maxPoints', 160))") |
| 36 | + THRESHOLD=$((MAX - GRANTED)) |
| 37 | + echo "published=true" >> "$GITHUB_OUTPUT" |
| 38 | + echo "granted=$GRANTED" >> "$GITHUB_OUTPUT" |
| 39 | + echo "max=$MAX" >> "$GITHUB_OUTPUT" |
| 40 | + echo "threshold=$THRESHOLD" >> "$GITHUB_OUTPUT" |
| 41 | + echo "Published score for ${PACKAGE_NAME}: ${GRANTED}/${MAX} (threshold: ${THRESHOLD})" |
| 42 | + else |
| 43 | + echo "published=false" >> "$GITHUB_OUTPUT" |
| 44 | + echo "Package ${PACKAGE_NAME} not found on pub.dev (HTTP ${HTTP_CODE}) — skipping threshold enforcement" |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Run pana |
| 48 | + id: pana |
| 49 | + shell: bash |
| 50 | + working-directory: ${{ inputs.working-directory }} |
| 51 | + run: | |
| 52 | + set +e |
| 53 | + if [ "${{ steps.published.outputs.published }}" = "true" ]; then |
| 54 | + echo "Enforcing threshold: score must be at least ${{ steps.published.outputs.granted }}/${{ steps.published.outputs.max }} (published score)" |
| 55 | + dart pub global run pana \ |
| 56 | + --exit-code-threshold ${{ steps.published.outputs.threshold }} \ |
| 57 | + --no-warning . > "$RUNNER_TEMP/score_report.md" 2>&1 |
| 58 | + else |
| 59 | + echo "No published score found — running pana without threshold" |
| 60 | + dart pub global run pana \ |
| 61 | + --no-warning . > "$RUNNER_TEMP/score_report.md" 2>&1 |
| 62 | + fi |
| 63 | + PANA_EXIT=$? |
| 64 | + set -e |
| 65 | + echo "pana_exit=$PANA_EXIT" >> "$GITHUB_OUTPUT" |
| 66 | +
|
| 67 | + - name: Print score report |
| 68 | + shell: bash |
| 69 | + run: python3 "$GITHUB_ACTION_PATH/render_score.py" "$RUNNER_TEMP/score_report.md" |
| 70 | + |
| 71 | + - name: Upload score report |
| 72 | + if: always() |
| 73 | + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # 7.0.0 |
| 74 | + with: |
| 75 | + name: score_report-${{ inputs.package-name }}-${{ github.run_id }} |
| 76 | + path: ${{ runner.temp }}/score_report.md |
| 77 | + |
| 78 | + - name: Enforce score threshold |
| 79 | + if: steps.pana.outputs.pana_exit != '0' |
| 80 | + shell: bash |
| 81 | + run: | |
| 82 | + echo "::error::Pana score regressed below the published score (${{ steps.published.outputs.granted }}/${{ steps.published.outputs.max }}) on pub.dev" |
| 83 | + exit ${{ steps.pana.outputs.pana_exit }} |
0 commit comments