-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
238 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,62 @@ | ||
name: Publish Package | ||
name: Release | ||
|
||
on: | ||
release: | ||
types: [published] | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
|
||
tag: | ||
name: Create release tag | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Create release tag | ||
id: release_tag | ||
uses: yyx990803/release-tag@master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
body: | | ||
[CHANGELOG.md](https://github.com/hujiulong/vue-3d-model/blob/master/CHANGELOG.md) | ||
publish-npm: | ||
name: Publish to NPM | ||
runs-on: ubuntu-latest | ||
needs: tag | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14' | ||
registry-url: 'https://registry.npmjs.org' | ||
- name: Build & publish | ||
run: | | ||
npm install | ||
npm run build | ||
npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
publish-gpr: | ||
name: Publish to GPR | ||
runs-on: ubuntu-latest | ||
needs: tag | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/setup-node@v1 | ||
- uses: actions/checkout@v2 | ||
- name: Setup node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 12 | ||
registry-url: https://registry.npmjs.org/ | ||
- run: npm install | ||
- run: npm run test | ||
- run: npm run build | ||
- run: npm publish | ||
node-version: '14' | ||
registry-url: 'https://npm.pkg.github.com/' | ||
scope: '@hujiulong' | ||
- name: Build & publish | ||
run: | | ||
npm install | ||
npm run build | ||
npm run gpr-setup | ||
npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} | ||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const pkg = require('../package.json'); | ||
|
||
pkg.name = '@hujiulong/vue-3d-model'; | ||
|
||
// Update package.json with the udpated name | ||
fs.writeFileSync( | ||
path.join(__dirname, '../package.json'), | ||
JSON.stringify(pkg, null, 2), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* eslint-disable */ | ||
|
||
const args = require('minimist')(process.argv.slice(2)); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const chalk = require('chalk'); | ||
const semver = require('semver'); | ||
const { prompt } = require('enquirer'); | ||
const execa = require('execa'); | ||
const pkg = require('../package.json'); | ||
|
||
const currentVersion = pkg.version; | ||
const preId = | ||
args.preid || | ||
(semver.prerelease(currentVersion) && semver.prerelease(currentVersion)[0]); | ||
const isDryRun = args.dry; | ||
const skipTests = args.skipTests; | ||
const skipBuild = args.skipBuild; | ||
|
||
const pkgPath = path.resolve(__dirname, '../package.json'); | ||
const versionIncrements = [ | ||
'patch', | ||
'minor', | ||
'major', | ||
...(preId ? ['prepatch', 'preminor', 'premajor', 'prerelease'] : []), | ||
]; | ||
|
||
const inc = (i) => semver.inc(currentVersion, i, preId); | ||
const run = (bin, args, opts = {}) => | ||
execa(bin, args, { stdio: 'inherit', ...opts }); | ||
const dryRun = (bin, args, opts = {}) => | ||
console.log(chalk.blue(`[dryrun] ${bin} ${args.join(' ')}`), opts); | ||
const runIfNotDry = isDryRun ? dryRun : run; | ||
const step = (msg) => console.log(chalk.cyan(msg)); | ||
|
||
async function main() { | ||
let targetVersion = args._[0]; | ||
|
||
if (!targetVersion) { | ||
// no explicit version, offer suggestions | ||
const { release } = await prompt({ | ||
type: 'select', | ||
name: 'release', | ||
message: 'Select release type', | ||
choices: versionIncrements | ||
.map((i) => `${i} (${inc(i)})`) | ||
.concat(['custom']), | ||
}); | ||
|
||
if (release === 'custom') { | ||
targetVersion = ( | ||
await prompt({ | ||
type: 'input', | ||
name: 'version', | ||
message: 'Input custom version', | ||
initial: currentVersion, | ||
}) | ||
).version; | ||
} else { | ||
targetVersion = release.match(/\((.*)\)/)[1]; | ||
} | ||
} | ||
|
||
if (!semver.valid(targetVersion)) { | ||
throw new Error(`invalid target version: ${targetVersion}`); | ||
} | ||
|
||
const { yes } = await prompt({ | ||
type: 'confirm', | ||
name: 'yes', | ||
message: `Releasing v${targetVersion}. Confirm?`, | ||
}); | ||
|
||
if (!yes) { | ||
return; | ||
} | ||
|
||
// update all package versions and inter-dependencies | ||
step('\nUpdating cross dependencies...'); | ||
if (!isDryRun) { | ||
pkg.version = targetVersion; | ||
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n'); | ||
} else { | ||
console.log(`(skipped)`); | ||
} | ||
|
||
// run tests before release | ||
step('\nRunning tests...'); | ||
if (!skipTests && !isDryRun) { | ||
await run('npm', ['test']); | ||
} else { | ||
console.log(`(skipped)`); | ||
} | ||
|
||
// build package | ||
step('\nBuilding package...'); | ||
if (!skipBuild && !isDryRun) { | ||
await run('npm', ['build', '--release']); | ||
} else { | ||
console.log(`(skipped)`); | ||
} | ||
|
||
// generate changelog | ||
await run(`npm`, ['run', 'changelog']); | ||
|
||
const { stdout } = await run('git', ['diff'], { stdio: 'pipe' }); | ||
if (stdout) { | ||
step('\nCommitting changes...'); | ||
await runIfNotDry('git', ['add', '-A']); | ||
await runIfNotDry('git', ['commit', '-m', `release: v${targetVersion}`]); | ||
} else { | ||
console.log('No changes to commit.'); | ||
} | ||
|
||
// push to GitHub | ||
step('\nPushing to GitHub...'); | ||
await runIfNotDry('git', ['tag', `v${targetVersion}`]); | ||
await runIfNotDry('git', ['push', 'origin', `refs/tags/v${targetVersion}`]); | ||
await runIfNotDry('git', ['push']); | ||
|
||
if (isDryRun) { | ||
console.log(`\nDry run finished - run git diff to see package changes.`); | ||
} | ||
|
||
console.log(); | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Invoked on the commit-msg git hook by yorkie. | ||
|
||
/* eslint-disable prefer-template, quotes, operator-linebreak */ | ||
|
||
const chalk = require('chalk'); | ||
|
||
const msgPath = process.env.GIT_PARAMS; | ||
const msg = require('fs').readFileSync(msgPath, 'utf-8').trim(); | ||
|
||
const commitRE = /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/; | ||
|
||
if (!commitRE.test(msg)) { | ||
console.log(); | ||
console.error( | ||
` ${chalk.bgRed.white(' ERROR ')} ${chalk.red( | ||
`invalid commit message format.`, | ||
)}\n\n` + | ||
chalk.red( | ||
` Proper commit message format is required for automated changelog generation. Examples:\n\n`, | ||
) + | ||
` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` + | ||
` ${chalk.green( | ||
`fix(v-model): handle events on blur (close #28)`, | ||
)}\n\n` + | ||
chalk.red(` See .github/commit-convention.md for more details.\n`), | ||
); | ||
process.exit(1); | ||
} |