Skip to content

Commit 7b44bad

Browse files
Refactor release workflow for push and dispatch triggers
Updated release workflow to trigger on push and workflow dispatch events. Removed PR-related conditions and streamlined version tagging process.
1 parent 9146bb4 commit 7b44bad

1 file changed

Lines changed: 41 additions & 68 deletions

File tree

.github/workflows/release.yml

Lines changed: 41 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
11
name: Release
22

33
on:
4-
pull_request:
4+
workflow_dispatch:
5+
push:
56
branches:
67
- master
7-
types:
8-
- closed
98

109
jobs:
11-
release:
12-
# Only run when the PR is merged (not just closed) and comes from auto-version-bump branch
13-
if: github.event.pull_request.merged == true && github.event.pull_request.head.ref == 'auto-version-bump'
10+
auto-tag:
1411
runs-on: ubuntu-latest
15-
permissions:
16-
contents: write
17-
id-token: write
18-
12+
if: github.event_name == 'push' && startsWith(github.event.head_commit.message, 'v')
1913
steps:
20-
- name: Extract version from PR title
21-
id: version
14+
- uses: actions/checkout@v4
15+
with:
16+
token: ${{ secrets.GITHUB_TOKEN }}
17+
- name: Create tag from commit message
2218
run: |
23-
PR_TITLE="${{ github.event.pull_request.title }}"
24-
echo "PR title: $PR_TITLE"
25-
26-
if [[ "$PR_TITLE" =~ ^v?([0-9]+\.[0-9]+\.[0-9]+) ]]; then
27-
VERSION="${BASH_REMATCH[1]}"
28-
echo "version=$VERSION" >> $GITHUB_OUTPUT
29-
echo "Extracted version: $VERSION"
19+
COMMIT_MSG=$(git log -1 --pretty=%B)
20+
if [[ $COMMIT_MSG =~ ^(v[0-9]+\.[0-9]+\.[0-9]+) ]]; then
21+
TAG_NAME="${BASH_REMATCH[1]}"
22+
git config user.name "github-actions[bot]"
23+
git config user.email "github-actions[bot]@users.noreply.github.com"
24+
git tag -a "$TAG_NAME" -m "Release $TAG_NAME"
25+
git push origin "$TAG_NAME"
26+
echo "Tag $TAG_NAME created"
3027
else
31-
echo "PR title does not contain a valid version number"
28+
echo "Invalid version format"
3229
exit 1
3330
fi
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3433

34+
publish-npm:
35+
permissions:
36+
contents: read
37+
id-token: write
38+
runs-on: ubuntu-latest
39+
needs: [auto-tag]
40+
if: github.event_name == 'workflow_dispatch' || success()
41+
steps:
3542
- uses: actions/checkout@v4
36-
with:
37-
fetch-depth: 0
38-
token: ${{ secrets.GITHUB_TOKEN }}
3943

4044
- uses: pnpm/action-setup@v4
4145

@@ -46,60 +50,29 @@ jobs:
4650
registry-url: "https://registry.npmjs.org/"
4751

4852
- name: Install Lerna Lite
49-
run: pnpm add -g @lerna-lite/cli @lerna-lite/publish @lerna-lite/version @lerna-lite/exec
53+
run: pnpm add -g @lerna-lite/cli @lerna-lite/publish
5054

5155
- name: Install dependencies
5256
run: pnpm install --frozen-lockfile
5357

54-
- name: Check if version override is needed
55-
id: check_override
56-
run: |
57-
TARGET_VERSION="${{ steps.version.outputs.version }}"
58-
CURRENT_VERSION=$(node -e "console.log(require('./lerna.json').version)")
59-
echo "Target: $TARGET_VERSION, Current in repo: $CURRENT_VERSION"
60-
61-
if [ "$TARGET_VERSION" != "$CURRENT_VERSION" ]; then
62-
echo "override=true" >> $GITHUB_OUTPUT
63-
echo "Version override needed: $CURRENT_VERSION -> $TARGET_VERSION"
64-
else
65-
echo "override=false" >> $GITHUB_OUTPUT
66-
echo "Version matches, no override needed"
67-
fi
68-
69-
- name: Override version if PR title was changed
70-
if: steps.check_override.outputs.override == 'true'
71-
run: |
72-
TARGET_VERSION="${{ steps.version.outputs.version }}"
73-
74-
git config user.name "github-actions[bot]"
75-
git config user.email "github-actions[bot]@users.noreply.github.com"
76-
77-
lerna version "$TARGET_VERSION" \
78-
--yes --no-push --no-git-tag-version --force-publish --exact
79-
80-
git add -A
81-
git commit -m "v$TARGET_VERSION" --allow-empty
82-
git push origin master
83-
84-
- name: Create git tag
85-
run: |
86-
VERSION="${{ steps.version.outputs.version }}"
87-
TAG_NAME="v$VERSION"
88-
89-
git config user.name "github-actions[bot]"
90-
git config user.email "github-actions[bot]@users.noreply.github.com"
91-
92-
git tag -a "$TAG_NAME" -m "Release $TAG_NAME"
93-
git push origin "$TAG_NAME"
94-
echo "Tag $TAG_NAME created"
95-
9658
- name: Build
9759
run: npm run build
9860

9961
- name: Publish to NPM
10062
run: lerna publish from-package --yes
10163

64+
- name: Wait for npm registry sync
65+
run: sleep 30
66+
10267
- name: Add dist-tag volar-2.4
10368
run: |
104-
lerna exec --no-bail --no-private --no-sort --stream -- \
105-
'[ -n "$(npm v . dist-tags.latest)" ] && npm dist-tag add ${LERNA_PACKAGE_NAME}@$(npm v . dist-tags.latest) volar-2.4'
69+
for pkg in $(ls -d packages/*/); do
70+
PKG_NAME=$(node -e "console.log(require('./$pkg/package.json').name)")
71+
PKG_PRIVATE=$(node -e "console.log(require('./$pkg/package.json').private || false)")
72+
if [ "$PKG_PRIVATE" != "true" ]; then
73+
LATEST=$(npm v "$PKG_NAME" dist-tags.latest 2>/dev/null || echo "")
74+
if [ -n "$LATEST" ]; then
75+
npm dist-tag add "$PKG_NAME@$LATEST" volar-2.4 || true
76+
fi
77+
fi
78+
done

0 commit comments

Comments
 (0)