From 4a414b5d8f03dee6f9c663ed2b3e964a648ef44f Mon Sep 17 00:00:00 2001 From: fewensa Date: Tue, 24 Mar 2026 08:13:23 +0000 Subject: [PATCH] fix(smart-vercel): restore yaml preview comments Summary: - switch preview comment rendering to a helper script that emits raw multiline YAML-style entries instead of percent-encoded text - normalize preview links before exporting action outputs and keep optional preview section metadata in the rendered entry - add a shell regression script covering yaml formatting and link normalization Rationale: - sticky PR comments should append readable list entries instead of literal %0A sequences after the output handling change from PR #28 - moving the formatter into a reusable script keeps the action logic small and gives the repo a deterministic regression target Tests: - bash scripts/test-smart-vercel-comment-format.sh - git diff --check --- actions/smart-vercel/action.yml | 26 ++-------- .../smart-vercel/bin/render-preview-output.sh | 47 +++++++++++++++++++ scripts/test-smart-vercel-comment-format.sh | 41 ++++++++++++++++ 3 files changed, 91 insertions(+), 23 deletions(-) create mode 100755 actions/smart-vercel/bin/render-preview-output.sh create mode 100755 scripts/test-smart-vercel-comment-format.sh diff --git a/actions/smart-vercel/action.yml b/actions/smart-vercel/action.yml index a9b9b94..506c92b 100644 --- a/actions/smart-vercel/action.yml +++ b/actions/smart-vercel/action.yml @@ -178,6 +178,7 @@ runs: cd ${{ inputs.workdir }} DIR_NAME=${{ steps.dir-name.outputs.DIR_NAME }} REPO_NAME=${{ steps.repo-name.outputs.REPO_NAME }} + FORMAT_PREVIEW_OUTPUT=${{ github.action_path }}/bin/render-preview-output.sh VERCEL_TOKEN=${{ inputs.vercel_token }} VERCEL_GROUP=${{ inputs.vercel_group }} PREVIEW_OUTPUT=${{ inputs.preview_output }} @@ -239,10 +240,7 @@ runs: fi done - content="${DEPLOYMENT_URL//'%'/'%25'}" - content="${content//$'\n'/'%0A'}" - content="${content//$'\r'/'%0D'}" - PREVIEW_LINK="${content}" + PREVIEW_LINK=$("${FORMAT_PREVIEW_OUTPUT}" normalize-link "${DEPLOYMENT_URL}") for DOMAIN in ${ALL_ALIAS_DOMAIN} do @@ -268,25 +266,7 @@ runs: SHA=${{ github.event.pull_request.head.sha }} SHA=${SHA::7} fi - COMMIT="Commit: [${SHA}](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commit/${SHA})" - PREVIEW="Preview: ${PREVIEW_LINK}" - - if [ -n "${PREVIEW_SECTION}" ]; then - echo "\---${PREVIEW_SECTION}---" >> comment.md - else - echo '\---' >> comment.md - fi - echo $COMMIT >> comment.md - echo $PREVIEW >> comment.md - echo '' >> comment.md - - content=$(cat comment.md) - content="${content//'%'/'%25'}" - content="${content//$'\n'/'%0A'}" - content="${content//$'\r'/'%0D'}" - PREVIEW_OUTPUT=${content} - - rm -rf comment.md + PREVIEW_OUTPUT=$("${FORMAT_PREVIEW_OUTPUT}" render-entry "${SHA}" "${PREVIEW_LINK}" "${PREVIEW_SECTION}") { echo 'PREVIEW_OUTPUT< ..." >&2 + exit 1 +} + +main() { + local command="${1:-}" + + case "${command}" in + normalize-link) + [ $# -eq 2 ] || usage + normalize_link "$2" + ;; + render-entry) + [ $# -ge 3 ] && [ $# -le 4 ] || usage + render_entry "$2" "$3" "${4:-}" + ;; + *) + usage + ;; + esac +} + +main "$@" diff --git a/scripts/test-smart-vercel-comment-format.sh b/scripts/test-smart-vercel-comment-format.sh new file mode 100755 index 0000000..7fd3ed0 --- /dev/null +++ b/scripts/test-smart-vercel-comment-format.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +FORMATTER="${ROOT_DIR}/actions/smart-vercel/bin/render-preview-output.sh" + +assert_eq() { + local expected="$1" + local actual="$2" + local name="$3" + + if [ "${expected}" != "${actual}" ]; then + echo "assertion failed: ${name}" >&2 + echo "expected:" >&2 + printf '%s\n' "${expected}" >&2 + echo "actual:" >&2 + printf '%s\n' "${actual}" >&2 + exit 1 + fi +} + +main() { + local actual expected + + actual="$("${FORMATTER}" render-entry "f56896b" "https://degov-home-a19ab32qi-itering.vercel.app")" + expected=$'- comment: f56896b\n preview: https://degov-home-a19ab32qi-itering.vercel.app' + assert_eq "${expected}" "${actual}" "renders yaml-style preview entry" + + actual="$("${FORMATTER}" render-entry "113a1fd" $'https://degov-home-mbjpfedv3-itering.vercel.app\nhttps://alias.vercel.app' "staging")" + expected=$'- section: staging\n comment: 113a1fd\n preview: https://degov-home-mbjpfedv3-itering.vercel.app https://alias.vercel.app' + assert_eq "${expected}" "${actual}" "normalizes multiline preview links and preserves section metadata" + + actual="$("${FORMATTER}" normalize-link $'https://preview.vercel.app\r\nhttps://alias.vercel.app')" + expected='https://preview.vercel.app https://alias.vercel.app' + assert_eq "${expected}" "${actual}" "normalizes raw preview link output" + + echo "smart-vercel comment formatter tests passed" +} + +main "$@"