infra-kit 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +2 -3
- package/dist/main.js.map +4 -4
- package/package.json +3 -2
- package/scripts/build.js +4 -2
- package/src/commands/gh-create-release/gh-create-release.ts +68 -0
- package/src/commands/gh-create-release/index.ts +1 -0
- package/src/commands/gh-deploy/gh-deploy.ts +69 -0
- package/src/commands/gh-deploy/index.ts +1 -0
- package/src/commands/gh-merge-dev/gh-merge-dev.ts +60 -0
- package/src/commands/gh-merge-dev/index.ts +1 -0
- package/src/entry/main.ts +30 -74
- package/src/shared/gh-cli-auth/gh-cli-auth.ts +22 -0
- package/src/shared/gh-cli-auth/index.ts +1 -0
package/dist/main.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
`),console.log(`\u2705 Successfully launched workflow_dispatch with name !deploy-all for release branch: ${r} and environment: ${o}`)}catch(e){console.error("\u274C Error launching workflow:",e.message),process.exit(1)}
|
|
1
|
+
import{Command as x}from"commander";import{$ as a,question as d}from"zx";import{$ as p}from"zx";var n=async()=>{try{await p`gh --version`}catch{console.error("Error: GitHub CLI (gh) is not installed."),console.error("Please install it from: https://cli.github.com/"),process.exit(1)}try{await p`gh auth status`}catch{console.error("Error: GitHub CLI (gh) is not authenticated."),console.error('Please authenticate it from: https://cli.github.com/manual/gh_auth_login or type "gh auth login"'),process.exit(1)}};var l=async()=>{let r=(await d("Enter versions (e.g. 1.2.5, 1.2.6): ")).split(",").map(t=>t.trim());r.length===0&&(console.error("No versions provided. Exiting..."),process.exit(1)),(await d(`Are you sure you want to create release branches for these versions: ${r.join(", ")}? (y/n) `)).toLowerCase()!=="y"&&(console.log("Operation cancelled. Exiting..."),process.exit(0)),await a`git fetch origin`,await a`git switch dev`,await a`git pull origin dev`;for(let t of r)await y(t);console.log("All release branches were created successfully.")};async function y(e){await n(),console.log(`Creating release branch release/v${e}...`);try{await a`git switch dev`,await a`git pull origin dev`,await a`git checkout -b release/v${e}`,await a`git commit --allow-empty-message --allow-empty --message ''`,await a`git push origin release/v${e}`,await a`gh pr create --title "WIP Release v${e}" --body "Release v${e}" --base dev --head release/v${e}`,await a`git switch dev`,console.log(`Successfully created release branch: release/v${e}`)}catch(r){console.error(`Error creating release branch release/v${e}:`,r.message)}}import w from"@inquirer/select";import{$ as u}from"zx";var g=async()=>{await n();let e=["dev","arthur","renana","roman","eliran","alex","vova","oriana"],r=[];try{let o=await u`gh pr list --search "Release in:title" --base dev --json number,title,headRefName,state,baseRefName`,h=JSON.parse(o.stdout);h.length===0&&(console.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),process.exit(1)),r=h.map(v=>v.headRefName)}catch(o){console.error("\u274C Error fetching release PRs:",o.message),process.exit(1)}let s=await w({message:"\u{1F50D} Select release branch",choices:r.map(o=>({name:o.replace("release/v",""),value:o}))});r.some(o=>o===s)||(console.error(`\u274C Release branch ${s} not found in open PRs. Exiting...`),process.exit(1));let t=await w({message:"Select environment",choices:e.map(o=>({name:o,value:o}))});e.includes(t)||(console.error(`\u274C Invalid environment: ${t}. Exiting...`),process.exit(1));try{await u`gh workflow run "!deploy-all" --ref ${s} -f environment=${t}`,console.log(`
|
|
2
|
+
`),console.log(`\u2705 Successfully launched workflow_dispatch with name !deploy-all for release branch: ${s} and environment: ${t}`)}catch(o){console.error("\u274C Error launching workflow:",o.message),process.exit(1)}};import{$ as i,question as f}from"zx";var m=async()=>{let r=(await f("Enter branch names separated by commas: ")).split(",").map(t=>t.trim());r.length===0&&(console.error("No branches provided. Exiting..."),process.exit(1)),(await f(`Are you sure you want to merge dev into these branches: ${r.join(", ")}? (y/n) `)).toLowerCase()!=="y"&&(console.log("Operation cancelled. Exiting..."),process.exit(0)),await i`git fetch origin`,await i`git switch dev`,await i`git pull origin dev`;for(let t of r)await b(t);console.log("All merges completed.")},b=async e=>{console.log(`Merging dev into ${e}...`);try{await i`git switch ${e}`,await i`git pull origin ${e}`,await i`git merge origin/dev --no-edit`,await i`git push origin ${e}`,await i`git switch dev`,console.log(`Successfully merged dev into ${e}`)}catch(r){console.error(`Error merging dev into ${e}:`,r.message)}};var c=new x;c.command("deploy").description("Deploy any release branch to any environment").action(async()=>{await g()});c.command("create-release").description("Create a new release branch").action(async()=>{await l()});c.command("merge-dev").description("Merge dev branch into every release branch").action(async()=>{await m()});c.parse(process.argv);
|
|
4
3
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/entry/main.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["select", "$", "ENVs", "releasePRsList", "releasePRs", "releasePRsArray", "pr", "error", "selectedReleaseBranch", "env"]
|
|
3
|
+
"sources": ["../src/entry/main.ts", "../src/commands/gh-create-release/gh-create-release.ts", "../src/shared/gh-cli-auth/gh-cli-auth.ts", "../src/commands/gh-deploy/gh-deploy.ts", "../src/commands/gh-merge-dev/gh-merge-dev.ts"],
|
|
4
|
+
"sourcesContent": ["import { Command } from 'commander'\n\nimport { ghCreateRelease } from '../commands/gh-create-release'\nimport { ghDeploy } from '../commands/gh-deploy'\nimport { ghMergeDev } from '../commands/gh-merge-dev'\n\nconst program = new Command()\n\nprogram\n .command('deploy')\n .description('Deploy any release branch to any environment')\n .action(async () => {\n await ghDeploy()\n })\n\nprogram\n .command('create-release')\n .description('Create a new release branch')\n .action(async () => {\n await ghCreateRelease()\n })\n\nprogram\n .command('merge-dev')\n .description('Merge dev branch into every release branch')\n .action(async () => {\n await ghMergeDev()\n })\n\nprogram.parse(process.argv)\n", "import { $, question } from 'zx'\n\nimport { validateGitHubCliAndAuth } from '../../shared/gh-cli-auth'\n\nexport const ghCreateRelease = async () => {\n const versionBranches = await question('Enter versions (e.g. 1.2.5, 1.2.6): ')\n\n const versions = versionBranches.split(',').map((version) => version.trim())\n\n // Validate input\n if (versions.length === 0) {\n console.error('No versions provided. Exiting...')\n process.exit(1)\n }\n\n // Confirm the operation\n const confirm = await question(\n `Are you sure you want to create release branches for these versions: ${versions.join(', ')}? (y/n) `,\n )\n\n if (confirm.toLowerCase() !== 'y') {\n console.log('Operation cancelled. Exiting...')\n process.exit(0)\n }\n\n await $`git fetch origin`\n\n await $`git switch dev`\n\n await $`git pull origin dev`\n\n // Create release branches for each version\n for (const version of versions) {\n await createReleaseBranch(version)\n }\n\n console.log('All release branches were created successfully.')\n}\n\n//#region Declarations\n\n// Function to create a release branch\nasync function createReleaseBranch(version: string) {\n await validateGitHubCliAndAuth()\n\n console.log(`Creating release branch release/v${version}...`)\n\n try {\n await $`git switch dev`\n\n await $`git pull origin dev`\n\n await $`git checkout -b release/v${version}`\n\n await $`git commit --allow-empty-message --allow-empty --message ''`\n\n await $`git push origin release/v${version}`\n\n await $`gh pr create --title \"WIP Release v${version}\" --body \"Release v${version}\" --base dev --head release/v${version}`\n\n await $`git switch dev`\n\n console.log(`Successfully created release branch: release/v${version}`)\n } catch (error) {\n console.error(`Error creating release branch release/v${version}:`, error.message)\n }\n}\n//#endregion Declarations\n", "import { $ } from 'zx'\n\n/**\n * Validate GitHub CLI installation and authentication status and throw an error if not valid\n */\nexport const validateGitHubCliAndAuth = async () => {\n try {\n await $`gh --version`\n } catch (error) {\n console.error('Error: GitHub CLI (gh) is not installed.')\n console.error('Please install it from: https://cli.github.com/')\n process.exit(1)\n }\n\n try {\n await $`gh auth status`\n } catch (error) {\n console.error('Error: GitHub CLI (gh) is not authenticated.')\n console.error('Please authenticate it from: https://cli.github.com/manual/gh_auth_login or type \"gh auth login\"')\n process.exit(1)\n }\n}\n", "import select from '@inquirer/select'\nimport { $ } from 'zx'\n\nimport { validateGitHubCliAndAuth } from '../../shared/gh-cli-auth'\n\nexport const ghDeploy = async () => {\n await validateGitHubCliAndAuth()\n\n const ENVs = ['dev', 'arthur', 'renana', 'roman', 'eliran', 'alex', 'vova', 'oriana']\n\n let releasePRsList: string[] = []\n\n try {\n // Example of releasePRs.output: {\"headRefName\":\"release/v1.8.0\",\"number\":665,\"state\":\"OPEN\",\"title\":\"WIP Release/v1.8.0\"}\n const releasePRs =\n await $`gh pr list --search \"Release in:title\" --base dev --json number,title,headRefName,state,baseRefName`\n\n const releasePRsArray = JSON.parse(releasePRs.stdout)\n\n if (releasePRsArray.length === 0) {\n console.error('\u274C No release PRs found. Check the project folder for the script. Exiting...')\n process.exit(1)\n }\n\n releasePRsList = releasePRsArray.map((pr) => pr.headRefName)\n } catch (error) {\n console.error('\u274C Error fetching release PRs:', error.message)\n process.exit(1)\n }\n\n const selectedReleaseBranch = await select({\n message: '\uD83D\uDD0D Select release branch',\n choices: releasePRsList.map((pr) => ({\n name: pr.replace('release/v', ''),\n value: pr,\n })),\n })\n\n // Check if release branch exists in the list\n if (!releasePRsList.some((pr) => pr === selectedReleaseBranch)) {\n console.error(`\u274C Release branch ${selectedReleaseBranch} not found in open PRs. Exiting...`)\n process.exit(1)\n }\n\n const env = await select({\n message: 'Select environment',\n choices: ENVs.map((env) => ({\n name: env,\n value: env,\n })),\n })\n\n if (!ENVs.includes(env)) {\n console.error(`\u274C Invalid environment: ${env}. Exiting...`)\n process.exit(1)\n }\n\n try {\n await $`gh workflow run \"!deploy-all\" --ref ${selectedReleaseBranch} -f environment=${env}`\n\n console.log('\\n')\n console.log(\n `\u2705 Successfully launched workflow_dispatch with name !deploy-all for release branch: ${selectedReleaseBranch} and environment: ${env}`,\n )\n } catch (error) {\n console.error('\u274C Error launching workflow:', error.message)\n process.exit(1)\n }\n}\n", "import { $, question } from 'zx'\n\n/**\n * Merge dev into every release branch\n */\nexport const ghMergeDev = async () => {\n const branchesInput = await question('Enter branch names separated by commas: ')\n\n const branches = branchesInput.split(',').map((branch) => branch.trim())\n\n // Validate input\n if (branches.length === 0) {\n console.error('No branches provided. Exiting...')\n process.exit(1)\n }\n\n // Confirm the operation\n const confirm = await question(\n `Are you sure you want to merge dev into these branches: ${branches.join(', ')}? (y/n) `,\n )\n\n if (confirm.toLowerCase() !== 'y') {\n console.log('Operation cancelled. Exiting...')\n process.exit(0)\n }\n\n await $`git fetch origin`\n\n await $`git switch dev`\n\n await $`git pull origin dev`\n\n // Merge dev into each branch\n for (const branch of branches) {\n await mergeDev(branch)\n }\n\n console.log('All merges completed.')\n}\n\n// Function to merge dev into a given branch\nconst mergeDev = async (branch: string) => {\n console.log(`Merging dev into ${branch}...`)\n\n try {\n await $`git switch ${branch}`\n\n await $`git pull origin ${branch}`\n\n await $`git merge origin/dev --no-edit`\n\n await $`git push origin ${branch}`\n\n await $`git switch dev`\n\n console.log(`Successfully merged dev into ${branch}`)\n } catch (error) {\n console.error(`Error merging dev into ${branch}:`, error.message)\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,WAAAA,MAAe,YCAxB,OAAS,KAAAC,EAAG,YAAAC,MAAgB,KCA5B,OAAS,KAAAC,MAAS,KAKX,IAAMC,EAA2B,SAAY,CAClD,GAAI,CACF,MAAMD,eACR,MAAgB,CACd,QAAQ,MAAM,0CAA0C,EACxD,QAAQ,MAAM,iDAAiD,EAC/D,QAAQ,KAAK,CAAC,CAChB,CAEA,GAAI,CACF,MAAMA,iBACR,MAAgB,CACd,QAAQ,MAAM,8CAA8C,EAC5D,QAAQ,MAAM,kGAAkG,EAChH,QAAQ,KAAK,CAAC,CAChB,CACF,EDjBO,IAAME,EAAkB,SAAY,CAGzC,IAAMC,GAFkB,MAAMC,EAAS,sCAAsC,GAE5C,MAAM,GAAG,EAAE,IAAKC,GAAYA,EAAQ,KAAK,CAAC,EAGvEF,EAAS,SAAW,IACtB,QAAQ,MAAM,kCAAkC,EAChD,QAAQ,KAAK,CAAC,IAIA,MAAMC,EACpB,wEAAwED,EAAS,KAAK,IAAI,CAAC,UAC7F,GAEY,YAAY,IAAM,MAC5B,QAAQ,IAAI,iCAAiC,EAC7C,QAAQ,KAA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QAAQ,IAAI,gCAAgCI,CAAM,EAAE,CACtD,OAASE,EAAO,CACd,QAAQ,MAAM,0BAA0BF,CAAM,IAAKE,EAAM,OAAO,CAClE,CACF,EJrDA,IAAMC,EAAU,IAAIC,EAEpBD,EACG,QAAQ,QAAQ,EAChB,YAAY,8CAA8C,EAC1D,OAAO,SAAY,CAClB,MAAME,EAAS,CACjB,CAAC,EAEHF,EACG,QAAQ,gBAAgB,EACxB,YAAY,6BAA6B,EACzC,OAAO,SAAY,CAClB,MAAMG,EAAgB,CACxB,CAAC,EAEHH,EACG,QAAQ,WAAW,EACnB,YAAY,4CAA4C,EACxD,OAAO,SAAY,CAClB,MAAMI,EAAW,CACnB,CAAC,EAEHJ,EAAQ,MAAM,QAAQ,IAAI",
|
|
6
|
+
"names": ["Command", "$", "question", "$", "validateGitHubCliAndAuth", "ghCreateRelease", "versions", "question", "version", "$", "createReleaseBranch", "validateGitHubCliAndAuth", "error", "select", "$", "ghDeploy", "validateGitHubCliAndAuth", "ENVs", "releasePRsList", "releasePRs", "$", "releasePRsArray", "pr", "error", "selectedReleaseBranch", "select", "env", "$", "question", "ghMergeDev", "branches", "branch", "mergeDev", "error", "program", "Command", "ghDeploy", "ghCreateRelease", "ghMergeDev"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "infra-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"description": "infra-kit",
|
|
6
6
|
"main": "dist/main.js",
|
|
7
7
|
"module": "dist/main.js",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@inquirer/select": "^4.0.6",
|
|
33
|
+
"commander": "^13.1.0",
|
|
33
34
|
"zx": "^8.3.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
@@ -37,6 +38,6 @@
|
|
|
37
38
|
"@monorepo/storybook-config": "workspace:*",
|
|
38
39
|
"@monorepo/vitest-config": "workspace:*",
|
|
39
40
|
"esbuild": "^0.24.2",
|
|
40
|
-
"typescript": "^5.7.
|
|
41
|
+
"typescript": "^5.7.3"
|
|
41
42
|
}
|
|
42
43
|
}
|
package/scripts/build.js
CHANGED
|
@@ -3,6 +3,8 @@ import fs from 'node:fs'
|
|
|
3
3
|
import { dirname, resolve } from 'node:path'
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
5
|
|
|
6
|
+
import packageJson from '../package.json' with { type: 'json' }
|
|
7
|
+
|
|
6
8
|
const __filename = fileURLToPath(import.meta.url)
|
|
7
9
|
const __dirname = dirname(__filename)
|
|
8
10
|
|
|
@@ -21,7 +23,7 @@ await esbuild.build({
|
|
|
21
23
|
outdir: OUT_DIR,
|
|
22
24
|
sourcemap: true,
|
|
23
25
|
minify: true,
|
|
24
|
-
external:
|
|
26
|
+
external: Object.keys(packageJson.dependencies),
|
|
25
27
|
})
|
|
26
28
|
|
|
27
29
|
for (const entryPoint of entryPoints) {
|
|
@@ -31,5 +33,5 @@ for (const entryPoint of entryPoints) {
|
|
|
31
33
|
|
|
32
34
|
const fileName = bundlePath.split('/').pop()
|
|
33
35
|
|
|
34
|
-
console.log('✅ Build', fileName, '-', +(stat.size / 1024 / 1024).toPrecision(3), 'MB')
|
|
36
|
+
console.log('✅ Build was completed successfully: ', fileName, '-', +(stat.size / 1024 / 1024).toPrecision(3), 'MB')
|
|
35
37
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { $, question } from 'zx'
|
|
2
|
+
|
|
3
|
+
import { validateGitHubCliAndAuth } from '../../shared/gh-cli-auth'
|
|
4
|
+
|
|
5
|
+
export const ghCreateRelease = async () => {
|
|
6
|
+
const versionBranches = await question('Enter versions (e.g. 1.2.5, 1.2.6): ')
|
|
7
|
+
|
|
8
|
+
const versions = versionBranches.split(',').map((version) => version.trim())
|
|
9
|
+
|
|
10
|
+
// Validate input
|
|
11
|
+
if (versions.length === 0) {
|
|
12
|
+
console.error('No versions provided. Exiting...')
|
|
13
|
+
process.exit(1)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Confirm the operation
|
|
17
|
+
const confirm = await question(
|
|
18
|
+
`Are you sure you want to create release branches for these versions: ${versions.join(', ')}? (y/n) `,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
if (confirm.toLowerCase() !== 'y') {
|
|
22
|
+
console.log('Operation cancelled. Exiting...')
|
|
23
|
+
process.exit(0)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
await $`git fetch origin`
|
|
27
|
+
|
|
28
|
+
await $`git switch dev`
|
|
29
|
+
|
|
30
|
+
await $`git pull origin dev`
|
|
31
|
+
|
|
32
|
+
// Create release branches for each version
|
|
33
|
+
for (const version of versions) {
|
|
34
|
+
await createReleaseBranch(version)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.log('All release branches were created successfully.')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#region Declarations
|
|
41
|
+
|
|
42
|
+
// Function to create a release branch
|
|
43
|
+
async function createReleaseBranch(version: string) {
|
|
44
|
+
await validateGitHubCliAndAuth()
|
|
45
|
+
|
|
46
|
+
console.log(`Creating release branch release/v${version}...`)
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
await $`git switch dev`
|
|
50
|
+
|
|
51
|
+
await $`git pull origin dev`
|
|
52
|
+
|
|
53
|
+
await $`git checkout -b release/v${version}`
|
|
54
|
+
|
|
55
|
+
await $`git commit --allow-empty-message --allow-empty --message ''`
|
|
56
|
+
|
|
57
|
+
await $`git push origin release/v${version}`
|
|
58
|
+
|
|
59
|
+
await $`gh pr create --title "WIP Release v${version}" --body "Release v${version}" --base dev --head release/v${version}`
|
|
60
|
+
|
|
61
|
+
await $`git switch dev`
|
|
62
|
+
|
|
63
|
+
console.log(`Successfully created release branch: release/v${version}`)
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(`Error creating release branch release/v${version}:`, error.message)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//#endregion Declarations
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ghCreateRelease } from './gh-create-release'
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import select from '@inquirer/select'
|
|
2
|
+
import { $ } from 'zx'
|
|
3
|
+
|
|
4
|
+
import { validateGitHubCliAndAuth } from '../../shared/gh-cli-auth'
|
|
5
|
+
|
|
6
|
+
export const ghDeploy = async () => {
|
|
7
|
+
await validateGitHubCliAndAuth()
|
|
8
|
+
|
|
9
|
+
const ENVs = ['dev', 'arthur', 'renana', 'roman', 'eliran', 'alex', 'vova', 'oriana']
|
|
10
|
+
|
|
11
|
+
let releasePRsList: string[] = []
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
// Example of releasePRs.output: {"headRefName":"release/v1.8.0","number":665,"state":"OPEN","title":"WIP Release/v1.8.0"}
|
|
15
|
+
const releasePRs =
|
|
16
|
+
await $`gh pr list --search "Release in:title" --base dev --json number,title,headRefName,state,baseRefName`
|
|
17
|
+
|
|
18
|
+
const releasePRsArray = JSON.parse(releasePRs.stdout)
|
|
19
|
+
|
|
20
|
+
if (releasePRsArray.length === 0) {
|
|
21
|
+
console.error('❌ No release PRs found. Check the project folder for the script. Exiting...')
|
|
22
|
+
process.exit(1)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
releasePRsList = releasePRsArray.map((pr) => pr.headRefName)
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error('❌ Error fetching release PRs:', error.message)
|
|
28
|
+
process.exit(1)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const selectedReleaseBranch = await select({
|
|
32
|
+
message: '🔍 Select release branch',
|
|
33
|
+
choices: releasePRsList.map((pr) => ({
|
|
34
|
+
name: pr.replace('release/v', ''),
|
|
35
|
+
value: pr,
|
|
36
|
+
})),
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
// Check if release branch exists in the list
|
|
40
|
+
if (!releasePRsList.some((pr) => pr === selectedReleaseBranch)) {
|
|
41
|
+
console.error(`❌ Release branch ${selectedReleaseBranch} not found in open PRs. Exiting...`)
|
|
42
|
+
process.exit(1)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const env = await select({
|
|
46
|
+
message: 'Select environment',
|
|
47
|
+
choices: ENVs.map((env) => ({
|
|
48
|
+
name: env,
|
|
49
|
+
value: env,
|
|
50
|
+
})),
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
if (!ENVs.includes(env)) {
|
|
54
|
+
console.error(`❌ Invalid environment: ${env}. Exiting...`)
|
|
55
|
+
process.exit(1)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
await $`gh workflow run "!deploy-all" --ref ${selectedReleaseBranch} -f environment=${env}`
|
|
60
|
+
|
|
61
|
+
console.log('\n')
|
|
62
|
+
console.log(
|
|
63
|
+
`✅ Successfully launched workflow_dispatch with name !deploy-all for release branch: ${selectedReleaseBranch} and environment: ${env}`,
|
|
64
|
+
)
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error('❌ Error launching workflow:', error.message)
|
|
67
|
+
process.exit(1)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ghDeploy } from './gh-deploy'
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { $, question } from 'zx'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merge dev into every release branch
|
|
5
|
+
*/
|
|
6
|
+
export const ghMergeDev = async () => {
|
|
7
|
+
const branchesInput = await question('Enter branch names separated by commas: ')
|
|
8
|
+
|
|
9
|
+
const branches = branchesInput.split(',').map((branch) => branch.trim())
|
|
10
|
+
|
|
11
|
+
// Validate input
|
|
12
|
+
if (branches.length === 0) {
|
|
13
|
+
console.error('No branches provided. Exiting...')
|
|
14
|
+
process.exit(1)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Confirm the operation
|
|
18
|
+
const confirm = await question(
|
|
19
|
+
`Are you sure you want to merge dev into these branches: ${branches.join(', ')}? (y/n) `,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
if (confirm.toLowerCase() !== 'y') {
|
|
23
|
+
console.log('Operation cancelled. Exiting...')
|
|
24
|
+
process.exit(0)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
await $`git fetch origin`
|
|
28
|
+
|
|
29
|
+
await $`git switch dev`
|
|
30
|
+
|
|
31
|
+
await $`git pull origin dev`
|
|
32
|
+
|
|
33
|
+
// Merge dev into each branch
|
|
34
|
+
for (const branch of branches) {
|
|
35
|
+
await mergeDev(branch)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
console.log('All merges completed.')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Function to merge dev into a given branch
|
|
42
|
+
const mergeDev = async (branch: string) => {
|
|
43
|
+
console.log(`Merging dev into ${branch}...`)
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
await $`git switch ${branch}`
|
|
47
|
+
|
|
48
|
+
await $`git pull origin ${branch}`
|
|
49
|
+
|
|
50
|
+
await $`git merge origin/dev --no-edit`
|
|
51
|
+
|
|
52
|
+
await $`git push origin ${branch}`
|
|
53
|
+
|
|
54
|
+
await $`git switch dev`
|
|
55
|
+
|
|
56
|
+
console.log(`Successfully merged dev into ${branch}`)
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error(`Error merging dev into ${branch}:`, error.message)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ghMergeDev } from './gh-merge-dev'
|
package/src/entry/main.ts
CHANGED
|
@@ -1,74 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
releasePRsList = releasePRsArray.map((pr) => pr.headRefName)
|
|
32
|
-
} catch (error) {
|
|
33
|
-
console.error('❌ Error fetching release PRs:', error.message)
|
|
34
|
-
process.exit(1)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const selectedReleaseBranch = await select({
|
|
38
|
-
message: 'Select release branch',
|
|
39
|
-
choices: releasePRsList.map((pr) => ({
|
|
40
|
-
name: pr.replace('release/v', ''),
|
|
41
|
-
value: pr,
|
|
42
|
-
})),
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
// Check if release branch exists in the list
|
|
46
|
-
if (!releasePRsList.some((pr) => pr === selectedReleaseBranch)) {
|
|
47
|
-
console.error(`❌ Release branch ${selectedReleaseBranch} not found in open PRs. Exiting...`)
|
|
48
|
-
process.exit(1)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const env = await select({
|
|
52
|
-
message: 'Select environment',
|
|
53
|
-
choices: ENVs.map((env) => ({
|
|
54
|
-
name: env,
|
|
55
|
-
value: env,
|
|
56
|
-
})),
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
if (!ENVs.includes(env)) {
|
|
60
|
-
console.error(`❌ Invalid environment: ${env}. Exiting...`)
|
|
61
|
-
process.exit(1)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
await $`gh workflow run "!deploy-all" --ref ${selectedReleaseBranch} -f environment=${env}`
|
|
66
|
-
|
|
67
|
-
console.log('\n')
|
|
68
|
-
console.log(
|
|
69
|
-
`✅ Successfully launched workflow_dispatch with name !deploy-all for release branch: ${selectedReleaseBranch} and environment: ${env}`,
|
|
70
|
-
)
|
|
71
|
-
} catch (error) {
|
|
72
|
-
console.error('❌ Error launching workflow:', error.message)
|
|
73
|
-
process.exit(1)
|
|
74
|
-
}
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
|
|
3
|
+
import { ghCreateRelease } from '../commands/gh-create-release'
|
|
4
|
+
import { ghDeploy } from '../commands/gh-deploy'
|
|
5
|
+
import { ghMergeDev } from '../commands/gh-merge-dev'
|
|
6
|
+
|
|
7
|
+
const program = new Command()
|
|
8
|
+
|
|
9
|
+
program
|
|
10
|
+
.command('deploy')
|
|
11
|
+
.description('Deploy any release branch to any environment')
|
|
12
|
+
.action(async () => {
|
|
13
|
+
await ghDeploy()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
program
|
|
17
|
+
.command('create-release')
|
|
18
|
+
.description('Create a new release branch')
|
|
19
|
+
.action(async () => {
|
|
20
|
+
await ghCreateRelease()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
program
|
|
24
|
+
.command('merge-dev')
|
|
25
|
+
.description('Merge dev branch into every release branch')
|
|
26
|
+
.action(async () => {
|
|
27
|
+
await ghMergeDev()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
program.parse(process.argv)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { $ } from 'zx'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Validate GitHub CLI installation and authentication status and throw an error if not valid
|
|
5
|
+
*/
|
|
6
|
+
export const validateGitHubCliAndAuth = async () => {
|
|
7
|
+
try {
|
|
8
|
+
await $`gh --version`
|
|
9
|
+
} catch (error) {
|
|
10
|
+
console.error('Error: GitHub CLI (gh) is not installed.')
|
|
11
|
+
console.error('Please install it from: https://cli.github.com/')
|
|
12
|
+
process.exit(1)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
await $`gh auth status`
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error('Error: GitHub CLI (gh) is not authenticated.')
|
|
19
|
+
console.error('Please authenticate it from: https://cli.github.com/manual/gh_auth_login or type "gh auth login"')
|
|
20
|
+
process.exit(1)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { validateGitHubCliAndAuth } from './gh-cli-auth'
|