Skip to content

Commit 910163e

Browse files
authored
fix(compare-actions): flag tag mismatch as outdated even when SHAs match (#6)
Previously, a pin of '@<sha> # v1' against an action whose latest release is 'v1.0.0' was reported as 'Up to date: (v1)' because the SHAs coincided (v1 floating tag currently points to v1.0.0's commit). The consumer's pin label never got refreshed, so logs showed the stale alias and the auto-update PR never fired. Now: current_tag != latest_tag triggers outdated-flag even with matching SHAs. apply-updates.sh already writes both sha + tag on rewrite, so the resulting PR cleanly updates '# v1' -> '# v1.0.0' (and '# v1.0.0' -> '# v1.0.1' when the next release arrives). Added bats coverage: - flags outdated when SHAs match but tags differ (the exact case here) - up-to-date when both SHAs and tags match exactly (regression guard) - up-to-date when SHAs match and current_tag is empty (empty-comment case where tag comparison is skipped)
1 parent c10e61a commit 910163e

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

scripts/compare-actions.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ OUTDATED_COUNT=0
1010
: >actions-outdated.txt
1111

1212
while IFS='|' read -r action current_sha current_tag latest_sha latest_tag; do
13-
if [[ "$current_sha" != "$latest_sha" ]]; then
13+
# Flag outdated on SHA mismatch OR on tag mismatch when SHAs coincide
14+
# (e.g. pin comment says "# v1" but latest release is "v1.0.0" — same
15+
# commit today because v1 floats, but the pin label is stale; refresh
16+
# it to the exact release name so consumers see what version they're on).
17+
if [[ "$current_sha" != "$latest_sha" ]] ||
18+
{ [[ -n "$current_tag" ]] && [[ -n "$latest_tag" ]] && [[ "$current_tag" != "$latest_tag" ]]; }; then
1419
echo " Outdated: ${action} ${current_tag:-unknown} -> ${latest_tag}"
1520
echo "${action}|${current_sha}|${current_tag}|${latest_sha}|${latest_tag}" >>actions-outdated.txt
1621
((OUTDATED_COUNT++)) || true

tests/compare-actions.bats

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,40 @@ EOF
3838
[[ "$output" != *"actions/setup-node"* ]]
3939
assert_output_contains "has_outdated=true"
4040
}
41+
42+
@test "compare-actions: flags outdated when SHAs match but tags differ (floating pin behind exact release)" {
43+
cat > actions-latest.txt <<EOF
44+
nerdalytics/check-action-versions|same-sha|v1|same-sha|v1.0.0
45+
EOF
46+
47+
run bash "${SCRIPT_DIR}/compare-actions.sh"
48+
[ "$status" -eq 0 ]
49+
run cat actions-outdated.txt
50+
[[ "$output" == *"nerdalytics/check-action-versions|same-sha|v1|same-sha|v1.0.0"* ]]
51+
assert_output_contains "has_outdated=true"
52+
}
53+
54+
@test "compare-actions: up-to-date when both SHAs and tags match exactly" {
55+
cat > actions-latest.txt <<EOF
56+
actions/checkout|same-sha|v5.0.0|same-sha|v5.0.0
57+
EOF
58+
59+
run bash "${SCRIPT_DIR}/compare-actions.sh"
60+
[ "$status" -eq 0 ]
61+
run cat actions-outdated.txt
62+
[ -z "$output" ]
63+
assert_output_contains "has_outdated=false"
64+
}
65+
66+
@test "compare-actions: up-to-date when SHAs match and current_tag is empty" {
67+
# No comment in the pin -> current_tag is empty. Only SHA comparison matters.
68+
cat > actions-latest.txt <<EOF
69+
actions/checkout|same-sha||same-sha|v5.0.0
70+
EOF
71+
72+
run bash "${SCRIPT_DIR}/compare-actions.sh"
73+
[ "$status" -eq 0 ]
74+
run cat actions-outdated.txt
75+
[ -z "$output" ]
76+
assert_output_contains "has_outdated=false"
77+
}

0 commit comments

Comments
 (0)