Skip to content

Commit 40adce2

Browse files
committed
ci: add publish workflow
1 parent 76a5913 commit 40adce2

File tree

7 files changed

+77
-61
lines changed

7 files changed

+77
-61
lines changed

.github/workflows/publish.yml

Lines changed: 37 additions & 0 deletions
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*
7+
8+
jobs:
9+
publish:
10+
if: github.repository == 'qmhc/vite-plugin-dts'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Install pnpm
18+
uses: pnpm/action-setup@v2
19+
20+
- name: Set node
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: 18.x
24+
registry-url: https://registry.npmjs.org/
25+
cache: pnpm
26+
27+
- name: Install deps
28+
run: pnpm install
29+
30+
- name: Build
31+
run: pnpm run build
32+
33+
- name: Publish package
34+
run: pnpm run publish:ci ${{ github.ref_name }}
35+
env:
36+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
37+
NODE_OPTIONS: --max-old-space-size=4096

.github/workflows/release.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ on:
66
- v*
77

88
jobs:
9-
build:
10-
name: Create Release
9+
release:
10+
if: github.repository == 'qmhc/vite-plugin-dts'
1111
runs-on: ubuntu-latest
1212
steps:
13-
- name: Checkout code
14-
uses: actions/checkout@master
13+
- uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set node
18+
uses: actions/setup-node@v3
19+
with:
20+
node-version: 18.x
1521

16-
- name: Create Release for Tag
17-
id: release_tag
18-
uses: yyx990803/release-tag@master
22+
- run: npx changelogithub
1923
env:
2024
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21-
with:
22-
tag_name: ${{ github.ref }}
23-
body: |
24-
Please refer to [CHANGELOG.md](https://github.com/qmhc/vite-plugin-dts/blob/main/CHANGELOG.md) for details.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"prepublishOnly": "pinst --disable",
1616
"prettier": "pretty-quick --staged && pnpm run lint",
1717
"postpublish": "pinst --enable",
18+
"publish:ci": "tsx scripts/publish.ts",
1819
"release": "tsx scripts/release.ts",
1920
"test": "vitest run",
2021
"test:dev": "vitest",

scripts/constant.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { resolve } from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
4+
export const rootDir = resolve(fileURLToPath(import.meta.url), '../..')

scripts/logger.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

scripts/publish.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import minimist from 'minimist'
2+
import { logger, publish } from '@vexip-ui/scripts'
3+
import { rootDir } from './constant'
4+
5+
const args = minimist<{
6+
d?: boolean,
7+
dry?: boolean,
8+
t?: string,
9+
tag?: string
10+
}>(process.argv.slice(2))
11+
12+
const isDryRun = args.dry || args.d
13+
const releaseTag = args.tag || args.t
14+
15+
publish({
16+
pkgDir: rootDir,
17+
isDryRun,
18+
releaseTag
19+
}).catch(error => {
20+
logger.error(error)
21+
process.exit(1)
22+
})

scripts/release.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import path from 'node:path'
2-
import { fileURLToPath } from 'node:url'
31
import minimist from 'minimist'
4-
import { logger } from './logger'
5-
import { release, run } from '@vexip-ui/scripts'
2+
import { logger, release, run } from '@vexip-ui/scripts'
3+
import { rootDir } from './constant'
64

75
const args = minimist<{
86
d?: boolean,
@@ -16,8 +14,6 @@ const args = minimist<{
1614
const isDryRun = args.dry || args.d
1715
const preId = args.preid || args.p
1816

19-
const rootDir = path.resolve(fileURLToPath(import.meta.url), '../..')
20-
2117
release({
2218
pkgDir: rootDir,
2319
isDryRun,

0 commit comments

Comments
 (0)