Skip to content

ci: prerelease バージョンの publish 時に --tag を自動付与するように修正#132

Merged
KinjiKawaguchi merged 1 commit intodevelopfrom
fix/publish-prerelease-tag
Mar 31, 2026
Merged

ci: prerelease バージョンの publish 時に --tag を自動付与するように修正#132
KinjiKawaguchi merged 1 commit intodevelopfrom
fix/publish-prerelease-tag

Conversation

@KinjiKawaguchi
Copy link
Copy Markdown
Member

@KinjiKawaguchi KinjiKawaguchi commented Mar 31, 2026

Why

prerelease バージョン(3.0.0-rc.1 等)を npm publish する際、--tag オプションが未指定のため publish が失敗する。
https://github.com/su-its/core/actions/runs/23796409089/job/69344776248

What

package.json のバージョンにハイフンが含まれる場合、prerelease ID(rc, beta 等)を抽出して --tag に指定する。

  • 3.0.0-rc.1npm publish --access public --tag rc
  • 3.0.0-beta.1npm publish --access public --tag beta
  • 3.0.0npm publish --access public(latest)

🤖 Generated with Claude Code


Open with Devin

package.json のバージョンにハイフンが含まれる場合(rc, beta 等)、
npm publish に --tag を付与して prerelease タグで公開する。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 31, 2026 12:10
@KinjiKawaguchi KinjiKawaguchi changed the title fix(ci): prerelease バージョンの publish 時に --tag を自動付与 ci: prerelease バージョンの publish 時に --tag を自動付与するように修正 Mar 31, 2026
@KinjiKawaguchi KinjiKawaguchi merged commit aba31a2 into develop Mar 31, 2026
6 checks passed
@KinjiKawaguchi KinjiKawaguchi deleted the fix/publish-prerelease-tag branch March 31, 2026 12:12
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 3 potential issues.

Open in Devin Review

Comment on lines +36 to +37
PRERELEASE_ID=$(echo "$VERSION" | sed 's/.*-\([a-zA-Z]*\).*/\1/')
echo "tag=--tag $PRERELEASE_ID" >> "$GITHUB_OUTPUT"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Numeric-only prerelease identifiers produce empty --tag argument, breaking npm publish

The sed pattern 's/.*-\([a-zA-Z]*\).*/\1/' only captures alphabetic characters ([a-zA-Z]*). For valid semver prerelease versions with numeric-only identifiers (e.g., 1.0.0-1 or 1.0.0-0.3.7), PRERELEASE_ID will be an empty string. Since the grep -q '-' check still passes (the version contains a hyphen), the output becomes tag=--tag (with an empty tag value). The resulting command npm publish --access public --tag will pass a bare --tag flag with no value, causing npm to error.

While the project currently uses alpha, beta, and rc prerelease IDs (see package.json:45-47), the workflow doesn't validate or restrict to these, so a numeric prerelease version would silently break the publish step.

Suggested change
PRERELEASE_ID=$(echo "$VERSION" | sed 's/.*-\([a-zA-Z]*\).*/\1/')
echo "tag=--tag $PRERELEASE_ID" >> "$GITHUB_OUTPUT"
PRERELEASE_ID=$(echo "$VERSION" | sed 's/.*-\([a-zA-Z]*\).*/\1/')
if [ -z "$PRERELEASE_ID" ]; then
echo "tag=--tag prerelease" >> "$GITHUB_OUTPUT"
else
echo "tag=--tag $PRERELEASE_ID" >> "$GITHUB_OUTPUT"
fi
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

else
echo "tag=" >> "$GITHUB_OUTPUT"
fi
- run: npm publish --access public ${{ steps.tag.outputs.tag }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 Info: Unquoted ${{ steps.tag.outputs.tag }} is intentional but worth noting

The expression ${{ steps.tag.outputs.tag }} at line 41 is deliberately unquoted so that --tag rc is word-split into two separate arguments (--tag and rc) by the shell. If it were quoted as "${{ steps.tag.outputs.tag }}", npm would receive a single argument --tag rc which would be incorrect. This is safe here because the sed pattern at line 36 restricts PRERELEASE_ID to [a-zA-Z]* only, preventing any shell metacharacter injection. However, this pattern (embedding both flag and value in a single output) is fragile — a future maintainer might quote it for "safety" and break the command. A more robust approach would be to output just the tag name and construct the --tag flag separately in the run step.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

run: |
VERSION=$(node -p "require('./package.json').version")
if echo "$VERSION" | grep -q '-'; then
PRERELEASE_ID=$(echo "$VERSION" | sed 's/.*-\([a-zA-Z]*\).*/\1/')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 Info: Greedy .*- in sed captures the last hyphen-delimited segment only

The sed pattern 's/.*-\([a-zA-Z]*\).*/\1/' uses greedy .*- which matches up to the last hyphen in the version string. For standard semver like 3.0.0-rc.0, there's only one hyphen so this is fine. But for hypothetical versions with multiple hyphens in the prerelease section (e.g., 1.0.0-alpha-beta.2), it would extract beta rather than alpha. This matches how this project uses prerelease IDs (single identifier like alpha, beta, rc as seen in package.json:45-47), so it works correctly in practice, but the behavior is worth documenting.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

GitHub Actions の publish ワークフローで、prerelease バージョン(例: 3.0.0-rc.1)を npm publish する際に dist-tag を自動付与し、publish 失敗を防ぐための変更です。

Changes:

  • package.jsonversion- が含まれる場合、prerelease ID を抽出して npm publish --tag <id> を付与
  • stable バージョンの場合は tag を付与せず従来どおり latest 扱いで publish

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +35 to +39
if echo "$VERSION" | grep -q '-'; then
PRERELEASE_ID=$(echo "$VERSION" | sed 's/.*-\([a-zA-Z]*\).*/\1/')
echo "tag=--tag $PRERELEASE_ID" >> "$GITHUB_OUTPUT"
else
echo "tag=" >> "$GITHUB_OUTPUT"
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

PRERELEASE_ID の抽出が sed 's/.*-\([a-zA-Z]*\).*/\1/' だと、SemVer 上は有効な 1.2.3-1 / 1.2.3-rc1 のような prerelease(先頭が数字 or 英数字混在)で空文字や途中までしか取れず、--tag の値が不正になって publish が失敗する可能性があります。ここは Bash/Node 側で -(?<id>[0-9A-Za-z-]+)(?:\.|$) のように最初の prerelease identifier を厳密に取り、マッチしない場合は tag を付与しない/明示的に失敗させる、のいずれかにした方が安全です。

Suggested change
if echo "$VERSION" | grep -q '-'; then
PRERELEASE_ID=$(echo "$VERSION" | sed 's/.*-\([a-zA-Z]*\).*/\1/')
echo "tag=--tag $PRERELEASE_ID" >> "$GITHUB_OUTPUT"
else
echo "tag=" >> "$GITHUB_OUTPUT"
PRERELEASE_ID=$(node -p "(() => { const v = require('./package.json').version; const m = v.match(/-(?<id>[0-9A-Za-z-]+)(?:\\.|$)/); return m ? m.groups.id : ''; })()")
if [ -n \"$PRERELEASE_ID\" ]; then
echo \"tag=--tag $PRERELEASE_ID\" >> \"$GITHUB_OUTPUT\"
else
echo \"tag=\" >> \"$GITHUB_OUTPUT\"

Copilot uses AI. Check for mistakes.
KinjiKawaguchi added a commit that referenced this pull request Mar 31, 2026
## Why

prerelease バージョン(`3.0.0-rc.1` 等)を `npm publish` する際、`--tag` オプションが未指定のため
publish が失敗する。
https://github.com/su-its/core/actions/runs/23796409089/job/69344776248

## What

package.json のバージョンにハイフンが含まれる場合、prerelease ID(`rc`, `beta` 等)を抽出して
`--tag` に指定する。

- `3.0.0-rc.1` → `npm publish --access public --tag rc`
- `3.0.0-beta.1` → `npm publish --access public --tag beta`
- `3.0.0` → `npm publish --access public`(latest)

🤖 Generated with [Claude Code](https://claude.com/claude-code) <!--
devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/su-its/core/pull/132"
target="_blank">
  <picture>
<source media="(prefers-color-scheme: dark)"

srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
<img

src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1"
alt="Open with Devin">
  </picture>
</a>
<!-- devin-review-badge-end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants