Skip to content

fix: notify release step #3010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,46 @@ jobs:
tools/*/stories.js
key: ${{needs.build.outputs.cache-primary-key}}

- name: Version packages
- name: Version, Publish & Create GitHub Release
id: changesets
uses: changesets/action@v1
with:
version: pnpm run version
publish: pnpm publish -r --no-git-checks
createGithubReleases: true
run: |
set -e

# 1. Publish packages, capturing the JSON summary report at the end.
publish_output=$(pnpm publish -r --no-git-checks --report-summary || true)
Copy link
Preview

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using || true masks all potential errors from the publish command, making it difficult to distinguish between actual failures and expected scenarios where no packages need publishing. Consider checking the exit code explicitly or using a more specific error handling approach.

Suggested change
publish_output=$(pnpm publish -r --no-git-checks --report-summary || true)
set +e
publish_output=$(pnpm publish -r --no-git-checks --report-summary 2>&1)
publish_exit_code=$?
set -e

Copilot uses AI. Check for mistakes.

echo "$publish_output"

# 2. Extract the JSON summary from the last line of the output.
json_summary=$(echo "$publish_output" | tail -n 1)

# 3. Check if any packages were actually published by checking the 'added' count.
published_count=$(echo "$json_summary" | jq -r '.added')
Copy link
Preview

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If jq fails to parse the JSON or the .added field doesn't exist, this will produce an empty string or 'null', which could cause the subsequent numeric comparison to fail. Consider adding validation to ensure the value is a valid number before the comparison.

Suggested change
published_count=$(echo "$json_summary" | jq -r '.added')
published_count=$(echo "$json_summary" | jq -r 'if (.added | type == "number") then .added else 0 end')

Copilot uses AI. Check for mistakes.


if [ "$published_count" -gt 0 ]; then
Comment on lines +202 to +205
Copy link
Preview

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracting JSON from the last line assumes the JSON summary is always on the final line, but if the publish command fails or produces unexpected output, this could capture non-JSON content. Consider validating that the extracted content is valid JSON before proceeding.

Suggested change
# 3. Check if any packages were actually published by checking the 'added' count.
published_count=$(echo "$json_summary" | jq -r '.added')
if [ "$published_count" -gt 0 ]; then
# Validate that the extracted line is valid JSON.
if ! echo "$json_summary" | jq empty > /dev/null 2>&1; then
echo "❌ Error: The last line of pnpm publish output is not valid JSON. Aborting publish step."
echo "published=false" >> "$GITHUB_OUTPUT"
echo "publishedPackages=[]" >> "$GITHUB_OUTPUT"
exit 1
fi
# 3. Check if any packages were actually published by checking the 'added' count.
published_count=$(echo "$json_summary" | jq -r '.added')

Copilot uses AI. Check for mistakes.

echo "✅ Successfully published $published_count package(s)."

# 4. Extract the published package details into a compact JSON string.
# This creates a JSON array like: '[{"name":"pkg-a","version":"1.0.0"},...]'
published_packages=$(echo "$json_summary" | jq -c '.packages')

# 5. Set both outputs for subsequent jobs.
echo "published=true" >> "$GITHUB_OUTPUT"
echo "publishedPackages=$published_packages" >> "$GITHUB_OUTPUT"

# 6. Create Git tags and GitHub Releases.
npx changeset tag
git tag --points-at HEAD | xargs -I % sh -c 'gh release create % --generate-notes'
Copy link
Preview

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command will fail if there are no tags at HEAD (when git tag --points-at HEAD returns empty). Consider adding a check to ensure tags exist before attempting to create releases, or handle the case where no tags are found.

Suggested change
git tag --points-at HEAD | xargs -I % sh -c 'gh release create % --generate-notes'
tags_at_head=$(git tag --points-at HEAD)
if [ -n "$tags_at_head" ]; then
echo "$tags_at_head" | xargs -I % sh -c 'gh release create % --generate-notes'
else
echo "No tags found at HEAD; skipping GitHub release creation."
fi

Copilot uses AI. Check for mistakes.


else
echo "No packages were published."

# Set both outputs to their empty/false state.
echo "published=false" >> "$GITHUB_OUTPUT"
echo "publishedPackages=[]" >> "$GITHUB_OUTPUT"
fi
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
NPM_TOKEN: '${{ secrets.NPM_TOKEN }}'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

notify:
name: Notify Slack & Website
Expand Down