Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: alextremp/versiona
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.2.0
Choose a base ref
...
head repository: alextremp/versiona
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 18 commits
  • 2 files changed
  • 2 contributors

Commits on Jan 9, 2020

  1. [skip travis] Update version to: 4.2.0

    Travis CI User committed Jan 9, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8235ec9 View commit details
  2. Copy the full SHA
    3bc13f4 View commit details
  3. Copy the full SHA
    dd83be9 View commit details
  4. [skip travis] Update version to: 4.2.1

    Travis CI User committed Jan 9, 2020
    Copy the full SHA
    9766475 View commit details

Commits on Jan 23, 2020

  1. Copy the full SHA
    e017730 View commit details
  2. [skip travis] Update version to: 4.2.2

    Travis CI User committed Jan 23, 2020
    Copy the full SHA
    900e101 View commit details
  3. Copy the full SHA
    9844c47 View commit details
  4. [skip travis] Update version to: 4.2.3

    Travis CI User committed Jan 23, 2020
    Copy the full SHA
    06917a7 View commit details

Commits on Jun 17, 2020

  1. allow master command (#5)

    alextremp authored Jun 17, 2020
    Copy the full SHA
    26d575b View commit details
  2. Copy the full SHA
    c47d8b9 View commit details
  3. [skip travis] Update version to: 4.3.0

    Travis CI User committed Jun 17, 2020
    Copy the full SHA
    451826e View commit details
  4. Copy the full SHA
    b282cba View commit details
  5. [skip travis] Update version to: 4.4.0

    Travis CI User committed Jun 17, 2020
    Copy the full SHA
    39b2e3c View commit details

Commits on Jun 18, 2020

  1. skip versiona with commit message

    * this is for private travis where automatic skip is not enabled
    alextremp committed Jun 18, 2020
    Copy the full SHA
    4516ab7 View commit details
  2. Copy the full SHA
    afd3d8c View commit details
  3. [skip travis] Update version to: 4.5.0

    Travis CI User committed Jun 18, 2020
    Copy the full SHA
    2719598 View commit details

Commits on Oct 20, 2020

  1. Copy the full SHA
    f2bcc43 View commit details
  2. [skip travis] Update version to: 4.6.0

    Travis CI User committed Oct 20, 2020
    Copy the full SHA
    86e4a18 View commit details
Showing with 83 additions and 50 deletions.
  1. +3 −3 package.json
  2. +80 −47 src/main/versiona.js
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "versiona",
"version": "4.1.0",
"version": "4.6.0",
"description": "NPM auto publisher tool for Travis CI + Git tags commiting new package version",
"main": "dist",
"author": "Alex Castells",
@@ -48,7 +48,7 @@
"extends": "./node_modules/@s-ui/lint/stylelint.config.js"
},
"dependencies": {
"logda": "^1.0.0",
"shelljs": "^0.8.3"
"logda": "1",
"shelljs": "0.8.3"
}
}
127 changes: 80 additions & 47 deletions src/main/versiona.js
Original file line number Diff line number Diff line change
@@ -7,24 +7,29 @@ const versiona = ({
repoOrg,
repoName,
host = 'github.com',
publish = 'npm publish',
publish = NPM_PUBLISH,
masterCommand = MASTER_COMMAND,
test = false
} = {}) => {
const packageJSONPath = path.resolve(process.cwd(), PACKAGE_JSON)
const packageJSON = require(packageJSONPath)

if (process.env.TRAVIS_COMMIT_MESSAGE.startsWith(SKIP_TRAVIS_PREFIX)) {
console.log(process.env.TRAVIS_COMMIT_MESSAGE + ' >> skipping versiona')
return false
}

if (!repoOrg || !repoName) {
log.error(() => 'repoOrg and repoName are required')
quit()
}

const isMaster =
process.env.TRAVIS_BRANCH === 'master' &&
process.env.TRAVIS_PULL_REQUEST === 'false'

const travisTag = process.env.TRAVIS_TAG
if (!travisTag) {
log.info(
() => 'TRAVIS_TAG is not present in process.env, stopping versiona'
)
return false
}
if (!REGEX.test(travisTag)) {
if (travisTag && !REGEX.test(travisTag)) {
log.info(() => [
'TRAVIS_TAG is not a semver format tag, stopping versiona',
{
@@ -34,53 +39,78 @@ const versiona = ({
])
return false
}
const ghToken = process.env.GH_TOKEN
if (!ghToken) {
log.error(() => 'GH_TOKEN is not in process env')
quit()

let environment = travisTag ? 'pro' : 'pre'
const addMasterCommand = () => {
const command =
typeof masterCommand === 'function'
? masterCommand(environment)
: `VERSIONA_ENV=${environment} ${masterCommand}`
masterCommand && addShell(command)
}

const releaseVersion = travisTag.replace('v', '')
if (travisTag) {
const ghToken = process.env.GH_TOKEN || process.env.GITHUB_TOKEN
if (!ghToken) {
log.error(() => 'GH_TOKEN neiter GITHUB_TOKEN in process env')
quit()
}

const repoURL = `https://${ghToken}@${host}/${repoOrg}/${repoName}.git`
const message = `[skip travis] Update version to: ${releaseVersion}`
const releaseVersion = travisTag.replace('v', '')

const isBeta = releaseVersion.indexOf('-beta.') > -1
const repoURL = `https://${ghToken}@${host}/${repoOrg}/${repoName}.git`
const message = `${SKIP_TRAVIS_PREFIX} Update version to: ${releaseVersion}`

const toBranch = isBeta
? `develop/v${releaseVersion.replace(/\.[0-9]+\.[0-9]+-beta\.[0-9]+/, '')}`
: 'master'
const isBeta = releaseVersion.indexOf('-beta.') > -1

const oldVersion = packageJSON.version
isBeta && (environment = 'dev')

packageJSON.version = releaseVersion
const updatedJSON = JSON.stringify(packageJSON, null, 2)
const toBranch = isBeta
? `develop/v${releaseVersion.replace(
/\.[0-9]+\.[0-9]+-beta\.[0-9]+/,
''
)}`
: 'master'

log.info(() => [
'Updating...',
{
repoOrg,
repoName,
host,
travisTag,
isBeta,
toBranch,
oldversion: oldVersion,
newVersion: releaseVersion,
publish
}
])

addShell(`git remote rm origin`)
addShell(`git remote add origin ${repoURL}`)
addShell(`git checkout -b ${toBranch}`)
addFunction(`Update package.json to ${releaseVersion}`, () =>
fs.writeFileSync(packageJSONPath, updatedJSON)
)
addShell(`git add package.json`)
addShell(`git commit -m "${message}"`)
publish && addShell(`npm publish${isBeta ? ' --tag beta' : ''}`)
addShell(`git push --repo=${repoURL} origin ${toBranch} --quiet`)
const oldVersion = packageJSON.version

packageJSON.version = releaseVersion
const updatedJSON = `${JSON.stringify(packageJSON, null, 2)}`

log.info(() => [
'Updating...',
{
repoOrg,
repoName,
host,
travisTag,
isBeta,
toBranch,
oldversion: oldVersion,
newVersion: releaseVersion,
publish
}
])

addShell(`git remote rm origin`)
addShell(`git remote add origin ${repoURL}`)
addShell(`git checkout -b ${toBranch}`)
addFunction(`Update package.json to ${releaseVersion}`, () =>
fs.writeFileSync(packageJSONPath, updatedJSON)
)
addShell(`git add package.json`)
addShell(`git commit -m "${message}"`)
publish &&
addShell(
NPM_PUBLISH === publish
? `${publish}${isBeta ? ' --tag beta' : ''}`
: publish
)
addMasterCommand()
addShell(`git push --repo=${repoURL} origin ${toBranch} --quiet`)
} else if (isMaster) {
addMasterCommand()
}

if (test) {
log.info(() => 'Test finished')
@@ -90,8 +120,11 @@ const versiona = ({
return true
}

const NPM_PUBLISH = 'npm publish'
const MASTER_COMMAND = 'echo Running on master'
const PACKAGE_JSON = 'package.json'
const REGEX_PATTERN = '^v[0-9]+.[0-9]+.[0-9]+(-beta.[0-9]+)?$'
const REGEX = new RegExp(REGEX_PATTERN)
const SKIP_TRAVIS_PREFIX = '[skip travis]'

export {versiona}