Skip to content

Commit e1120da

Browse files
authored
Tag branch package versions with branch name (#346)
1 parent 2e08299 commit e1120da

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

.github/workflows/publish-preview.yml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,40 @@ jobs:
3838
- name: Build packages
3939
run: pnpm build
4040

41-
- name: Generate version string
41+
- name: Generate version string and tag
4242
id: version
4343
run: |
4444
BRANCH="${GITHUB_REF_NAME}"
45-
# Sanitize branch name for npm (replace / with -)
45+
46+
# Error if branch is named "preview" (reserved for main branch tag)
47+
if [ "$BRANCH" = "preview" ]; then
48+
echo "::error::Branch name 'preview' is reserved. The 'preview' tag is used for main branch publishes."
49+
exit 1
50+
fi
51+
52+
# Determine the npm tag: "preview" for main, branch name for others
53+
if [ "$BRANCH" = "main" ]; then
54+
TAG="preview"
55+
else
56+
# Sanitize branch name for npm tag (replace invalid chars with -)
57+
TAG=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9-]/-/g' | sed 's/--*/-/g' | sed 's/^-//' | sed 's/-$//')
58+
fi
59+
60+
# Sanitize branch name for version string
4661
BRANCH_SAFE=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9-]/-/g' | sed 's/--*/-/g' | sed 's/^-//' | sed 's/-$//')
4762
SHORT_SHA="${GITHUB_SHA::7}"
4863
VERSION="0.0.0-${BRANCH_SAFE}.${SHORT_SHA}"
64+
4965
echo "version=$VERSION" >> $GITHUB_OUTPUT
5066
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
51-
echo "Publishing version: $VERSION"
67+
echo "tag=$TAG" >> $GITHUB_OUTPUT
68+
echo "Publishing version: $VERSION with tag: $TAG"
5269
5370
- name: Update package versions
5471
run: pnpm -r exec npm version ${{ steps.version.outputs.version }} --no-git-tag-version
5572

5673
- name: Publish packages
57-
run: pnpm -r publish --access public --tag preview --no-git-checks
74+
run: pnpm -r publish --access public --tag ${{ steps.version.outputs.tag }} --no-git-checks
5875
env:
5976
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6077

@@ -63,10 +80,11 @@ jobs:
6380
echo "## Published Packages" >> $GITHUB_STEP_SUMMARY
6481
echo "" >> $GITHUB_STEP_SUMMARY
6582
echo "Version: \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
83+
echo "Tag: \`${{ steps.version.outputs.tag }}\`" >> $GITHUB_STEP_SUMMARY
6684
echo "" >> $GITHUB_STEP_SUMMARY
6785
echo "Install with:" >> $GITHUB_STEP_SUMMARY
6886
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
69-
echo "pnpm add @casekit/orm@${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
87+
echo "pnpm add @casekit/orm@${{ steps.version.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
7088
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
7189
7290
cleanup:

0 commit comments

Comments
 (0)