fix: extract decorate-pr comment rendering from action yaml

This commit is contained in:
Micheal Wilkinson
2026-03-21 14:17:07 +00:00
parent 5a207e7d5d
commit 4a47580ea8
2 changed files with 73 additions and 124 deletions

View File

@@ -328,37 +328,6 @@ runs:
echo "$failure_reason" >&2 echo "$failure_reason" >&2
exit 1 exit 1
fi fi
- name: Extract changelog unreleased entries
id: extract-changelog
shell: bash
env:
CHANGELOG: ${{ inputs.changelog }}
run: |
set -euo pipefail
if [[ ! -f "$CHANGELOG" ]]; then
printf 'unreleased_entries=%s\n' "" >> "$GITHUB_OUTPUT"
exit 0
fi
# Extract everything between [Unreleased] header and the next [X.Y.Z] header
unreleased="$(awk '
/^## \[Unreleased\]/ { in_unreleased=1; next }
/^## \[[0-9]+\.[0-9]+\.[0-9]+\]/ { if (in_unreleased) exit }
in_unreleased && NF { print }
' "$CHANGELOG")"
# Use a temporary file to handle multiline content
tmp_file=$(mktemp)
printf '%s' "$unreleased" > "$tmp_file"
# Read it back and set as output
delimiter="EOF_CHANGELOG"
printf '%s<<%s\n' "unreleased_entries<<$delimiter" "$delimiter" >> "$GITHUB_OUTPUT"
cat "$tmp_file" >> "$GITHUB_OUTPUT"
printf '%s\n' "$delimiter" >> "$GITHUB_OUTPUT"
rm -f "$tmp_file"
- name: Build PR comment markdown - name: Build PR comment markdown
id: build-comment id: build-comment
@@ -373,102 +342,11 @@ runs:
GATE_MODE: ${{ inputs.changelog-gate-mode }} GATE_MODE: ${{ inputs.changelog-gate-mode }}
DOCS_ONLY: ${{ steps.changelog-gate.outputs.docs_only }} DOCS_ONLY: ${{ steps.changelog-gate.outputs.docs_only }}
ADDITIONS_COUNT: ${{ steps.changelog-gate.outputs.unreleased_additions_count }} ADDITIONS_COUNT: ${{ steps.changelog-gate.outputs.unreleased_additions_count }}
FAILURE_REASON: ${{ steps.changelog-gate.outputs.gate_failure_reason }} FAILURE_REASON: ${{ steps.changelog-gate.outputs.failure_reason }}
run: | run: |
set -euo pipefail set -euo pipefail
# Start building the comment bash "$GITHUB_ACTION_PATH/build-comment.sh"
tmp_file=$(mktemp)
# Add title and coverage section
cat > "$tmp_file" << 'EOF'
<!-- vociferate-pr-review -->
EOF
printf '## %s\n\n' "$COMMENT_TITLE" >> "$tmp_file"
# Coverage badge section
cat >> "$tmp_file" << EOF
### Coverage
![Coverage Badge]($BADGE_URL)
**Coverage:** $COVERAGE_PCT%
EOF
# Changelog gate section (if enabled)
if [[ "$GATE_ENABLED" == "true" ]]; then
gate_status="✓ Pass"
if [[ "$GATE_PASSED" != "true" ]]; then
if [[ "$GATE_MODE" == "strict" ]]; then
gate_status="✗ Fail"
else
gate_status="⚠ Warning"
fi
fi
cat >> "$tmp_file" << EOF
### Changelog Gate
**Status:** $gate_status
EOF
if [[ "$DOCS_ONLY" == "true" ]]; then
cat >> "$tmp_file" << 'EOF'
This PR only modifies documentation—changelog entry not required.
EOF
elif [[ "$GATE_PASSED" == "true" ]]; then
cat >> "$tmp_file" << EOF
Found $ADDITIONS_COUNT line(s) added to Unreleased section ✓
EOF
else
cat >> "$tmp_file" << EOF
**Issue:** $FAILURE_REASON
**How to fix:** Add an entry under the appropriate subsection in the \`## [Unreleased]\` section of \`CHANGELOG.md\`. Use one of:
- \`### Breaking\` for backwards-incompatible changes
- \`### Added\` for new features
- \`### Changed\` for behavior changes
- \`### Removed\` for deprecated removals
- \`### Fixed\` for bug fixes
Example:
\`\`\`markdown
## [Unreleased]
### Added
- New changelog gate validation for PR decoration.
\`\`\`
EOF
fi
fi
# Changelog section
if [[ -n "$UNRELEASED" ]]; then
cat >> "$tmp_file" << 'EOF'
### Unreleased Changes
EOF
printf '%s\n' "$UNRELEASED" >> "$tmp_file"
printf '\n' >> "$tmp_file"
fi
# Add footer
cat >> "$tmp_file" << 'EOF'
---
*This comment was automatically generated by [vociferate/decorate-pr](https://git.hrafn.xyz/aether/vociferate).*
EOF
# Store as output using delimiter
delimiter="EOF_COMMENT"
printf '%s<<%s\n' "comment_body<<$delimiter" "$delimiter" >> "$GITHUB_OUTPUT"
cat "$tmp_file" >> "$GITHUB_OUTPUT"
printf '%s\n' "$delimiter" >> "$GITHUB_OUTPUT"
rm -f "$tmp_file"
- name: Find and update/post PR comment - name: Find and update/post PR comment
id: post-comment id: post-comment

View File

@@ -0,0 +1,71 @@
#!/usr/bin/env bash
set -euo pipefail
tmp_file=$(mktemp)
trap 'rm -f "$tmp_file"' EXIT
{
printf '%s\n' '<!-- vociferate-pr-review -->'
printf '\n## %s\n\n' "$COMMENT_TITLE"
printf '### Coverage\n'
printf '![Coverage Badge](%s)\n\n' "$BADGE_URL"
printf '**Coverage:** %s%%\n' "$COVERAGE_PCT"
} > "$tmp_file"
if [[ "$GATE_ENABLED" == "true" ]]; then
gate_status="Pass"
if [[ "$GATE_PASSED" != "true" ]]; then
if [[ "$GATE_MODE" == "strict" ]]; then
gate_status="Fail"
else
gate_status="Warning"
fi
fi
{
printf '\n### Changelog Gate\n'
printf '**Status:** %s\n\n' "$gate_status"
} >> "$tmp_file"
if [[ "$DOCS_ONLY" == "true" ]]; then
printf '%s\n\n' 'This PR only modifies documentation; changelog entry not required.' >> "$tmp_file"
elif [[ "$GATE_PASSED" == "true" ]]; then
printf 'Found %s line(s) added to Unreleased section.\n\n' "$ADDITIONS_COUNT" >> "$tmp_file"
else
printf '**Issue:** %s\n\n' "$FAILURE_REASON" >> "$tmp_file"
cat >> "$tmp_file" <<'EOF'
**How to fix:** Add an entry under the appropriate subsection in the `## [Unreleased]` section of `CHANGELOG.md`. Use one of:
- `### Breaking` for backwards-incompatible changes
- `### Added` for new features
- `### Changed` for behavior changes
- `### Removed` for deprecated removals
- `### Fixed` for bug fixes
Example:
```markdown
## [Unreleased]
### Added
- New changelog gate validation for PR decoration.
```
EOF
fi
fi
if [[ -n "$UNRELEASED" ]]; then
{
printf '### Unreleased Changes\n\n'
printf '%s\n\n' "$UNRELEASED"
} >> "$tmp_file"
fi
cat >> "$tmp_file" <<'EOF'
---
*This comment was automatically generated by [vociferate/decorate-pr](https://git.hrafn.xyz/aether/vociferate).*
EOF
delimiter="EOF_COMMENT"
printf 'comment_body<<%s\n' "$delimiter" >> "$GITHUB_OUTPUT"
cat "$tmp_file" >> "$GITHUB_OUTPUT"
printf '%s\n' "$delimiter" >> "$GITHUB_OUTPUT"