Skip to content

Commit 83e4e47

Browse files
committed
refactor: streamline auto-release workflow and improve version checking logic
1 parent 81cc4cf commit 83e4e47

File tree

1 file changed

+30
-49
lines changed

1 file changed

+30
-49
lines changed

.github/workflows/auto-release.yml

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
- name: Setup Node.js
2424
uses: actions/setup-node@v4
2525
with:
26-
node-version: '18'
27-
cache: 'pnpm'
26+
node-version: "18"
27+
cache: "pnpm"
2828

2929
- name: Install dependencies
3030
run: pnpm install --frozen-lockfile
@@ -58,9 +58,9 @@ jobs:
5858
- name: Setup Node.js
5959
uses: actions/setup-node@v4
6060
with:
61-
node-version: '18'
62-
registry-url: 'https://registry.npmjs.org'
63-
cache: 'pnpm'
61+
node-version: "18"
62+
registry-url: "https://registry.npmjs.org"
63+
cache: "pnpm"
6464

6565
- name: Install dependencies
6666
run: pnpm install --frozen-lockfile
@@ -73,64 +73,48 @@ jobs:
7373
git config --local user.email "action@github.com"
7474
git config --local user.name "GitHub Action"
7575
76-
- name: Determine version bump
77-
id: bump
76+
- name: Check if release is needed
77+
id: check_release
7878
run: |
79-
# Get the last commit message
80-
COMMIT_MSG=$(git log -1 --pretty=%B)
81-
echo "Commit message: $COMMIT_MSG"
82-
83-
# Determine bump type based on commit message
84-
if echo "$COMMIT_MSG" | grep -i "BREAKING CHANGE\|major:"; then
85-
echo "bump=major" >> $GITHUB_OUTPUT
86-
echo "Detected MAJOR version bump"
87-
elif echo "$COMMIT_MSG" | grep -i "feat:\|feature:\|minor:"; then
88-
echo "bump=minor" >> $GITHUB_OUTPUT
89-
echo "Detected MINOR version bump"
79+
# Get the version from the merged package.json
80+
CURRENT_VERSION=$(node -p "require('./package.json').version")
81+
echo "Version in package.json is $CURRENT_VERSION"
82+
83+
# Check if a git tag for this version already exists
84+
if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
85+
echo "Tag v$CURRENT_VERSION already exists. Skipping release."
86+
echo "skip=true" >> $GITHUB_OUTPUT
9087
else
91-
echo "bump=patch" >> $GITHUB_OUTPUT
92-
echo "Detected PATCH version bump"
88+
echo "Tag v$CURRENT_VERSION does not exist. Proceeding with release."
89+
echo "skip=false" >> $GITHUB_OUTPUT
90+
echo "VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
9391
fi
9492
95-
- name: Bump version
96-
run: |
97-
pnpm version ${{ steps.bump.outputs.bump }} -m "chore: release v%s [skip ci]"
98-
echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
99-
10093
- name: Create and push tag
94+
if: steps.check_release.outputs.skip == 'false'
10195
run: |
102-
git fetch --tags
103-
# Check if tag already exists for this commit
104-
if [ -z "$(git tag --points-at HEAD)" ]; then
105-
git tag v${{ env.VERSION }}
106-
git push origin v${{ env.VERSION }}
107-
echo "Created and pushed tag v${{ env.VERSION }}"
108-
else
109-
echo "Tag already exists for this commit"
110-
fi
96+
git tag v${{ env.VERSION }}
97+
git push origin v${{ env.VERSION }}
98+
echo "Created and pushed tag v${{ env.VERSION }}"
11199
112100
- name: Generate changelog
101+
if: steps.check_release.outputs.skip == 'false'
113102
run: |
114103
# Create a simple changelog entry
115104
echo "## v${{ env.VERSION }} ($(date +'%Y-%m-%d'))" > release-notes.md
116105
echo "" >> release-notes.md
117106
echo "### Changes" >> release-notes.md
118-
# Try to get commits since last tag, or get last 10 commits if no tags
119-
if git describe --tags --abbrev=0 HEAD^ 2>/dev/null; then
120-
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^)
121-
git log --oneline --pretty=format:"- %s" ${LAST_TAG}..HEAD >> release-notes.md
122-
else
123-
echo "- Initial release" >> release-notes.md
124-
git log --oneline --pretty=format:"- %s" -10 >> release-notes.md || true
125-
fi
126-
echo "" >> release-notes.md
107+
# Get commits since last tag
108+
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^)
109+
git log --oneline --pretty=format:"- %s" ${LAST_TAG}..HEAD >> release-notes.md
127110
echo "" >> release-notes.md
128111
echo "### Installation" >> release-notes.md
129112
echo "\`\`\`bash" >> release-notes.md
130113
echo "npm install --save-dev vite-plugin-component-debugger@${{ env.VERSION }}" >> release-notes.md
131114
echo "\`\`\`" >> release-notes.md
132115
133116
- name: Create GitHub Release
117+
if: steps.check_release.outputs.skip == 'false'
134118
id: create_release
135119
uses: actions/create-release@v1
136120
env:
@@ -143,17 +127,14 @@ jobs:
143127
prerelease: false
144128

145129
- name: Publish to NPM
130+
if: steps.check_release.outputs.skip == 'false'
146131
run: pnpm publish --access public --no-git-checks
147132
env:
148133
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
149134

150-
- name: Push version bump
151-
run: |
152-
git push origin main
153-
# Tags are already pushed in "Create and push tag" step
154-
155135
- name: Success notification
136+
if: steps.check_release.outputs.skip == 'false'
156137
run: |
157138
echo "🎉 Successfully released v${{ env.VERSION }}"
158139
echo "📦 NPM: https://www.npmjs.com/package/vite-plugin-component-debugger"
159-
echo "🏷️ GitHub: ${{ steps.create_release.outputs.html_url }}"
140+
echo "🏷️ GitHub: ${{ steps.create_release.outputs.html_url }}"

0 commit comments

Comments
 (0)