Skip to content

Commit

Permalink
Merge pull request #35 from VisActor/chore/34-chore-pre-release-workflow
Browse files Browse the repository at this point in the history
chore: add pre-release
  • Loading branch information
fangsmile committed Jun 15, 2023
2 parents cf0de2a + 1a709f5 commit f2c225e
Show file tree
Hide file tree
Showing 8 changed files with 1,332 additions and 933 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Pre-release CI

on:
push:
branches:
- pre-release/*

jobs:
build:
runs-on: macOS-latest # 如果用了electron,记得改成 macOS-latest

permissions:
contents: write

strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: './common/config/rush/pnpm-lock.yaml'

# Install rush
- name: Install rush
run: node common/scripts/install-run-rush.js install --bypass-policy

- name: Build packages
run: node common/scripts/install-run-rush.js build --only tag:package

- name: Parse semver version from branch name
id: semver_parser
uses: release-kit/semver@v2
with:
string: ${{ github.ref_name }}
pattern: '^pre-release/(.*)$' # ^v?(.*)$ by default

- name: Apply prereleaseName
run: node common/scripts/install-run-rush.js publish --apply --prerelease-name ${{ steps.semver_parser.outputs.prerelease }} --partial-prerelease

- name: Publish to npm
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
NPM_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: node common/scripts/install-run-rush.js publish --publish --include-all --tag ${{ steps.semver_parser.outputs.prerelease }}

- name: Update shrinkwrap
run: node common/scripts/install-run-rush.js update

- name: Get package version
id: package-version
uses: culshaw/read-package-node-version-actions@v1
with:
path: './packages/vtable' # 各项目需要修改一下

- name: Commit & Push changes
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: 'build: prelease version ${{ steps.package-version.outputs.version }}'
branch: ${{ github.ref_name }}
author_name: ${{ github.actor }}
80 changes: 80 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Release CI

on:
push:
branches:
- release/*

jobs:
build:
runs-on: macOS-latest # 如果用了electron,记得改成 macOS-latest
permissions:
contents: write
pull-requests: write

strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- run: |
git config user.name ${{ github.actor }}
git config user.email ${{ github.actor }}@users.noreply.github.com
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: './common/config/rush/pnpm-lock.yaml'

# Install rush
- name: Install rush
run: node common/scripts/install-run-rush.js install --bypass-policy

- name: Build packages
run: node common/scripts/install-run-rush.js version --bump

- name: Publish to npm
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
NPM_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: node common/scripts/install-run-rush.js publish --publish --include-all

- name: Update shrinkwrap
run: node common/scripts/install-run-rush.js update

- name: Get package version
id: package-version
uses: culshaw/read-package-node-version-actions@v1
with:
path: './packages/vtable' # 各项目修改一下

- name: Commit & Push changes
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: 'build: prelease version ${{ steps.package-version.outputs.version }}'
branch: ${{ github.ref_name }}

- name: Create Release for Tag
id: release_tag
# See more about this action: https://github.com/actions/create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.package-version.outputs.version }}
release_name: Release v${{ steps.package-version.outputs.version }}
prerelease: false #

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: main
branch: ${{ github.ref_name }}
title: '[Auto release] release ${{ steps.package-version.outputs.version }}'
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
43 changes: 43 additions & 0 deletions common/autoinstallers/lint/change-all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import path from 'path';
import chalk from 'chalk';
import minimist, { ParsedArgs } from 'minimist';
import { spawnSync } from 'child_process';

interface RunScriptArgv extends ParsedArgs {
message?: string;
type?: string;
}

function run() {
const commitLineConfigPath = path.resolve(__dirname, './commitlint.config.js');
const commitLintBinPath = path.resolve(__dirname, './node_modules/.bin/commitlint');
const argv: RunScriptArgv = minimist(process.argv.slice(2));
const message = argv.message;
let bumpType = argv.type;

if (message) {
const result = spawnSync(
'sh',
['-c', `echo ${message} | ${commitLintBinPath} --config ${commitLineConfigPath}`],
{
stdio: 'inherit'
}
);

if (result.status !== 0) {
process.exit(1);
}

if (!bumpType) {
console.log(chalk.green(`[Notice] no bumpType is supplied, we'll use default bumpType: ${chalk.red.bold('patch')}`));
bumpType = 'patch';
}

spawnSync('sh', ['-c', `rush change --bulk --bump-type '${bumpType}' --message '${message}'`], {
stdio: 'inherit',
shell: false,
});
}
}

run();
5 changes: 3 additions & 2 deletions common/autoinstallers/lint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
"lint-staged": "13.0.3",
"minimist": "1.2.6",
"prettier": "2.7.1",
"ts-node": "10.9.0"
"ts-node": "10.9.0",
"chalk": "4.1.2"
},
"devDependencies": {
"@types/minimist": "1.2.2",
"@types/node": "*",
"typescript": "5.0.2"
}
}
}
Loading

0 comments on commit f2c225e

Please sign in to comment.