Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
51 changes: 51 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,57 @@ jobs:
name: publish package versions
command: |
bun ./publish-version.mjs
- run:
name: create GitHub release from version tag
command: |
if [ -z "$GH_TOKEN" ]; then
echo "GH_TOKEN is required to create GitHub releases."
exit 1
fi

if [ ! -f ./version.txt ]; then
echo "version.txt was not found; cannot create release."
exit 1
fi

VERSION=$(tr -d '\r\n' < ./version.txt)
TAG="v${VERSION}"
IS_PRERELEASE=false

if [ "$CIRCLE_BRANCH" = "beta" ]; then
IS_PRERELEASE=true
fi

RELEASE_PAYLOAD=$(cat \<<EOF
{
"tag_name": "${TAG}",
"target_commitish": "${CIRCLE_SHA1}",
"name": "${TAG}",
"body": "Automated release for ${TAG}",
"draft": false,
"prerelease": ${IS_PRERELEASE},
"generate_release_notes": true
}
EOF
)

HTTP_CODE=$(curl -sS -o /tmp/create-release-response.json -w "%{http_code}" \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/releases" \
-d "${RELEASE_PAYLOAD}")

if [ "$HTTP_CODE" = "201" ]; then
echo "Created GitHub release for ${TAG}."
elif [ "$HTTP_CODE" = "422" ]; then
echo "Release for ${TAG} already exists; treating as success."
Comment on lines +225 to +226
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Overly broad 422 suppression

A 422 from the GitHub Releases API means any validation failure (bad JSON, invalid tag format, duplicate name, etc.), not just an already-existing release. Silently treating all 422 responses as success will hide misconfiguration bugs. To be safe, parse the response and check for the specific "already_exists" error code before suppressing the failure.

Prompt To Fix With AI
This is a comment left during a code review.
Path: .circleci/config.yml
Line: 225-226

Comment:
**Overly broad 422 suppression**

A 422 from the GitHub Releases API means *any* validation failure (bad JSON, invalid tag format, duplicate name, etc.), not just an already-existing release. Silently treating all 422 responses as success will hide misconfiguration bugs. To be safe, parse the response and check for the specific `"already_exists"` error code before suppressing the failure.

How can I resolve this? If you propose a fix, please make it concise.

else
echo "Failed to create release. HTTP status: $HTTP_CODE"
cat /tmp/create-release-response.json
exit 1
fi
- run:
name: Again set the NPM registry (was deleted in the version script)
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/repo/.npmrc
Expand Down
2 changes: 0 additions & 2 deletions publish-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ async function run() {
'--message',
`chore(version): Update package versions to ${nextVersion} [skip ci]`,
'--conventional-commits',
'--create-release',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so why is this not working anymore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated lerna version

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Might also be missing GH_TOKEN, which is a silent failure in newer lerna versions.

'github',
'--no-push',
]);

Expand Down
Loading