Skip to content

Commit fe8ef39

Browse files
authored
workflow: separate version bumping and publishing on release (#6879)
1 parent 6ea6e08 commit fe8ef39

File tree

13 files changed

+361
-312
lines changed

13 files changed

+361
-312
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/create-vite/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
"template-*"
1313
],
1414
"main": "index.js",
15-
"scripts": {
16-
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package create-vite",
17-
"release": "ts-node updateVersions && ts-node ../../scripts/release.ts --skipBuild"
18-
},
1915
"engines": {
2016
"node": ">=12.0.0"
2117
},

packages/create-vite/updateVersions.ts

-23
This file was deleted.

packages/plugin-legacy/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-legacy",
14-
"release": "ts-node ../../scripts/release.ts --skipBuild"
15-
},
1612
"engines": {
1713
"node": ">=12.0.0"
1814
},

packages/plugin-react/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
"build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:@babel/* --external:@rollup/* --external:resolve --external:react-refresh/* --outfile=dist/index.js && npm run patch-dist",
1919
"patch-dist": "ts-node ../../scripts/patchEsbuildDist.ts dist/index.js viteReact",
2020
"build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp",
21-
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-react",
22-
"release": "ts-node ../../scripts/release.ts"
21+
"prepublishOnly": "npm run build"
2322
},
2423
"engines": {
2524
"node": ">=12.0.0"

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"

packages/vite/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
"roll-types": "api-extractor run && rimraf temp",
4040
"lint": "eslint --ext .ts src/**",
4141
"format": "prettier --write --parser typescript \"src/**/*.ts\"",
42-
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path .",
43-
"release": "ts-node ../../scripts/release.ts"
42+
"prepublishOnly": "npm run build"
4443
},
4544
"//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
4645
"dependencies": {

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)