Skip to content

Commit

Permalink
feat(ci/cd): Command to publish beta version (#4478)
Browse files Browse the repository at this point in the history
* feat(ci/cd): publish beta command

* feat(ci/cd): publish beta command
  • Loading branch information
kobenguyent authored Sep 3, 2024
1 parent 05a362d commit 0e3d432
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"types-fix": "node typings/fixDefFiles.js",
"dtslint": "npm run types-fix && tsd",
"prepare": "husky install",
"prepare-release": "./runok.js versioning && ./runok.js get:commit-log"
"prepare-release": "./runok.js versioning && ./runok.js get:commit-log",
"publish-beta": "./runok.js publish:next-beta-version"
},
"dependencies": {
"@codeceptjs/configure": "1.0.1",
Expand Down Expand Up @@ -155,6 +156,7 @@
"qrcode-terminal": "0.12.0",
"rosie": "2.1.1",
"runok": "0.9.3",
"semver": "7.6.3",
"sinon": "18.0.0",
"sinon-chai": "3.7.0",
"testcafe": "3.5.0",
Expand Down
43 changes: 43 additions & 0 deletions runok.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const {
runok,
} = require('runok')
const contributors = require('contributor-faces')
const { execSync } = require('node:child_process')
const semver = require('semver')

const helperMarkDownFile = function (name) {
return `docs/helpers/${name}.md`
Expand Down Expand Up @@ -478,6 +480,47 @@ ${changelog}`
)
fs.writeFileSync('./README.md', readmeContent)
},

getCurrentBetaVersion() {
try {
const output = execSync('npm view codeceptjs versions --json').toString()
const versions = JSON.parse(output)
const betaVersions = versions.filter((version) => version.includes('beta'))
const latestBeta = betaVersions.length ? betaVersions[betaVersions.length - 1] : null
console.log(`Current beta version: ${latestBeta}`)
return latestBeta
} catch (error) {
console.error('Error fetching package versions:', error)
process.exit(1)
}
},

publishNextBetaVersion() {
const currentBetaVersion = this.getCurrentBetaVersion()
if (!currentBetaVersion) {
console.error('No beta version found.')
process.exit(1)
}

const nextBetaVersion = semver.inc(currentBetaVersion, 'prerelease', 'beta')
console.log(`Publishing version: ${nextBetaVersion}`)

try {
// Save original version
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'))
const originalVersion = packageJson.version
execSync(`npm version ${nextBetaVersion} --no-git-tag-version`)
execSync('npm publish --tag beta')
console.log(`Successfully published ${nextBetaVersion}`)

// Revert to original version
execSync(`npm version ${originalVersion} --no-git-tag-version`)
console.log(`Reverted back to original version: ${originalVersion}`)
} catch (error) {
console.error('Error publishing package:', error)
process.exit(1)
}
},
}

async function processChangelog() {
Expand Down

0 comments on commit 0e3d432

Please sign in to comment.