Skip to content

Commit

Permalink
feat: Test release
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Oct 18, 2019
1 parent 5945aae commit d71558c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ inputs:
description: 'Commit message to use'
default: 'chore(release): {version} :tada:'
required: false

preset:
description: 'The preset from Conventional Changelog to use'
default: 'preset'
required: false
58 changes: 58 additions & 0 deletions src/helpers/packageJson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const path = require('path')
const fs = require('fs')

module.exports = {

/**
* Get's the project package.json
* @return {any}
*/
get: () => {
const packageJsonLoc = path.resolve('./', 'package.json')

return JSON.parse(fs.readFileSync(packageJsonLoc))
},

/**
* Bumps the version in the package.json
*
* @param packageJson
* @param releaseType
* @return {*}
*/
bump: (packageJson, releaseType) => {
let [major, minor, patch] = packageJson.version.split('.')

switch (releaseType) {
case 'major':
major = major + 1
minor = 0
patch = 0
break

case 'minor':
minor = minor + 1
patch = 0
break

default:
patch = patch + 1
}

// Update the package.json with the new version
packageJson.version = `${major}.${minor}.${patch}`

return packageJson
},

/**
* Update package.json
*
* @param packageJson
* @return {*}
*/
update: (packageJson) => (
fs.writeFileSync(packageJsonLoc, JSON.stringify(packageJson, null, 2))
),

}
21 changes: 15 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@ const conventionalChangelog = require('conventional-changelog')
const conventionalRecommendedBump = require('conventional-recommended-bump')

const git = require('./helpers/git')
const packageJson = require('./helpers/packageJson')

async function run() {
try {
const githubToken = core.getInput('github-token', { required: true })
const commitMessage = core.getInput('git-message')
const preset = core.getInput('preset')

// Make the Github token secret
core.setSecret(githubToken)


// conventionalChangelog({
// preset: 'angular',
// }).pipe(process.stdout)

conventionalRecommendedBump({
preset: `angular`,
}, (error, recommendation) => {
console.log(recommendation.releaseType) // 'major'

core.info(`[recommendation.releaseType]: ${recommendation.releaseType}`)
conventionalRecommendedBump({ preset }, (error, recommendation) => {
if (error) {
core.setFailed(error.message)

} else {
const packageJson = packageJson.bump(
packageJson.get(),
recommendation.releaseType,
)

core.info(`New version: ${packageJson.version}`)
}
})

// Get the current version
Expand Down

0 comments on commit d71558c

Please sign in to comment.