Skip to content

Commit

Permalink
fix: release scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
luthfimasruri committed Mar 29, 2021
1 parent 62dc820 commit ae00c70
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 14 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/release-vue-quill.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ jobs:
run: npm ci
- name: Release package
working-directory: packages/vue-quill
# run: npx ts-node ../../scripts/release.ts vue-quill
run: npx semantic-release
run: npx ts-node ../../scripts/release.ts vue-quill
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN}}
2 changes: 1 addition & 1 deletion packages/vue-quill/src/assets/snow.styl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ backgroundColor = #fff
inactiveColor = #4B5563
shadowColor = #D1D5DB
textColor = #4B5563
// Additional colors
// Additional color
backgroundHoverColor = #F3F4F6
backgroundActiveColor = #DBEAFE

Expand Down
118 changes: 107 additions & 11 deletions scripts/release.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,114 @@
(() => {
const chalk = require('chalk')
const execa = require('execa')
const path = require('path')
const semanticRelease = require('semantic-release')
// const { WritableStreamBuffer } = require('stream-buffers');
// const stdoutBuffer = WritableStreamBuffer();
// const stderrBuffer = WritableStreamBuffer();

const args = require('minimist')(process.argv.slice(2))
const targets = args._

if (process.env.CI && targets[0]) {
console.log("execute zip >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
execa.sync('zip', ['-r', `${targets[0]}-dist.zip`, '.', '-i', 'dist'])
console.log("execute semantic-release >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
const a = execa.sync('npx', ['semantic-release'])
console.log("A", a)
console.log("finished execution >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
} else {
console.log(chalk.redBright("You can't run semantic-release locally"))
const target = args._[0]
const pkg = require(path.resolve(__dirname, `../packages/${target}`, 'package.json'))
const releaserc = {
branches: [
'master',
'next',
'next-major',
{ name: 'beta', prerelease: true },
{ name: 'alpha', prerelease: true }
],
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
'@semantic-release/npm',
[
'@semantic-release/github',
{
assets: [
{
path: `${target}-dist.zip`,
name: `${target}-dist-\$\{nextRelease.gitTag\}.zip`,
label: 'Distribution code (zip)'
}
]
}
]
]
}

run(target)

async function run(target: string) {
const nextVersion = await getNextVersion()
await prepare(target, nextVersion)
await release()
}

async function prepare(target: string, nextVersion: string) {
const buildScript = path.resolve(__dirname, 'build.js')
execa.sync('npx', ['ts-node', buildScript, '--nextVersion', nextVersion])
execa.sync('zip', ['-r', `${target}-dist.zip`, '.', '-i', 'dist'])
execa.sync('npx', ['semantic-release'])
}

async function release() {
try {
const result = await semanticRelease({
// Core options
branches: releaserc.branches,
repositoryUrl: pkg.repository.url,
plugins: releaserc.plugins
}, {
// Run semantic-release from `/path/to/git/repo/root` without having to change local process `cwd` with `process.chdir()`
cwd: '',
// Pass the variable `MY_ENV_VAR` to semantic-release without having to modify the local `process.env`
env: { ...process.env },
// Store stdout and stderr to use later instead of writing to `process.stdout` and `process.stderr`
// stdout: stdoutBuffer,
// stderr: stderrBuffer
});

if (result) {
const { lastRelease, commits, nextRelease, releases } = result;

console.log(`Published ${nextRelease.type} release version ${nextRelease.version} containing ${commits.length} commits.`);

if (lastRelease.version) {
console.log(`The last release was "${lastRelease.version}".`);
}

for (const release of releases) {
console.log(`The release was published with plugin "${release.pluginName}".`);
}
} else {
console.log('No release published.');
}

// Get stdout and stderr content
// const logs = stdoutBuffer.getContentsAsString('utf8');
// const errors = stderrBuffer.getContentsAsString('utf8');
// console.log(logs, errors);

} catch (err) {
console.error('The automated release failed with %O', err)
}
}

async function getNextVersion(): Promise<string> {
try {
const { nextRelease } = await semanticRelease({
branches: releaserc.branches,
repositoryUrl: pkg.repository.url,
dryRun: true,
ci: false,
plugins: ['@semantic-release/commit-analyzer']
})
if (nextRelease) return nextRelease.version
else console.log('No release will bepublished')
} catch (err) {
console.error('Failed to retrieve next version with %O', err)
}
return pkg.version
}
})()

0 comments on commit ae00c70

Please sign in to comment.