Skip to content

Commit 8013d90

Browse files
authored
workflow: separate version bumping and publishing on release (#6879)
1 parent 633532c commit 8013d90

File tree

8 files changed

+359
-277
lines changed

8 files changed

+359
-277
lines changed

.github/workflows/publish.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish Package
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
7+
- "plugin-*" # Push events to matching plugin-*, i.e. plugin-(vue|vue-jsx|react|legacy)@1.0.0
8+
- "create-vite*" # # Push events to matching create-vite*, i.e. [email protected]
9+
10+
jobs:
11+
publish:
12+
# prevents this action from running on forks
13+
if: github.repository == 'vitejs/vite'
14+
runs-on: ubuntu-latest
15+
environment: Release
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
20+
- name: Install pnpm
21+
uses: pnpm/action-setup@v2
22+
with:
23+
version: 6
24+
25+
- name: Set node version to 16.x
26+
uses: actions/setup-node@v2
27+
with:
28+
node-version: 16.x
29+
cache: "pnpm"
30+
31+
- name: Install deps
32+
run: pnpm install
33+
34+
- name: Publish package
35+
run: pnpm run ci-publish -- ${{ github.ref_name }} --dry
36+
env:
37+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/release.yml

-79
This file was deleted.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
"docs": "vitepress dev docs",
2525
"build-docs": "vitepress build docs",
2626
"serve-docs": "vitepress serve docs",
27+
"release": "ts-node scripts/release.ts",
28+
"ci-publish": "ts-node scripts/publishCI.ts",
2729
"build": "run-s build-vite build-plugin-vue build-plugin-react",
2830
"build-vite": "cd packages/vite && npm run build",
2931
"build-plugin-vue": "cd packages/plugin-vue && npm run build",

packages/plugin-vue-jsx/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
],
1010
"main": "index.js",
1111
"types": "index.d.ts",
12-
"scripts": {
13-
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue-jsx",
14-
"release": "ts-node ../../scripts/release.ts --skipBuild"
15-
},
1612
"engines": {
1713
"node": ">=12.0.0"
1814
},

packages/plugin-vue/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:@vue/compiler-sfc --external:vue/compiler-sfc --external:vite --outfile=dist/index.js & npm run patch-dist",
1717
"patch-dist": "ts-node ../../scripts/patchEsbuildDist.ts dist/index.js vuePlugin",
1818
"build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp",
19-
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue",
20-
"release": "ts-node ../../scripts/release.ts"
19+
"prepublishOnly": "npm run build"
2120
},
2221
"engines": {
2322
"node": ">=12.0.0"

scripts/publishCI.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { args, getPackageInfo, publishPackage, step } from './releaseUtils'
2+
3+
async function main() {
4+
const tag = args._[0]
5+
6+
if (!tag) {
7+
throw new Error('No tag specified')
8+
}
9+
10+
let pkgName = 'vite'
11+
let version
12+
13+
if (tag.includes('@')) [pkgName, version] = tag.split('@')
14+
else version = tag
15+
16+
if (version.startsWith('v')) version = version.slice(1)
17+
18+
const { currentVersion, pkgDir } = getPackageInfo(pkgName)
19+
if (currentVersion !== version)
20+
throw new Error(
21+
`Package version from tag "${version}" mismatches with current version "${currentVersion}"`
22+
)
23+
24+
step('Publishing package...')
25+
await publishPackage(pkgDir, version.includes('beta') ? 'beta' : undefined)
26+
}
27+
28+
main().catch((err) => {
29+
console.error(err)
30+
process.exit(1)
31+
})

0 commit comments

Comments
 (0)