Skip to content

Commit

Permalink
feat: improve release script with commits list
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre committed Jan 8, 2024
1 parent 6a0fef3 commit 7ea35da
Show file tree
Hide file tree
Showing 3 changed files with 347 additions and 99 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/inquirer": "^9.0.7",
"@types/node": "^20.10.7",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
Expand All @@ -32,6 +33,7 @@
"eslint-plugin-react-refresh": "^0.4.5",
"eslint-plugin-simple-import-sort": "^10.0.0",
"happy-dom": "^12.10.3",
"inquirer": "^9.2.12",
"prettier": "^3.1.1",
"simple-git": "^3.22.0",
"typescript": "^5.2.2",
Expand Down
39 changes: 33 additions & 6 deletions scripts/release.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chalk from 'chalk'
import inquirer from 'inquirer'
import { simpleGit as git } from 'simple-git'

export const exit = (reason?: string) => Boolean(reason && console.log(reason)) || process.exit(0)
Expand All @@ -11,15 +12,42 @@ const assertIsCleanRepo = async () => {
}
}

const getCommitsList = async () => {
const log = await git().log({
from: 'main',
to: 'develop',
})
return log.all.map(commit => `${commit.hash} - ${commit.message}`)
}

const inquireProceedWithCommits = async (commits: string[]) => {
console.log(chalk.blue(['', ...commits, ''].join('\n')))
const questions = [
{
type: 'confirm',
name: 'shouldProceed',
message: 'Do you want to merge and push these commits into main?',
default: true,
},
]
const answers = await inquirer.prompt(questions)
return answers.shouldProceed
}

const mergeAndPush = async () => {
await assertIsCleanRepo()

console.log(chalk.green('Checking out develop...'))
await git().checkout(['develop'])

console.log(chalk.green('Fetching latest changes for develop...'))
console.log(chalk.green('Fetching latest changes...'))
await git().fetch(['origin', 'develop'])
await git().pull('origin', 'develop')
await git().fetch(['origin', 'main'])

const commits = await getCommitsList()

const shouldProceed = await inquireProceedWithCommits(commits)
if (!shouldProceed) {
console.log(chalk.yellow('Merge and push cancelled.'))
exit()
}

console.log(chalk.green('Checking out main...'))
await git().checkout(['main'])
Expand All @@ -34,7 +62,6 @@ const mergeAndPush = async () => {

console.log(chalk.green('Pushing main to remote...'))
await git().push(['origin', 'main'])

console.log(chalk.green('Merge and push completed successfully.'))
}

Expand Down
Loading

0 comments on commit 7ea35da

Please sign in to comment.