ci: auto publish nuxt-edge

This commit is contained in:
Pooya Parsa 2018-01-08 20:22:56 +03:30
parent b83d74588f
commit 12830e306f
2 changed files with 19 additions and 6 deletions

View File

@ -28,12 +28,12 @@ jobs:
name: Tests name: Tests
command: yarn test && yarn coverage command: yarn test && yarn coverage
# Release next # Release edge
- run: - run:
name: Publish nuxt-next name: Publish nuxt-edge
command: | command: |
if [ "${CIRCLE_BRANCH}" == "dev" ]; then if [ "${CIRCLE_BRANCH}" == "dev" ]; then
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
echo "//registry.yarnpkg.com/:_authToken=$NPM_TOKEN" >> ~/.npmrc echo "//registry.yarnpkg.com/:_authToken=$NPM_TOKEN" >> ~/.npmrc
./scripts/release-next && npm publish --tag next ./scripts/release-edge
fi fi

View File

@ -17,16 +17,29 @@ const originalPackage = readFileSync(packagePath, 'utf-8')
const p = JSON.parse(originalPackage) const p = JSON.parse(originalPackage)
// Change package name // Change package name
// p.name = 'nuxt-next' p.name = 'nuxt-edge'
// Get latest git commit id // Get latest git commit id
const gitCommit = String(spawnSync('git', 'rev-parse --short HEAD'.split(' ')).stdout).trim() const gitCommit = String(spawnSync('git', 'rev-parse --short HEAD'.split(' ')).stdout).trim()
// Version with latest git commit id // Version with latest git commit id
p.version = p.version.split('-')[0] + '-gh-' + gitCommit p.version = p.version.split('-')[0] + gitCommit
// Write package.json // Write package.json
writeFileSync(packagePath, JSON.stringify(p, null, 2) + '\r\n') writeFileSync(packagePath, JSON.stringify(p, null, 2) + '\r\n')
// Parse git branch to decide npm tag
let tag = String(spawnSync('git', 'rev-parse --abbrev-ref HEAD'.split(' ')).stdout).trim()
// dev ~> latest
if (tag === 'dev') {
tag = 'latest'
}
// Log // Log
console.log(p.name + '@' + p.version) // eslint-disable-line no-console // eslint-disable-next-line no-console
console.log(`publishing ${p.name}@${p.version} with tag ${tag}`)
// Do publish
// eslint-disable-next-line no-console
console.log(String(spawnSync('npm', `publish --tag ${tag}`.split(' ')).stdout).trim())