@docupace/pipeline 1.0.39-matttest.3 → 1.0.39-matttest.30
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/README.md +136 -0
- package/next/execute.sh +8 -2
- package/package.json +4 -2
- package/src/auth0/configure.js +4 -4
- package/src/auth0/metadata.js +1 -2
- package/src/changeset/cli.js +59 -220
- package/src/changeset/create.js +182 -0
- package/src/changeset/util.js +27 -0
- package/src/changeset/validate.js +25 -24
- package/src/changeset/version.js +89 -0
- package/src/jenkins/setParams.groovy +1 -2
- package/src/next/apache.js +38 -35
- package/src/next/cli.js +4 -13
- package/src/next/config.js +8 -0
- package/src/next/deploy.js +5 -1
- package/src/next/haproxy.js +25 -26
- package/src/next/jira.js +3 -6
- package/src/next/logger.js +17 -0
- package/src/next/publish.js +53 -30
- package/src/next/util.js +46 -42
- package/src/next/vault.js +7 -5
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Pipeline Shared Scripts
|
|
2
|
+
|
|
3
|
+
A collection of CLI tools for Docupace's CI/CD pipelines and deployment workflows.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides a set of command-line interfaces (CLIs) to facilitate various DevOps operations in the Docupace ecosystem:
|
|
8
|
+
|
|
9
|
+
- `dp-next-cli`: Deployment and pipeline management for Next applications
|
|
10
|
+
- `dp-changeset-cli`: Versioning and changeset management
|
|
11
|
+
- `dp-auth0-cli`: Auth0 tenant configuration and management
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @docupace/pipeline
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or with pnpm:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add @docupace/pipeline
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Command Line Interfaces
|
|
26
|
+
|
|
27
|
+
### dp-next-cli
|
|
28
|
+
|
|
29
|
+
Manages deployment, Docker image handling, and infrastructure configuration.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
dp-next-cli [command] [options]
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Commands:**
|
|
36
|
+
|
|
37
|
+
- `pull <imageName>`: Pull a Docker image from the registry
|
|
38
|
+
- `sonar`: Run Sonar analysis
|
|
39
|
+
- `addApacheSite`: Add site to apache
|
|
40
|
+
- `connectClone`: Clone connect site
|
|
41
|
+
- `haproxySync`: Sync haproxy config
|
|
42
|
+
- `vaultAddSiteData`: Add m2m auth0 data to vault
|
|
43
|
+
- `-s, --site-name <siteName>`: Site name
|
|
44
|
+
- `-p, --site-config-remote-path <path>`: Site config remote path
|
|
45
|
+
- `publish`: Publish a Docker image
|
|
46
|
+
- `deploy-from-site`: Deploy an application for a specific site
|
|
47
|
+
- `-f, --from-env <fromEnv>`: Source environment
|
|
48
|
+
- `-t, --to-env <toEnv>`: Target environment
|
|
49
|
+
- `-F, --from-site <fromSite>`: Source site
|
|
50
|
+
- `-T, --to-site <toSite>`: Target site
|
|
51
|
+
- `-c, --deploy-core <deployCore>`: Deploy Core (default: "false")
|
|
52
|
+
- `-C, --deploy-connect <deployConnect>`: Deploy Connect (default: "false")
|
|
53
|
+
- `deploy-template`: Deploy an application for a specific site
|
|
54
|
+
- `deploy-app <application>`: Deploy an application for a specific site
|
|
55
|
+
- `deploy-core <env> <site>`: Deploy Core
|
|
56
|
+
- `-l, --liquibase <liquibase>`: Application name (default: "true")
|
|
57
|
+
- `-b, --branch <branch>`: Branch (default: "master")
|
|
58
|
+
- `deploy-connect <env> <site>`: Deploy Connect
|
|
59
|
+
- `-l, --liquibase <liquibase>`: Application name (default: "true")
|
|
60
|
+
- `-b, --branch <branch>`: Branch (default: "master")
|
|
61
|
+
- `deploy-core-pipeline <env> <site>`: Deploy Core via pipeline
|
|
62
|
+
- `-l, --liquibase <liquibase>`: Application name (default: "true")
|
|
63
|
+
- `-b, --branch <branch>`: Branch (default: "master")
|
|
64
|
+
- `copy`: Copy a Docker image between registries
|
|
65
|
+
- `-a, --application <application>`: Application name
|
|
66
|
+
- `-f, --from-env <fromEnv>`: Source environment
|
|
67
|
+
- `-t, --to-env <toEnv>`: Target environment
|
|
68
|
+
- `-g, --tag <tag>`: Image tag
|
|
69
|
+
- `run-pipeline`: Trigger a pipeline by name
|
|
70
|
+
- `-r, --repository <repository>`: Repository name
|
|
71
|
+
- `-p, --pipeline-name <pipelineName>`: Pipeline name
|
|
72
|
+
- `-b, --branch <branch>`: Branch name
|
|
73
|
+
- `-v, --variables <key=value>`: Pipeline variable as key=value pair
|
|
74
|
+
- `-w, --wait`: Wait for the pipeline to complete (default: false)
|
|
75
|
+
|
|
76
|
+
### dp-changeset-cli
|
|
77
|
+
|
|
78
|
+
Manages versioning and changesets for mono-repos and single-package repos.
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
dp-changeset-cli [command] [options]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Commands:**
|
|
85
|
+
|
|
86
|
+
- `validate`: Validate changesets for the provided PR
|
|
87
|
+
- `version`: Run Changeset versioning
|
|
88
|
+
- `commit-tag`: Commit and tag the new version
|
|
89
|
+
- `version-commit-tag`: Run versioning and commit-and-tag in sequence
|
|
90
|
+
- `close-version`: Close a version and create a release branch
|
|
91
|
+
- `create-changeset`: Create a changeset based on the current branch and Jira ticket information
|
|
92
|
+
|
|
93
|
+
### dp-auth0-cli
|
|
94
|
+
|
|
95
|
+
Manages Auth0 tenant configuration across environments.
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
dp-auth0-cli [command] [options]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Commands:**
|
|
102
|
+
|
|
103
|
+
- `configureFromSite <fromSite> <toSite> <fromEnv> <toEnv> <deployUI> <deployGraphQLServer> <useNewDomain> <useS3>`: Configure Auth0 tenants
|
|
104
|
+
- `getVaultSecrets <vaultPath>`: Get secrets from Vault
|
|
105
|
+
- `configureAlias <site> <env> <username> <password> <realm>`: Configure Core Alias for the given site
|
|
106
|
+
- `exportConf <site> <env>`: Export Auth0 configuration for the given site
|
|
107
|
+
- `getAuth0Metadata <site> <env>`: Get Auth0 metadata for the given site
|
|
108
|
+
|
|
109
|
+
## Environment Configuration
|
|
110
|
+
|
|
111
|
+
The CLI tools look for environment configuration in the following locations:
|
|
112
|
+
- `.env.pipeline.local`
|
|
113
|
+
- `config/.env.pipeline.local`
|
|
114
|
+
|
|
115
|
+
## Examples
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# Deploy from one site to another
|
|
119
|
+
dp-next-cli deploy-from-site --from-env dev --to-env dev --from-site financialdev --to-site template --deploy-core true
|
|
120
|
+
|
|
121
|
+
# Run a pipeline
|
|
122
|
+
dp-next-cli run-pipeline -r docupace-next-e2e -b master -p run-tests-qa
|
|
123
|
+
|
|
124
|
+
# Validate changesets
|
|
125
|
+
dp-changeset-cli validate
|
|
126
|
+
|
|
127
|
+
# Create a new changeset
|
|
128
|
+
dp-changeset-cli create-changeset
|
|
129
|
+
|
|
130
|
+
# Configure Auth0 for a site
|
|
131
|
+
dp-auth0-cli configureFromSite sourceSite targetSite dev prod true true true false
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
ISC
|
package/next/execute.sh
CHANGED
|
@@ -53,8 +53,14 @@ copy() {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
publish() {
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
SLUG_SUFFIX=""
|
|
57
|
+
if [ -n "$APP_NAME" ]; then
|
|
58
|
+
SLUG_SUFFIX="-${APP_NAME}"
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
BUILD_IMAGE_NAME="${BITBUCKET_REPO_SLUG}${SLUG_SUFFIX}:build-${BITBUCKET_BUILD_NUMBER}"
|
|
62
|
+
IMAGE_NAME="${BITBUCKET_REPO_SLUG}${SLUG_SUFFIX}:sha-${GIT_SHA}"
|
|
63
|
+
|
|
58
64
|
export DOCKER_HOST=""
|
|
59
65
|
|
|
60
66
|
echo "Publishing Docker image ${IMAGE_NAME}..."
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docupace/pipeline",
|
|
3
|
-
"version": "1.0.39-matttest.
|
|
3
|
+
"version": "1.0.39-matttest.30",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"commander": "^12.1.0",
|
|
24
24
|
"dotenv": "^16.4.7",
|
|
25
25
|
"fs-extra": "^11.3.0",
|
|
26
|
+
"inquirer": "^12.6.1",
|
|
26
27
|
"js-yaml": "^4.1.0",
|
|
27
28
|
"lodash": "^4.17.21",
|
|
28
29
|
"openai": "^4.76.3",
|
|
@@ -42,6 +43,7 @@
|
|
|
42
43
|
"test-deploy-core": "dp-next-cli deploy-core-pipeline dev template",
|
|
43
44
|
"test-deploy-from-site": "dp-next-cli deploy-from-site --from-env dev --to-env dev --from-site financialdev --to-site template --deploy-core true",
|
|
44
45
|
"test-run-pipline": "dp-next-cli run-pipeline -r docupace-next-e2e -b master -p run-tests-qa",
|
|
45
|
-
"test-validate": "dp-changset-cli validate"
|
|
46
|
+
"test-validate": "dp-changset-cli validate",
|
|
47
|
+
"test-create": "dp-changset-cli create-changeset"
|
|
46
48
|
}
|
|
47
49
|
}
|
package/src/auth0/configure.js
CHANGED
|
@@ -5,16 +5,16 @@ import crypto from 'crypto';
|
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
cloneEnvRepository,
|
|
8
|
-
readDeployConfig,
|
|
9
|
-
pushDeployConfig,
|
|
10
8
|
cloneRepository,
|
|
9
|
+
pushDeployConfig,
|
|
10
|
+
readDeployConfig,
|
|
11
11
|
} from '../next/deploy.js';
|
|
12
12
|
|
|
13
13
|
import { getVaultSecrets, updateVaultSecrets } from './vault.js';
|
|
14
14
|
import {
|
|
15
|
-
getVaultSecretsConfigs,
|
|
16
|
-
environmentConfig,
|
|
17
15
|
coreSiteEnvMap,
|
|
16
|
+
environmentConfig,
|
|
17
|
+
getVaultSecretsConfigs,
|
|
18
18
|
} from '../next/config.js';
|
|
19
19
|
|
|
20
20
|
async function ensureDirectoryExists(dirPath) {
|
package/src/auth0/metadata.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { cloneRepository } from '../next/deploy.js';
|
|
4
|
+
import { cloneRepository, pushDeployConfig } from '../next/deploy.js';
|
|
5
5
|
import { getAuth0AuthToken } from './configure.js';
|
|
6
6
|
import { getVaultSecrets } from './vault.js';
|
|
7
7
|
import { getVaultSecretsConfigs } from '../next/config.js';
|
|
8
|
-
import { pushDeployConfig } from '../next/deploy.js';
|
|
9
8
|
|
|
10
9
|
export async function getAuth0Metadata(site, env) {
|
|
11
10
|
try {
|
package/src/changeset/cli.js
CHANGED
|
@@ -1,146 +1,71 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import { $ } from 'zx';
|
|
4
|
-
import path from 'path';
|
|
5
4
|
import { validateChangesets } from './validate.js';
|
|
6
|
-
import fs from 'fs';
|
|
7
|
-
import OpenAI from 'openai';
|
|
8
|
-
import { zodResponseFormat } from 'openai/helpers/zod';
|
|
9
|
-
import z from 'zod';
|
|
10
5
|
import dotenv from 'dotenv';
|
|
11
|
-
import {
|
|
6
|
+
import { isMonoRepo, setGitInfo } from '../next/util.js';
|
|
7
|
+
import { updateJiraWithVersion, versionCommand } from './version.js';
|
|
8
|
+
import { createChangeset } from './create.js';
|
|
9
|
+
|
|
12
10
|
dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
|
|
13
|
-
import { setGitInfo } from '../next/util.js';
|
|
14
11
|
|
|
15
12
|
const program = new Command();
|
|
16
13
|
|
|
17
14
|
const args = process.argv;
|
|
18
15
|
|
|
19
|
-
async function
|
|
20
|
-
|
|
21
|
-
// Use path.join to build a safe path to `.changeset`
|
|
22
|
-
const targetDir = path.join(process.cwd(), '.changeset');
|
|
16
|
+
async function commitTagCommand(releases) {
|
|
17
|
+
console.log('📌 Checking for updates to commit...');
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
console.
|
|
19
|
+
// Check if there are changes to commit
|
|
20
|
+
const status = (await $`git status --porcelain`).stdout.trim();
|
|
21
|
+
if (!status) {
|
|
22
|
+
console.log('✅ No changes to commit. Exiting.');
|
|
23
|
+
return;
|
|
28
24
|
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function run(command) {
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
exec(command, { shell: true }, (error, stdout, stderr) => {
|
|
34
|
-
if (error) {
|
|
35
|
-
reject(error);
|
|
36
|
-
} else {
|
|
37
|
-
resolve({ stdout, stderr });
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
25
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return true;
|
|
47
|
-
} catch {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
26
|
+
console.log('📌 Committing and tagging the new version...');
|
|
27
|
+
await setGitInfo();
|
|
28
|
+
await $`git add .`;
|
|
51
29
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (await fileExists(packageJsonPath)) {
|
|
57
|
-
const fileContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
|
|
58
|
-
const packageJson = JSON.parse(fileContent);
|
|
59
|
-
return packageJson;
|
|
60
|
-
}
|
|
30
|
+
if (isMonoRepo()) {
|
|
31
|
+
await commitTagMono(releases);
|
|
32
|
+
} else {
|
|
33
|
+
await commitTag();
|
|
61
34
|
}
|
|
62
|
-
throw new Error('Main package.json not found');
|
|
63
35
|
}
|
|
64
36
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
},
|
|
71
|
-
"type": "module",
|
|
72
|
-
"keywords": [],
|
|
73
|
-
"author": "",
|
|
74
|
-
"license": "ISC",
|
|
75
|
-
"dependencies": {},
|
|
76
|
-
"devDependencies": {
|
|
77
|
-
"@changesets/cli": "^2.27.10"
|
|
78
|
-
}
|
|
37
|
+
export function getAppReleases(releases) {
|
|
38
|
+
const appReleases = releases.filter((release) =>
|
|
39
|
+
release.name.endsWith('-app'),
|
|
40
|
+
);
|
|
41
|
+
return appReleases;
|
|
79
42
|
}
|
|
80
|
-
`;
|
|
81
|
-
|
|
82
|
-
async function versionCommand(closeVersion = false) {
|
|
83
|
-
console.log('📦 Running Changeset versioning...');
|
|
84
|
-
await setGitInfo();
|
|
85
|
-
await $`mv package.json package.json.bak`;
|
|
86
|
-
await $`mv pnpm-lock.yaml pnpm-lock.yaml.bak`;
|
|
87
|
-
await fs.promises.writeFile('package.json', changeSetPackage);
|
|
88
|
-
await $`pnpm install`;
|
|
89
|
-
await $`rm package.json pnpm-lock.yaml`;
|
|
90
|
-
await $`mv package.json.bak package.json`;
|
|
91
|
-
await $`mv pnpm-lock.yaml.bak pnpm-lock.yaml`;
|
|
92
|
-
if (closeVersion) {
|
|
93
|
-
await $`pnpm changeset pre exit`;
|
|
94
|
-
}
|
|
95
43
|
|
|
96
|
-
|
|
44
|
+
function getAppNameFromPackageName(packageName) {
|
|
45
|
+
const appName = packageName.includes('/')
|
|
46
|
+
? packageName.split('/')[1]
|
|
47
|
+
: packageName;
|
|
97
48
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
await fs.promises.readFile('package.json', 'utf-8'),
|
|
101
|
-
);
|
|
102
|
-
const version = packageJson.version;
|
|
103
|
-
const packageName = packageJson.name;
|
|
49
|
+
return appName;
|
|
50
|
+
}
|
|
104
51
|
|
|
105
|
-
|
|
106
|
-
|
|
52
|
+
async function commitTagMono(releases) {
|
|
53
|
+
let versions = [];
|
|
54
|
+
for (const release of getAppReleases(releases)) {
|
|
55
|
+
const newVersion = release.newVersion;
|
|
56
|
+
const appName = getAppNameFromPackageName(release.name);
|
|
57
|
+
versions.push(`${appName}@${newVersion}`);
|
|
107
58
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const jiraTicketMatch = lastCommit.match(/([A-Z]+-\d+)/);
|
|
114
|
-
const jiraTicketId = jiraTicketMatch ? jiraTicketMatch[0] : null;
|
|
115
|
-
|
|
116
|
-
// If we have all the necessary data, update the component version in Jira
|
|
117
|
-
if (jiraTicketId && version && packageName) {
|
|
118
|
-
try {
|
|
119
|
-
await updateComponentVersion(jiraTicketId, packageName, version);
|
|
120
|
-
} catch (error) {
|
|
121
|
-
console.error(
|
|
122
|
-
`Failed to update Jira component version: ${error.message}`,
|
|
123
|
-
);
|
|
124
|
-
}
|
|
59
|
+
await $`git commit -m "Version bump to ${versions.join(',')} and changelog"`;
|
|
60
|
+
for (const newVersion of versions) {
|
|
61
|
+
await $`git tag ${newVersion}`;
|
|
62
|
+
console.log(`✅ Version ${newVersion} tagged.`);
|
|
125
63
|
}
|
|
126
|
-
|
|
127
|
-
console.log(
|
|
128
|
-
return { version, packageName };
|
|
64
|
+
await $`git push origin --tags`;
|
|
65
|
+
console.log(`✅ Version pushed.`);
|
|
129
66
|
}
|
|
130
67
|
|
|
131
|
-
async function
|
|
132
|
-
console.log('📌 Checking for updates to commit...');
|
|
133
|
-
|
|
134
|
-
// Check if there are changes to commit
|
|
135
|
-
const status = (await $`git status --porcelain`).stdout.trim();
|
|
136
|
-
if (!status) {
|
|
137
|
-
console.log('✅ No changes to commit. Exiting.');
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
console.log('📌 Committing and tagging the new version...');
|
|
142
|
-
await setGitInfo();
|
|
143
|
-
await $`git add .`;
|
|
68
|
+
async function commitTag() {
|
|
144
69
|
const newVersion = (
|
|
145
70
|
await $`node -p "require('./package.json').version"`
|
|
146
71
|
).stdout.trim();
|
|
@@ -163,7 +88,7 @@ program
|
|
|
163
88
|
try {
|
|
164
89
|
await validateChangesets();
|
|
165
90
|
console.log('✅ Changeset validation passed.');
|
|
166
|
-
} catch
|
|
91
|
+
} catch {
|
|
167
92
|
console.error(
|
|
168
93
|
'❌ No changeset found. Please add a changeset to this PR. Please see more information at https://docupacellc.atlassian.net/wiki/spaces/PM/pages/1350893571/Creating+changesets+for+Docupace+Next',
|
|
169
94
|
);
|
|
@@ -192,8 +117,9 @@ program
|
|
|
192
117
|
.description('Run versioning and commit-and-tag in sequence')
|
|
193
118
|
.action(async () => {
|
|
194
119
|
console.log('📦 Running all steps...');
|
|
195
|
-
await versionCommand();
|
|
196
|
-
await
|
|
120
|
+
const releases = await versionCommand();
|
|
121
|
+
await updateJiraWithVersion(releases);
|
|
122
|
+
await commitTagCommand(releases);
|
|
197
123
|
});
|
|
198
124
|
|
|
199
125
|
program
|
|
@@ -201,15 +127,21 @@ program
|
|
|
201
127
|
.description('Closes a version')
|
|
202
128
|
.action(async () => {
|
|
203
129
|
console.log('📦 Running all steps...');
|
|
204
|
-
const
|
|
205
|
-
await commitTagCommand();
|
|
130
|
+
const releases = await versionCommand(true);
|
|
131
|
+
await commitTagCommand(releases);
|
|
206
132
|
|
|
207
|
-
// Get current branch
|
|
208
133
|
const { stdout: currentBranch } = await $`git rev-parse --abbrev-ref HEAD`;
|
|
209
134
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
135
|
+
if (isMonoRepo()) {
|
|
136
|
+
for (const release of getAppReleases(releases)) {
|
|
137
|
+
const appName = getAppNameFromPackageName(release.name);
|
|
138
|
+
await $`git checkout -b release/${appName}/${release.newVersion}`;
|
|
139
|
+
await $`git push origin release/${appName}/${release.newVersion}`;
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
await $`git checkout -b release/${releases[0].newVersion}`;
|
|
143
|
+
await $`git push origin release/${releases[0].newVersion}`;
|
|
144
|
+
}
|
|
213
145
|
|
|
214
146
|
// Return to original branch
|
|
215
147
|
await $`git checkout ${currentBranch.trim()}`;
|
|
@@ -227,100 +159,7 @@ program
|
|
|
227
159
|
'Creates a changeset based on the current branch and Jira ticket information',
|
|
228
160
|
)
|
|
229
161
|
.action(async () => {
|
|
230
|
-
|
|
231
|
-
const componentName = mainPackage.name;
|
|
232
|
-
|
|
233
|
-
try {
|
|
234
|
-
// Step 1: Get the current branch name
|
|
235
|
-
const branchName = (await $`git branch --show-current`).stdout.trim();
|
|
236
|
-
console.log(`Current branch: ${branchName}`);
|
|
237
|
-
|
|
238
|
-
// Step 2: Extract Jira ticket number (e.g., matching JIRA-1234 pattern)
|
|
239
|
-
const jiraTicketMatch = branchName.match(/([A-Z]+-\d+)/);
|
|
240
|
-
if (!jiraTicketMatch) {
|
|
241
|
-
throw new Error('No Jira ticket found in the branch name.');
|
|
242
|
-
}
|
|
243
|
-
const jiraTicketId = jiraTicketMatch[0];
|
|
244
|
-
|
|
245
|
-
const jiraBaseUrl = 'https://docupacellc.atlassian.net';
|
|
246
|
-
const jiraEmail = process.env.JIRA_API_EMAIL;
|
|
247
|
-
const jiraApiKey = process.env.JIRA_API_KEY;
|
|
248
|
-
const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
|
|
249
|
-
const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
|
|
250
|
-
const jiraResponse = await fetch(jiraUrl, {
|
|
251
|
-
headers: {
|
|
252
|
-
Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
|
|
253
|
-
'Content-Type': 'application/json',
|
|
254
|
-
},
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
if (!jiraResponse.ok) {
|
|
258
|
-
throw new Error(
|
|
259
|
-
`Failed to fetch Jira ticket. Status: ${jiraResponse.status}`,
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
const jiraTicketData = await jiraResponse.json();
|
|
263
|
-
|
|
264
|
-
const jiraSummary = jiraTicketData.fields.summary;
|
|
265
|
-
|
|
266
|
-
console.log(
|
|
267
|
-
`Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
|
|
268
|
-
);
|
|
269
|
-
|
|
270
|
-
const openaiClient = new OpenAI({
|
|
271
|
-
apiKey: process.env['OPENAI_API_KEY'],
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
const ChangeRequestSchema = z.object({
|
|
275
|
-
change_type: z.enum(['patch', 'minor']),
|
|
276
|
-
summary: z.string(),
|
|
277
|
-
jira_ticket_id: z.string(),
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
const openAiResponse = await openaiClient.chat.completions.create({
|
|
281
|
-
model: 'gpt-4o-mini',
|
|
282
|
-
messages: [
|
|
283
|
-
{
|
|
284
|
-
role: 'system',
|
|
285
|
-
content: `Process JSON from a Jira ticket to generate simple maximum 2 sentence release note for the ticket and determine the change type for bug it should be a patch for new feature it should be a minor change`,
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
role: 'user',
|
|
289
|
-
content: JSON.stringify(jiraTicketData),
|
|
290
|
-
},
|
|
291
|
-
],
|
|
292
|
-
response_format: zodResponseFormat(
|
|
293
|
-
ChangeRequestSchema,
|
|
294
|
-
'changeset_schema',
|
|
295
|
-
),
|
|
296
|
-
temperature: 0,
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
const assistantResponse = openAiResponse.choices[0].message.content;
|
|
300
|
-
const parsedResponse = JSON.parse(assistantResponse);
|
|
301
|
-
|
|
302
|
-
const { change_type, summary } = parsedResponse;
|
|
303
|
-
console.log(`Change type: ${change_type}`);
|
|
304
|
-
console.log(`Release note: ${summary}`);
|
|
305
|
-
|
|
306
|
-
// Step 5: Create a changeset .md file
|
|
307
|
-
const changesetContent = `---
|
|
308
|
-
"${componentName}": ${change_type}
|
|
309
|
-
---
|
|
310
|
-
|
|
311
|
-
${summary} [${jiraTicketId}]
|
|
312
|
-
`;
|
|
313
|
-
const changesetFile = `./.changeset/${jiraTicketId}.md`;
|
|
314
|
-
|
|
315
|
-
await createChangesetDirectory();
|
|
316
|
-
await fs.promises.writeFile(changesetFile, changesetContent);
|
|
317
|
-
console.log(`Created changeset file at ${changesetFile}`);
|
|
318
|
-
|
|
319
|
-
console.log('Done!');
|
|
320
|
-
} catch (err) {
|
|
321
|
-
console.error(`Error: ${err.message}`);
|
|
322
|
-
process.exit(1);
|
|
323
|
-
}
|
|
162
|
+
await createChangeset();
|
|
324
163
|
});
|
|
325
164
|
|
|
326
165
|
// Parse arguments
|