Skip to content

Commit f982b3e

Browse files
committed
Compare score to latest release if possible
1 parent 93335dd commit f982b3e

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

.github/composite_actions/package_score/action.yaml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ description: |
33
Run pana (pub.dev package analyzer) to compute the package score,
44
print a readable report to the workflow log, and upload an HTML
55
report as a workflow artifact.
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.
69
710
inputs:
811
working-directory:
@@ -11,12 +14,6 @@ inputs:
1114
package-name:
1215
description: The name of the package being scored
1316
required: true
14-
exit-code-threshold:
15-
description: |
16-
Fail the step if (maxPoints - grantedPoints) exceeds this value.
17-
Set to -1 to never fail. Default 160 means score must be >= 0/160.
18-
required: false
19-
default: "160"
2017

2118
runs:
2219
using: "composite"
@@ -25,18 +22,41 @@ runs:
2522
shell: bash
2623
run: dart pub global activate pana
2724

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+
2847
- name: Run pana
2948
id: pana
3049
shell: bash
3150
working-directory: ${{ inputs.working-directory }}
3251
run: |
33-
# Run pana with threshold; capture markdown output and exit code.
3452
set +e
35-
if [ "${{ inputs.exit-code-threshold }}" != "-1" ]; then
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)"
3655
dart pub global run pana \
37-
--exit-code-threshold ${{ inputs.exit-code-threshold }} \
56+
--exit-code-threshold ${{ steps.published.outputs.threshold }} \
3857
--no-warning . > "$RUNNER_TEMP/pana_score.md" 2>&1
3958
else
59+
echo "No published score found — running pana without threshold"
4060
dart pub global run pana \
4161
--no-warning . > "$RUNNER_TEMP/pana_score.md" 2>&1
4262
fi
@@ -63,5 +83,5 @@ runs:
6383
if: steps.pana.outputs.pana_exit != '0'
6484
shell: bash
6585
run: |
66-
echo "::error::Pana score is below the required threshold (exit-code-threshold: ${{ inputs.exit-code-threshold }})"
86+
echo "::error::Pana score regressed below the published score (${{ steps.published.outputs.granted }}/${{ steps.published.outputs.max }}) on pub.dev"
6787
exit ${{ steps.pana.outputs.pana_exit }}

0 commit comments

Comments
 (0)