diff --git a/dist/index.js b/dist/index.js index 87aa2ac..946e8e2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,7 +1,7 @@ parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c{if(await e(o,s),"package.json"===o)try{await e("package-lock.json",s)}catch(r){console.log(r)}};exports.bumpVersion=o; +"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.bumpVersion=void 0;const e=require("json-bumper"),r=async(r,s)=>await e(r,s);exports.bumpVersion=r; },{}],"lyg8":[function(require,module,exports) { module.exports={version:"1.0.1",testingen:"0.2.1"}; },{}],"QCba":[function(require,module,exports) { -"use strict";var e=require("actions-toolkit"),o=require("./helpers/bumper");const{version:s}=require("../version.json");console.log(`Version ${s}`),e.Toolkit.run(async e=>{const s=process.env.VERSION_FILE_NAME||"package.json",i=process.env.VERSION_ENTRY||"version",r=process.env.GITHUB_USER||"GitHub Version Bumper",n=process.env.GITHUB_EMAIL||"github-version-bumper@users.noreply.github.com";try{var t;await e.runInWorkspace("git",["config","user.name",`"${r}"`]),await e.runInWorkspace("git",["config","user.email",`"${n}"`]);let c=!1;const l=null===(t=/refs\/[a-zA-Z]+\/(.*)/.exec(process.env.GITHUB_REF))||void 0===t?void 0:t[1];await e.runInWorkspace("git",["checkout",l]);const p=JSON.stringify(await e.runInWorkspace("git",["log","-1"])).toLowerCase()||"";if(console.log("lastcommitmessage",p),p.toLowerCase().includes("ci-ignore"))console.log("ci-ignore"),c=!0;else if(p.toLowerCase().includes("ci-version=")){const e=p.toLowerCase().split('ci-version=\\"')[1].split('\\"')[0];console.log("replace:",e),await(0,o.bumpVersion)(s,{replace:e,entry:i})}else if(p.toLowerCase().includes("ci-pre=")){console.log("pre");const e=p.toLowerCase().split('ci-pre=\\"')[1].split('\\"')[0];console.log("pre:",e),await(0,o.bumpVersion)(s,{pre:e,entry:i})}else p.toLowerCase().includes("ci-major")?(console.log("major"),await(0,o.bumpVersion)(s,{major:!0,entry:i})):p.toLowerCase().includes("ci-minor")?(console.log("minor"),await(0,o.bumpVersion)(s,{minor:!0,entry:i})):(console.log("patch"),await(0,o.bumpVersion)(s));if(!c){const o=JSON.parse(e.getFile(s)).version;await e.runInWorkspace("git",["commit","-a","-m",`ci: version bumped to v ${o}`]);const i=`https://${process.env.GITHUB_ACTOR}:${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git`;await e.runInWorkspace("git",["tag",o]),await e.runInWorkspace("git",["push",i,"--follow-tags"]),await e.runInWorkspace("git",["push",i,"--tags"])}}catch(a){e.log.fatal(a),e.exit.failure("Failed to bump version")}e.exit.success("Version bumped!")}); +"use strict";var e=require("actions-toolkit"),o=require("./helpers/bumper");const{version:s}=require("../version.json"),i=require("json-bumper");console.log(`Version ${s}`),e.Toolkit.run(async e=>{let s=process.env.VERSION_FILE_NAME||"package.json",i=process.env.VERSION_ENTRY||"version";const r=process.env.GITHUB_USER||"GitHub Version Bumper",n=process.env.GITHUB_EMAIL||"github-version-bumper@users.noreply.github.com";console.log("fileName",s);try{var a;console.log("process-started---"),await e.runInWorkspace("git",["config","user.name",`"${r}"`]),await e.runInWorkspace("git",["config","user.email",`"${n}"`]);let c=!1;const l=null===(a=/refs\/[a-zA-Z]+\/(.*)/.exec(process.env.GITHUB_REF))||void 0===a?void 0:a[1];await e.runInWorkspace("git",["checkout",l]);const p=JSON.stringify(await e.runInWorkspace("git",["log","-1"])).toLowerCase()||"";if(console.log("lastcommitmessage",p),console.log("current branch",l),"master"===l)if(p.toLowerCase().includes("ci-ignore"))console.log("ci-ignore"),c=!0;else if(p.toLowerCase().includes("ci-version=")){const e=p.toLowerCase().split('ci-version=\\"')[1].split('\\"')[0];console.log("replace:",e),await(0,o.bumpVersion)(s,{replace:e,entry:i})}else if(p.toLowerCase().includes("ci-pre=")){console.log("pre");const e=p.toLowerCase().split('ci-pre=\\"')[1].split('\\"')[0];console.log("pre:",e),await(0,o.bumpVersion)(s,{pre:e,entry:i})}else p.toLowerCase().includes("ci-major")?(console.log("major"),await(0,o.bumpVersion)(s,{major:!0,entry:i})):p.toLowerCase().includes("ci-minor")?(console.log("minor"),await(0,o.bumpVersion)(s,{minor:!0,entry:i})):(console.log("patch"),await(0,o.bumpVersion)(s));else if("staging"===l||"qc"===l||"production"===l){const e=await(0,o.bumpVersion)(s);if(e.original.includes("rc")){let i=e.original.split("-rc.")[1];i++;const r=e.original.slice(0,-1)+i;await(0,o.bumpVersion)(s,{replace:r})}else{const i=e.original,r="-rc.0",n=i.concat(r);await(0,o.bumpVersion)(s,{replace:n})}}else if("alpha"===l){const e=await(0,o.bumpVersion)(s);if(e.original.includes("pr")){let i=e.original.split("-pr.")[1];i++;const r=e.original.slice(0,-1)+i;await(0,o.bumpVersion)(s,{replace:r})}else{const i=e.original,r="-pr.0",n=i.concat(r);await(0,o.bumpVersion)(s,{replace:n})}}if(!c){const o=JSON.parse(e.getFile(s)).version;console.log("-newVersion",o),await e.runInWorkspace("git",["commit","-a","-m",`ci: version bumped to v ${o}`]);const i=`https://${process.env.GITHUB_ACTOR}:${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git`;await e.runInWorkspace("git",["pull","--tags"]),await e.runInWorkspace("git",["tag",o]),await e.runInWorkspace("git",["push",i,"--follow-tags"]),await e.runInWorkspace("git",["push",i,"--tags"])}}catch(t){e.log.fatal(t),e.exit.failure("Failed to bump version")}e.exit.success("Version bumped!")}); },{"./helpers/bumper":"rP21","../version.json":"lyg8"}]},{},["QCba"], null) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d186de1..e6c0526 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "github-version-bumper", - "version": "0.5.2", + "version": "0.5.29", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 48bb5a9..2933eb3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "github-version-bumper", - "version": "1.0.1", + "version": "1.0.28", "repository": { "type": "git", "url": "git+https://github.com/kaangokdemir/github-version-bumper.git" diff --git a/src/helpers/bumper.ts b/src/helpers/bumper.ts index 86dc2eb..e354b4d 100644 --- a/src/helpers/bumper.ts +++ b/src/helpers/bumper.ts @@ -1,10 +1,10 @@ const bump = require('json-bumper') export const bumpVersion = async (fileName: string, options?: object) => { - await bump(fileName, options) + return await bump(fileName, options) if (fileName === 'package.json') { try { - await bump('package-lock.json', options) + return await bump('package-lock.json', options) } catch (error) { console.log(error) } diff --git a/src/index.ts b/src/index.ts index 4773e28..b59032a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,20 +1,21 @@ import { Toolkit } from 'actions-toolkit' import { bumpVersion } from './helpers/bumper' const { version } = require('../version.json') - +const bump = require('json-bumper') console.log(`Version ${version}`) Toolkit.run(async (tools) => { - const fileName = process.env.VERSION_FILE_NAME || 'package.json' - const entry = process.env.VERSION_ENTRY || 'version' + let fileName = process.env.VERSION_FILE_NAME || 'package.json' + let entry = process.env.VERSION_ENTRY || 'version' const githubUser = process.env.GITHUB_USER || 'GitHub Version Bumper' const githubEmail = - process.env.GITHUB_EMAIL || 'github-version-bumper@users.noreply.github.com' + process.env.GITHUB_EMAIL || 'github-version-bumper@users.noreply.github.com' const commitMessage = 'version bumped to v' - +console.log('fileName', fileName) try { // SET USER + console.log('process-started---') await tools.runInWorkspace('git', [ 'config', 'user.name', @@ -28,56 +29,88 @@ Toolkit.run(async (tools) => { let ignoreBump = false const currentBranch = /refs\/[a-zA-Z]+\/(.*)/.exec( - process.env.GITHUB_REF as string, + process.env.GITHUB_REF as string, )?.[1] as string await tools.runInWorkspace('git', ['checkout', currentBranch]) // Getting last commit information const lastCommit = - JSON.stringify(await tools.runInWorkspace('git', ['log', '-1'])).toLowerCase() || '' - - console.log('lastcommitmessage', lastCommit) + JSON.stringify(await tools.runInWorkspace('git', ['log', '-1'])).toLowerCase() || '' + console.log('lastcommitmessage', lastCommit) + console.log('current branch', currentBranch) // Bumping Starts - - if (lastCommit.toLowerCase().includes('ci-ignore')) { - console.log('ci-ignore') - ignoreBump = true - } else if (lastCommit.toLowerCase().includes('ci-version=')) { - const splitted = lastCommit.toLowerCase().split('ci-version=\\"') - const replace = splitted[1].split('\\"')[0] - console.log('replace:', replace) - await bumpVersion(fileName, { replace, entry }) - } else if (lastCommit.toLowerCase().includes('ci-pre=')) { - console.log('pre') - const splitted = lastCommit.toLowerCase().split('ci-pre=\\"') - const pre = splitted[1].split('\\"')[0] - console.log('pre:', pre) - await bumpVersion(fileName, { pre, entry }) - } else if (lastCommit.toLowerCase().includes('ci-major')) { - console.log('major') - await bumpVersion(fileName, { major: true, entry }) - } else if (lastCommit.toLowerCase().includes('ci-minor')) { - console.log('minor') - await bumpVersion(fileName, { minor: true, entry }) - } else { - console.log('patch') - await bumpVersion(fileName) + if(currentBranch === 'master'){ + if (lastCommit.toLowerCase().includes('ci-ignore')) { + console.log('ci-ignore') + ignoreBump = true + } else if (lastCommit.toLowerCase().includes('ci-version=')) { + const splitted = lastCommit.toLowerCase().split('ci-version=\\"') + const replace = splitted[1].split('\\"')[0] + console.log('replace:', replace) + await bumpVersion(fileName, { replace, entry }) + } else if (lastCommit.toLowerCase().includes('ci-pre=')) { + console.log('pre') + const splitted = lastCommit.toLowerCase().split('ci-pre=\\"') + const pre = splitted[1].split('\\"')[0] + console.log('pre:', pre) + await bumpVersion(fileName, { pre, entry }) + } else if (lastCommit.toLowerCase().includes('ci-major')) { + console.log('major') + await bumpVersion(fileName, { major: true, entry }) + } else if (lastCommit.toLowerCase().includes('ci-minor')) { + console.log('minor') + await bumpVersion(fileName, { minor: true, entry }) + } else { + console.log('patch') + await bumpVersion(fileName) + } + } + else if(currentBranch === 'staging' || currentBranch === 'qc' || currentBranch === 'production' ){ + const bumpedBranch = await bumpVersion(fileName) + ; + if(bumpedBranch.original.includes("rc")){ + let branchVersion = bumpedBranch.original.split('-rc.')[1] + branchVersion++; + const str2 = bumpedBranch.original.slice(0, -1) + branchVersion + await bumpVersion(fileName, { replace : str2 }) + }else{ + const vO = bumpedBranch.original + const pre = `-rc.0` + const replace = vO.concat(pre) + await bumpVersion(fileName, { replace }) + } + } + else if(currentBranch === 'alpha'){ + const bumpedBranch = await bumpVersion(fileName) + ; + if(bumpedBranch.original.includes("pr")){ + let branchVersion = bumpedBranch.original.split('-pr.')[1] + branchVersion++; + const str2 = bumpedBranch.original.slice(0, -1) + branchVersion + await bumpVersion(fileName, { replace : str2 }) + }else{ + const vO = bumpedBranch.original + const pre = `-pr.0` + const replace = vO.concat(pre) + await bumpVersion(fileName, { replace }) + } } if (!ignoreBump) { const newVersion = JSON.parse(tools.getFile(fileName)).version - + console.log('-newVersion', newVersion) await tools.runInWorkspace('git', [ 'commit', '-a', '-m', - `ci: ${commitMessage} ${newVersion}`, + `ci: ${commitMessage} ${newVersion}`, ]) // PUSH THE CHANGES const remoteRepo = `https://${process.env.GITHUB_ACTOR}:${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git` + await tools.runInWorkspace('git', ['pull', '--tags']) await tools.runInWorkspace('git', ['tag', newVersion]) await tools.runInWorkspace('git', ['push', remoteRepo, '--follow-tags']) await tools.runInWorkspace('git', ['push', remoteRepo, '--tags'])