Skip to content

Commit 888ded7

Browse files
committed
Enhance publish workflow and release script
1 parent 1760a18 commit 888ded7

2 files changed

Lines changed: 28 additions & 38 deletions

File tree

.github/workflows/publish.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: Publish to npm
22

3+
# Trigger when a new tag matching the pattern is created and pushed
34
on:
45
push:
56
tags:
@@ -9,7 +10,7 @@ jobs:
910
publish:
1011
runs-on: ubuntu-latest
1112
permissions:
12-
contents: read
13+
contents: write
1314
id-token: write
1415

1516
steps:
@@ -35,8 +36,31 @@ jobs:
3536
TAG=${GITHUB_REF#refs/tags/}
3637
VERSION=${TAG#v}
3738
echo "version=$VERSION" >> $GITHUB_OUTPUT
39+
echo "tag=$TAG" >> $GITHUB_OUTPUT
3840
echo "Extracted version: $VERSION from tag: $TAG"
3941
42+
- name: Get tag message
43+
id: tag_message
44+
run: |
45+
TAG="${{ steps.version.outputs.tag }}"
46+
TAG_MESSAGE=$(git tag -l --format='%(contents)' "$TAG" 2>/dev/null || echo "")
47+
if [ -z "$TAG_MESSAGE" ]; then
48+
TAG_MESSAGE="Release $TAG"
49+
fi
50+
echo "message<<EOF" >> $GITHUB_OUTPUT
51+
echo "$TAG_MESSAGE" >> $GITHUB_OUTPUT
52+
echo "EOF" >> $GITHUB_OUTPUT
53+
54+
- name: Create GitHub Release
55+
run: |
56+
TAG="${{ steps.version.outputs.tag }}"
57+
BODY="${{ steps.tag_message.outputs.message }}"
58+
gh release create "$TAG" \
59+
--title "Release $TAG" \
60+
--notes "$BODY"
61+
env:
62+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
4064
- name: Update package.json version (CI only, not committed)
4165
run: |
4266
npm version "${{ steps.version.outputs.version }}" --no-git-tag-version

scripts/trigger-release.sh

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,6 @@ if [ "$DRY_RUN" = true ]; then
151151
echo "---"
152152
echo ""
153153

154-
# Check for unpushed commits
155-
git fetch origin
156-
LOCAL_COMMITS=$(git log origin/main..HEAD --oneline 2>/dev/null || git log origin/master..HEAD --oneline 2>/dev/null || echo "")
157-
if [ -n "$LOCAL_COMMITS" ]; then
158-
echo "Local commits that would be pushed:"
159-
echo "$LOCAL_COMMITS"
160-
echo ""
161-
fi
162-
163154
echo "🚫 DRY RUN: No tag created, nothing pushed"
164155
else
165156
# Check if tag already exists
@@ -168,31 +159,6 @@ else
168159
exit 1
169160
fi
170161

171-
# Fetch to check for unpushed commits
172-
echo "Checking for unpushed commits..."
173-
git fetch origin
174-
175-
# Determine the main branch name
176-
MAIN_BRANCH="main"
177-
if ! git show-ref --verify --quiet refs/remotes/origin/main; then
178-
MAIN_BRANCH="master"
179-
fi
180-
181-
# Check if there are local commits to push
182-
LOCAL_COMMITS=$(git log origin/$MAIN_BRANCH..HEAD --oneline 2>/dev/null || echo "")
183-
if [ -n "$LOCAL_COMMITS" ]; then
184-
echo "Pushing local commits first..."
185-
echo "Commits to push:"
186-
echo "$LOCAL_COMMITS"
187-
echo ""
188-
git push origin HEAD:$MAIN_BRANCH
189-
echo "✓ Local commits pushed"
190-
echo ""
191-
else
192-
echo "No local commits to push"
193-
echo ""
194-
fi
195-
196162
# Create tag with message
197163
echo "Creating tag $TAG_NAME..."
198164
if [ -z "$CHANGES" ]; then
@@ -207,11 +173,11 @@ else
207173
fi
208174
fi
209175

210-
# Push tag to trigger CI/CD
176+
# Push tag to trigger publish workflow
211177
echo "Pushing tag to remote..."
212178
git push origin "$TAG_NAME"
213179

214-
echo "Release $TAG_NAME triggered successfully!"
215-
echo "The CI workflow will automatically build and publish to npm."
180+
echo "Tag $TAG_NAME created and pushed successfully!"
181+
echo "The publish workflow will automatically build and publish to npm."
216182
fi
217183

0 commit comments

Comments
 (0)