Skip to content

Commit

Permalink
feat: update build and release scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
shaobeichen committed Nov 1, 2024
1 parent d56fe36 commit 040e98d
Show file tree
Hide file tree
Showing 14 changed files with 11,885 additions and 107 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/blank.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 工作流名称
name: Build and Deploy

on:
# 指明要运行的分支,跟上面配置保持一致
push:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
# 把分支拉出来
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

# 指定node版本
- name: Set node version
uses: actions/setup-node@v4
with:
node-version: '20'

# 安装依赖,包括我们的 semantic-release 全套
- name: Install
run: npm install

# 执行 semantic-release 发布包
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
run: npx semantic-release
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18
v20
28 changes: 28 additions & 0 deletions .releaserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = {
branches: ['main'], // 指定在哪个分支下要执行发布操作
plugins: [
'@semantic-release/commit-analyzer', // 用于分析提交的类型,feat和fix类型都会发版和升级版本号
'@semantic-release/release-notes-generator', // 生成 CHANGELOG.md 文件
[
'@semantic-release/changelog', // 将 commit 记录到项目的 changelog 文件中
{
changelogFile: 'CHANGELOG.md',
},
],
[
'@semantic-release/exec',
{
// 这里可以运行你的自定义脚本
prepareCmd: 'node ./scripts/build.js ${nextRelease.version} && node ./scripts/release.js',
},
],
'@semantic-release/npm', // 用来更新 package.json 的,如果不需要发到 npm 可以设 npmPublish 为 false
'@semantic-release/github', // 发布 GitHub Release 并对已发布的拉取请求/问题发表评论。
[
'@semantic-release/git', // 把发版过程中修改的文件提交到 Git 仓库
{
assets: ['CHANGELOG.md', 'package.json'],
},
],
],
}
22 changes: 2 additions & 20 deletions install.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
const fs = require('fs')
const os = require('os')
const path = require('path')
const child_process = require('child_process')
const data = require('./package.json')
const utils = require('./utils')

const versionFromPackageJSON = data.version

const packages = {
'darwin arm64': '@grprogress/darwin-arm64',
'darwin x64': '@grprogress/darwin-amd64',
'linux x64': '@grprogress/linux-amd64',
'win32 x64': '@grprogress/windows-amd64',
}

/**
* 根据当前系统信息获取对应的包信息
*/
function getPackageInfoByCurrentPlatform() {
const key = `${process.platform} ${os.arch()}`
return {
packageName: packages[key],
platform: process.platform,
}
}

/**
* 日志格式化
*/
Expand Down Expand Up @@ -109,7 +91,7 @@ function firstInstall(pkg, subpath, binPath, fail) {
}

async function main() {
const { packageName, platform } = getPackageInfoByCurrentPlatform()
const { packageName, platform } = utils.getPackageInfoByCurrentPlatform()

const binFilename = 'grprogress'
const subpath = platform === 'win32' ? binFilename + '.exe' : binFilename
Expand Down
12 changes: 6 additions & 6 deletions npm/package.json.template
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "${name}",
"version": "${version}",
"name": "{{name}}",
"version": "{{version}}",
"description": "a gradient progress for nodejs by go",
"main": "${file}",
"main": "{{file}}",
"files": [
"${file}"
"{{file}}"
],
"repository": {
"type": "git",
Expand All @@ -23,9 +23,9 @@
"bubble"
],
"os": [
"${os}"
"{{os}}"
],
"cpu": [
"${cpu}"
"{{cpu}}"
]
}
Loading

0 comments on commit 040e98d

Please sign in to comment.