@docupace/pipeline 1.0.0-alpha.72 → 1.0.0-alpha.9

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.
@@ -4,5 +4,4 @@
4
4
  DIR="$(cd "$(dirname "$0")" && pwd)/../@docupace/pipeline"
5
5
 
6
6
  # Pass all arguments to the actual script
7
-
8
- bash $DIR/next/changeset.sh validate $2
7
+ bash $DIR/next/changeset.sh validate $2
package/next/changeset.sh CHANGED
@@ -8,6 +8,8 @@ DIR="$(cd "$(dirname "$0")" && pwd)"
8
8
  validate_changesets() {
9
9
  if [ ! -z "$PR_ID" ]; then
10
10
  echo "🔍 Validating changesets..."
11
+ echo "Current Dir $DIR"
12
+ echo "1=$1"
11
13
  pnpm node $DIR/validateChangeset.cjs $1 || {
12
14
  if [ $? -eq 1 ]; then
13
15
  echo "❌ 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"
package/next/deploy.sh CHANGED
@@ -1,40 +1,40 @@
1
- #!/bin/bash
1
+ #!/bin/bash
2
2
 
3
- set -e # Enable command tracing
4
- # Variables
5
- REPO_NAME="gitops-dev"
6
- REPO_URL="https://x-token-auth:$GITOPS_REP_TOKEN@bitbucket.org/dp-cloud/${REPO_NAME}.git"
7
- FILE_PATH="dp/$2/$1.values.yaml"
8
- BUILD_NUMBER=$BITBUCKET_BUILD_NUMBER
9
- GITOPS_BRANCH=master
10
- if [ -n "$VERSION_TAG" ]; then
11
- DEPLOY_TAG=$VERSION_TAG
12
- else
13
- DEPLOY_TAG="build-$BUILD_NUMBER"
14
- fi
3
+ set -e # Enable command tracing
4
+ # Variables
5
+ REPO_NAME="gitops-dev"
6
+ REPO_URL="https://x-token-auth:$GITOPS_REP_TOKEN@bitbucket.org/dp-cloud/${REPO_NAME}.git"
7
+ FILE_PATH="dp/$2/$1.values.yaml"
8
+ BUILD_NUMBER=$BITBUCKET_BUILD_NUMBER
9
+ GITOPS_BRANCH=master
10
+ if [ -n "$VERSION_TAG" ]; then
11
+ DEPLOY_TAG=$VERSION_TAG
12
+ else
13
+ DEPLOY_TAG="build-$BUILD_NUMBER"
14
+ fi
15
15
 
16
16
 
17
17
 
18
- # Clone the repository
18
+ # Clone the repository
19
19
 
20
- git config user.email qxebpukjnzljnwty1knte7ym53aogk@bots.bitbucket.org
21
- git clone $REPO_URL
22
- cd ${REPO_NAME} || exit
20
+ git config user.email qxebpukjnzljnwty1knte7ym53aogk@bots.bitbucket.org
21
+ git clone $REPO_URL
22
+ cd ${REPO_NAME} || exit
23
23
 
24
- # Checkout the branch
24
+ # Checkout the branch
25
25
 
26
- # Modify the YAML file
27
- sed -i "s/tag: .*/tag: $DEPLOY_TAG/" $FILE_PATH
26
+ # Modify the YAML file
27
+ sed -i "s/tag: .*/tag: $DEPLOY_TAG/" $FILE_PATH
28
28
 
29
- # Add changes to git
30
- git add $FILE_PATH
29
+ # Add changes to git
30
+ git add $FILE_PATH
31
31
 
32
- # Commit changes
33
- git commit -m "Update image tag to $DEPLOY_TAG"
32
+ # Commit changes
33
+ git commit -m "Update image tag to $DEPLOY_TAG"
34
34
 
35
- # Push changes
36
- git push origin $GITOPS_BRANCH
35
+ # Push changes
36
+ git push origin $GITOPS_BRANCH
37
37
 
38
- # Clean up
39
- cd ..
40
- rm -rf ${REPO_NAME}
38
+ # Clean up
39
+ cd ..
40
+ rm -rf ${REPO_NAME}
@@ -0,0 +1,43 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const directoryPath = process.argv[2];
5
+
6
+ try {
7
+ // Step 1: Read the directory for md files excluding README.md
8
+ const allFiles = fs.readdirSync(directoryPath);
9
+ const mdFiles = allFiles.filter(file => file.endsWith('.md') && file !== 'README.md');
10
+
11
+ // Step 2: Check for pre.json and parse it
12
+ const preJsonPath = path.join(directoryPath, 'pre.json');
13
+ let preJson;
14
+
15
+ if (!fs.existsSync(preJsonPath) && mdFiles.length === 0) {
16
+ console.error("Error: No pre.json and no md files found.");
17
+ process.exit(1);
18
+ }
19
+
20
+ if (fs.existsSync(preJsonPath)) {
21
+ preJson = JSON.parse(fs.readFileSync(preJsonPath, 'utf-8'));
22
+
23
+ if(preJson.mode == 'pre') {
24
+ // Step 4a: Get list of changesets from pre.json
25
+ const changesets = preJson.changesets || [];
26
+ const changesetNames = changesets.map(change => change);
27
+
28
+ // Step 4b: Match files with the list of changesets
29
+ const mdFileNamesWithoutExt = mdFiles.map(file => path.basename(file, '.md'));
30
+ const unmatchedFiles = mdFileNamesWithoutExt.filter(fileName => !changesetNames.includes(fileName));
31
+
32
+ if (unmatchedFiles.length == 0) {
33
+ console.error("No new MD files found:", unmatchedFiles);
34
+ process.exit(1);
35
+ }
36
+ }
37
+ }
38
+
39
+ console.log("Validation successful.");
40
+ } catch (error) {
41
+ console.error("Error while processing:", error);
42
+ process.exit(1);
43
+ }
package/package.json CHANGED
@@ -1,28 +1,17 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.0-alpha.72",
3
+ "version": "1.0.0-alpha.9",
4
4
  "description": "",
5
5
  "main": "index.js",
6
- "type": "module",
7
6
  "bin": {
8
- "dp-changeset-cli": "src/changeset/cli.js",
9
- "dp-next-cli": "src/next/cli.js"
7
+ "next-changeset-validate": "./bin/next-changeset-validate.sh"
10
8
  },
11
9
  "keywords": [
12
10
  "bash"
13
11
  ],
14
12
  "author": "",
15
13
  "license": "ISC",
16
- "dependencies": {
17
- "@changesets/cli": "^2.27.10",
18
- "commander": "^12.1.0",
19
- "dotenv": "^16.4.7",
20
- "js-yaml": "^4.1.0",
21
- "openai": "^4.76.3",
22
- "zod": "^3.24.1",
23
- "zx": "^8.2.4"
24
- },
25
- "devDependencies": {
26
- "esbuild": "^0.24.0"
14
+ "scripts": {
15
+ "next-changeset-validate": "bash next/changeset.sh validate"
27
16
  }
28
17
  }
@@ -1,231 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { $ } from 'zx';
4
- import path from 'path';
5
- 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
- import dotenv from 'dotenv';
11
- dotenv.config({path : ['.env.pipeline.local', 'config/.env.pipeline.local']});
12
-
13
- const program = new Command();
14
-
15
- const args = process.argv;
16
-
17
- const DIR = path.resolve(process.cwd());
18
-
19
- async function fileExists(filePath) {
20
- try {
21
- await fs.promises.access(filePath);
22
- return true;
23
- } catch {
24
- return false;
25
- }
26
- }
27
-
28
- async function getMainPackage() {
29
- const mainModulePath = process.env.PWD;
30
- if (mainModulePath) {
31
- const packageJsonPath = path.join(mainModulePath, 'package.json');
32
- if (await fileExists(packageJsonPath)) {
33
- const fileContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
34
- const packageJson = JSON.parse(fileContent);
35
- return packageJson;
36
- }
37
- }
38
- throw new Error('Main package.json not found');
39
- }
40
-
41
- // Helper function to set Git info
42
- async function setGitInfo() {
43
- await $`git config --global user.email "gitops@docupace.com"`;
44
- await $`git config --global user.name "Gitops"`;
45
- await $`git remote set-url origin https://x-token-auth:${process.env.THIS_REP_TOKEN}@bitbucket.org/${process.env.BITBUCKET_REPO_FULL_NAME}.git`;
46
- }
47
-
48
- const changeSetPackage = `{
49
- "name": "changeset-package",
50
- "version": "1.0.0",
51
- "description": "",
52
- "scripts": {
53
- },
54
- "type": "module",
55
- "keywords": [],
56
- "author": "",
57
- "license": "ISC",
58
- "dependencies": {},
59
- "devDependencies": {
60
- "@changesets/cli": "^2.27.10"
61
- }
62
- }
63
- `
64
-
65
- async function versionCommand() {
66
- console.log('📦 Running Changeset versioning...');
67
- await setGitInfo();
68
- await $`mv package.json package.json.bak`
69
- await $`mv pnpm-lock.yaml pnpm-lock.yaml.bak`
70
- await fs.promises.writeFile('package.json', changeSetPackage);
71
- await $`pnpm install`;
72
- await $`rm package.json pnpm-lock.yaml`
73
- await $`mv package.json.bak package.json`
74
- await $`mv pnpm-lock.yaml.bak pnpm-lock.yaml`
75
- await $`pnpm changeset version`;
76
- console.log('✅ Changeset versioning complete.');
77
- }
78
-
79
- async function commitTagCommand() {
80
- console.log('📌 Committing and tagging the new version...');
81
- await setGitInfo();
82
- await $`git add .`;
83
- const newVersion = (await $`node -p "require('./package.json').version"`).stdout.trim();
84
- await $`git commit -m "Version bump to ${newVersion} and changelog"`;
85
- await $`git push origin`;
86
- await $`git tag v${newVersion}`;
87
- await $`git push origin --tags`;
88
- console.log(`✅ Version ${newVersion} tagged and pushed.`);
89
- }
90
-
91
- // Command: validate
92
- program
93
- .command('validate <path>')
94
- .description('Validate changesets for the provided PR')
95
- .action(async (path) => {
96
- if(!process.env.BITBUCKET_PR_ID) {
97
- return;
98
- }
99
- console.log('🔍 Validating changesets...');
100
- try {
101
- await validateChangesets(path);
102
- console.log('✅ Changeset validation passed.');
103
- } catch (error) {
104
- console.error(
105
- '❌ 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'
106
- );
107
- process.exit(1);
108
- }
109
- });
110
- // Command: version
111
- program
112
- .command('version')
113
- .description('Run Changeset versioning')
114
- .action(async () => {
115
- await versionCommand();
116
- });
117
-
118
- // Command: commit-and-tag
119
- program
120
- .command('commit-tag')
121
- .description('Commit and tag the new version')
122
- .action(async () => {
123
- await commitTagCommand();
124
- });
125
-
126
- // Command: all
127
- program
128
- .command('version-commit-tag')
129
- .description('Run versioning and commit-and-tag in sequence')
130
- .action(async () => {
131
- console.log('📦 Running all steps...');
132
- await versionCommand();
133
- await commitTagCommand();
134
- });
135
-
136
- program
137
- .name('create-changeset')
138
- .description('Creates a changeset based on the current branch and Jira ticket information')
139
- .action(async () => {
140
- const mainPackage = await getMainPackage();
141
- const componentName = mainPackage.name;
142
-
143
- try {
144
- // Step 1: Get the current branch name
145
- const branchName = (await $`git branch --show-current`).stdout.trim();
146
- console.log(`Current branch: ${branchName}`);
147
-
148
- // Step 2: Extract Jira ticket number (e.g., matching JIRA-1234 pattern)
149
- const jiraTicketMatch = branchName.match(/([A-Z]+-\d+)/);
150
- if (!jiraTicketMatch) {
151
- throw new Error('No Jira ticket found in the branch name.');
152
- }
153
- const jiraTicketId = jiraTicketMatch[0];
154
-
155
- // Step 3: Fetch Jira ticket information
156
- const jiraBaseUrl = 'https://docupacellc.atlassian.net';
157
- const jiraEmail = process.env.JIRA_API_EMAIL;
158
- const jiraApiKey = process.env.JIRA_API_KEY;
159
- const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
160
- const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
161
- const jiraResponse = await fetch(jiraUrl, {
162
- headers: {
163
- Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
164
- 'Content-Type': 'application/json',
165
- },
166
- });
167
-
168
- if (!jiraResponse.ok) {
169
- throw new Error(`Failed to fetch Jira ticket. Status: ${jiraResponse.status}`);
170
- }
171
- const jiraTicketData = await jiraResponse.json();
172
-
173
- const jiraSummary = jiraTicketData.fields.summary;
174
-
175
- console.log(`Generating release notes for ${jiraTicketId} - ${jiraSummary}`)
176
-
177
- const openaiClient = new OpenAI({
178
- apiKey: process.env['OPENAI_API_KEY'],
179
- });
180
-
181
- const ChangeRequestSchema = z.object({
182
- change_type: z.enum(["patch", "minor"]),
183
- summary: z.string(),
184
- jira_ticket_id: z.string(),
185
- });
186
-
187
- const openAiResponse = await openaiClient.chat.completions.create({
188
- model: "gpt-4o-mini",
189
- messages: [
190
- {
191
- role: "system",
192
- 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`,
193
- },
194
- {
195
- role: "user",
196
- content: JSON.stringify(jiraTicketData),
197
- },
198
- ],
199
- response_format: zodResponseFormat(ChangeRequestSchema, 'changeset_schema'),
200
- temperature: 0
201
- });
202
-
203
- const assistantResponse = openAiResponse.choices[0].message.content;
204
- const parsedResponse = JSON.parse(assistantResponse);
205
-
206
- const { change_type, summary } = parsedResponse;
207
- console.log(`Change type: ${change_type}`);
208
- console.log(`Release note: ${summary}`);
209
-
210
- // Step 5: Create a changeset using pnpm
211
- const changesetContent = `---
212
- "${componentName}": ${change_type}
213
- ---
214
-
215
- ${summary} [${jiraTicketId}]
216
- `;
217
- const changesetFile = `./.changeset/${jiraTicketId}.md`;
218
-
219
- await $`mkdir -p ./.changeset`;
220
- await fs.promises.writeFile(changesetFile, changesetContent);
221
- console.log(`Created changeset file at ${changesetFile}`);
222
-
223
- console.log('Done!');
224
- } catch (err) {
225
- console.error(`Error: ${err.message}`);
226
- }
227
- });
228
-
229
-
230
- // Parse arguments
231
- program.parse(args);
@@ -1,44 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
-
4
- export async function validateChangesets(directoryPath) {
5
- try {
6
- // Step 1: Read the directory for md files excluding README.md
7
- const allFiles = fs.readdirSync(directoryPath);
8
- const mdFiles = allFiles.filter(file => file.endsWith('.md') && file !== 'README.md');
9
-
10
- // Step 2: Check for pre.json and parse it
11
- const preJsonPath = path.join(directoryPath, 'pre.json');
12
- let preJson;
13
-
14
- if (!fs.existsSync(preJsonPath) && mdFiles.length === 0) {
15
- throw new Error("Error: No pre.json and no md files found.")
16
- }
17
-
18
- if (fs.existsSync(preJsonPath)) {
19
- preJson = JSON.parse(fs.readFileSync(preJsonPath, 'utf-8'));
20
-
21
- if(preJson.mode == 'pre') {
22
- // Step 4a: Get list of changesets from pre.json
23
- const changesets = preJson.changesets || [];
24
- const changesetNames = changesets.map(change => change);
25
-
26
- // Step 4b: Match files with the list of changesets
27
- const mdFileNamesWithoutExt = mdFiles.map(file => path.basename(file, '.md'));
28
- const unmatchedFiles = mdFileNamesWithoutExt.filter(fileName => !changesetNames.includes(fileName));
29
-
30
- if (unmatchedFiles.length == 0) {
31
- throw new Error("Error: No new MD files found:");
32
- }
33
- }
34
- }
35
-
36
- console.log("Validation successful.");
37
- } catch (error) {
38
- console.log(error.message);
39
- throw(error);
40
- }
41
- }
42
-
43
-
44
-
package/src/next/cli.js DELETED
@@ -1,59 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { Command } from 'commander';
4
- import { pull } from './pull.js';
5
- import { sonar } from './sonar.js';
6
- import { publish } from './publish.js';
7
- import { deploy } from './deploy.js';
8
- import { deployTemplate } from './deploy.js';
9
- import { copy } from './copy.js';
10
-
11
- const program = new Command();
12
-
13
- // GIT SHA computation
14
- import { $ } from 'zx';
15
- const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
16
-
17
- program
18
- .command('pull <imageName>')
19
- .description('Pull a Docker image from the registry')
20
- .action(async (imageName) => {
21
- await pull(imageName);
22
- });
23
-
24
- program
25
- .command('sonar')
26
- .description('Run Sonar analysis')
27
- .action(async () => {
28
- await sonar(GIT_SHA);
29
- });
30
-
31
- program
32
- .command('publish')
33
- .description('Publish a Docker image')
34
- .action(async () => {
35
- await publish(GIT_SHA);
36
- });
37
-
38
- program
39
- .command('deploy <application> <site>')
40
- .description('Deploy an application for a specific site')
41
- .action(async (application, site) => {
42
- await deploy(application, site);
43
- });
44
-
45
- program
46
- .command('deployTemplate <site>')
47
- .description('Deploy an application for a specific site')
48
- .action(async (site) => {
49
- await deployTemplate(site);
50
- });
51
-
52
- program
53
- .command('copy')
54
- .description('Copy a Docker image between registries')
55
- .action(async () => {
56
- await copy();
57
- });
58
-
59
- program.parse(process.argv);
package/src/next/copy.js DELETED
@@ -1,27 +0,0 @@
1
- import { $ } from 'zx';
2
-
3
-
4
- /*
5
- TARGET_ENV
6
- PUBLISH_TAG
7
- REPOSITORY_NAME
8
- */
9
- export async function copy() {
10
- const JF_REGISTRY_URL = 'registry.paperout.com';
11
- const SOURCE_REGISTRY = `${JF_REGISTRY_URL}/${process.env.REPOSITORY_NAME}-dev-docker-local`;
12
- const TARGET_REGISTRY = `${JF_REGISTRY_URL}/${process.env.REPOSITORY_NAME}-${process.env.TARGET_ENV}-docker-local`;
13
- const IMAGE_NAME = `${process.env.REPOSITORY_NAME}:${process.env.PUBLISH_TAG}`;
14
- const SOURCE_FULL_IMAGE_NAME = `${SOURCE_REGISTRY}/${IMAGE_NAME}`;
15
- const TARGET_FULL_IMAGE_NAME = `${TARGET_REGISTRY}/${IMAGE_NAME}`;
16
-
17
- console.log(`Copying Docker image: ${SOURCE_FULL_IMAGE_NAME} -> ${TARGET_FULL_IMAGE_NAME}`);
18
-
19
- // Login to source registry
20
- await $`echo ${process.env.JF_REGISTRY_PASSWORD_DEV} | docker login --username ${process.env.JF_REGISTRY_USER_DEV} --password-stdin ${JF_REGISTRY_URL}`;
21
- await $`docker pull ${SOURCE_FULL_IMAGE_NAME}`;
22
- await $`docker tag ${SOURCE_FULL_IMAGE_NAME} ${TARGET_FULL_IMAGE_NAME}`;
23
-
24
- // Login to target registry
25
- await $`echo ${process.env.JF_REGISTRY_PASSWORD_QA} | docker login --username ${process.env.JF_REGISTRY_USER_QA} --password-stdin ${JF_REGISTRY_URL}`;
26
- await $`docker push ${TARGET_FULL_IMAGE_NAME}`;
27
- }
@@ -1,118 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import yaml from 'js-yaml';
4
- import { $ } from 'zx';
5
-
6
- const REPO_NAME = 'gitops-dev';
7
- const REPO_URL = `https://x-token-auth:${process.env.GITOPS_DEV_REP_TOKEN}@bitbucket.org/dp-cloud/${REPO_NAME}.git`;
8
- const GITOPS_BRANCH = 'master';
9
-
10
- /**
11
- * Clone the repository, read the YAML file, and return the parsed data and file paths.
12
- * @param {string} application - The application name.
13
- * @param {string} site - The site name.
14
- * @returns {object} - The repository path, file path, and YAML data.
15
- */
16
- export async function readDeployConfig(application, site) {
17
- const repoPath = path.join(process.cwd(), REPO_NAME);
18
- const deployConfigFilePath = path.join(repoPath, `dp/${site}/${application}.values.yaml`);
19
-
20
- console.log(`Cloning repository: ${REPO_NAME}`);
21
- await $`git clone ${REPO_URL}`;
22
- console.log(`Repository cloned to: ${repoPath}`);
23
-
24
- let deployConfig;
25
- try {
26
- deployConfig = yaml.load(fs.readFileSync(deployConfigFilePath, 'utf8'));
27
- console.log(`YAML file loaded from: ${deployConfigFilePath}`);
28
- } catch (error) {
29
- console.error(`Error reading YAML file: ${error.message}`);
30
- process.exit(1);
31
- }
32
-
33
- return { repoPath, deployConfigFilePath, deployConfig };
34
- }
35
-
36
- /**
37
- * Update the `tag` field in the YAML data.
38
- * @param {object} deployConfig - The parsed YAML data.
39
- * @param {string} tag - The new tag to set.
40
- * @returns {object} - The updated YAML data.
41
- */
42
- export function setTag(deployConfig, tag) {
43
- if (deployConfig.image && deployConfig.image.tag) {
44
- console.log(`Current image tag: ${deployConfig.image.tag}`);
45
- deployConfig.image.tag = tag;
46
- console.log(`Updated image tag to: ${deployConfig.image.tag}`);
47
- } else {
48
- console.error('No "image.tag" field found in the YAML file.');
49
- process.exit(1);
50
- }
51
- return deployConfig;
52
- }
53
-
54
- /**
55
- * Write the updated YAML data back to the file, commit the changes, and push to the remote branch.
56
- * @param {string} repoPath - The path to the cloned repository.
57
- * @param {string} deployConfigFilePath - The path to the YAML file.
58
- * @param {object} deployConfig - The updated YAML data.
59
- */
60
- export async function writeDeployConfig(repoPath, deployConfigFilePath, deployConfig) {
61
- try {
62
- fs.writeFileSync(deployConfigFilePath, yaml.dump(deployConfig), 'utf8');
63
- console.log(`Updated YAML file saved at: ${deployConfigFilePath}`);
64
- } catch (error) {
65
- console.error(`Error writing YAML file: ${error.message}`);
66
- process.exit(1);
67
- }
68
-
69
- console.log('Committing changes to the repository...');
70
- await $`cd ${repoPath} && git config user.email "gitops@docupace.com"`;
71
- await $`cd ${repoPath} && git add ${deployConfigFilePath}`;
72
- await $`cd ${repoPath} && git commit -m "Update image tag to ${deployConfig.image.tag}"`;
73
- await $`cd ${repoPath} && git push origin ${GITOPS_BRANCH}`;
74
- console.log('Changes pushed to the remote repository.');
75
-
76
- console.log('Cleaning up...');
77
- await $`rm -rf ${repoPath}`;
78
- console.log('Cleanup complete.');
79
- }
80
-
81
- /**
82
- * Main deploy function that orchestrates reading, updating, and writing the deployment config.
83
- * @param {string} application - The application name.
84
- * @param {string} site - The site name.
85
- */
86
-
87
- async function getDeployTag() {
88
- const gitTag = (await $`git tag --points-at HEAD | grep '^v' | head -n 1`).stdout.trim()
89
- const deployTag = gitTag || `build-${process.env.BITBUCKET_BUILD_NUMBER}`;
90
- return deployTag;
91
- }
92
-
93
- export async function deployTemplate(site) {
94
- const deployTag = await getDeployTag();
95
- console.log(`Deploying standard template for site: ${site}`);
96
- console.log(`Using deployment tag: ${deployTag}`);
97
- const { repoPath, deployConfigFilePath, deployConfig } = await readDeployConfig('graphql-server', site);
98
-
99
- deployConfig.graphqlServer.standardConfigRemoteBranch = deployTag;
100
-
101
- await writeDeployConfig(repoPath, deployConfigFilePath, deployConfig);
102
- console.log('Deployment completed successfully.');
103
-
104
- }
105
-
106
-
107
- export async function deploy(application, site) {
108
- const deployTag = getDeployTag();
109
-
110
- console.log(`Deploying application: ${application} for site: ${site}`);
111
- console.log(`Using deployment tag: ${deployTag}`);
112
-
113
- const { repoPath, deployConfigFilePath, deployConfig } = await readDeployConfig(application, site);
114
- const updatedConfigData = setTag(deployConfig, deployTag);
115
- await writeDeployConfig(repoPath, deployConfigFilePath, updatedConfigData);
116
-
117
- console.log('Deployment completed successfully.');
118
- }
@@ -1,46 +0,0 @@
1
- import { $ } from 'zx';
2
-
3
- export async function publish(GIT_SHA) {
4
- const BITBUCKET_REPO_SLUG = process.env.BITBUCKET_REPO_SLUG;
5
- const BUILD_IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:build-${process.env.BITBUCKET_BUILD_NUMBER}`;
6
- const IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
7
- const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
8
-
9
- console.log(`Publishing Docker image: ${IMAGE_NAME}`);
10
-
11
- // Docker login
12
- await $`echo ${process.env.JF_REGISTRY_PASSWORD_DEV} | docker login --username ${process.env.JF_REGISTRY_USER_DEV} --password-stdin ${process.env.JF_REGISTRY_URL}`;
13
-
14
- // Check if the image already exists
15
- try {
16
- await $`docker manifest inspect ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
17
- console.log(`Tag sha-${GIT_SHA} already exists in the remote repository. Skipping push.`);
18
- } catch {
19
- await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
20
- await $`docker push ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
21
- }
22
-
23
- // Tag and push build image
24
- await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
25
- await $`docker push ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
26
-
27
- // Fetch Git tags pointing to the current HEAD
28
- const gitTagsOutput = (await $`git tag --points-at HEAD`).stdout.trim();
29
- const gitTags = gitTagsOutput.split('\n').filter((tag) => tag);
30
-
31
- // Tag and push each Git tag as a Docker tag
32
- if (gitTags.length > 0) {
33
- console.log(`Found Git tags pointing to HEAD: ${gitTags.join(', ')}`);
34
- for (const gitTag of gitTags) {
35
- const dockerTag = `${JF_REGISTRY_FULL_URL}/${BITBUCKET_REPO_SLUG}:${gitTag}`;
36
- console.log(`Tagging and pushing Docker image for Git tag: ${gitTag}`);
37
- await $`docker tag ${IMAGE_NAME} ${dockerTag}`;
38
- await $`docker push ${dockerTag}`;
39
- }
40
- } else {
41
- console.log('No Git tags found pointing to the current HEAD.');
42
- }
43
-
44
- // Docker logout
45
- await $`docker logout ${process.env.JF_REGISTRY_URL}`;
46
- }
package/src/next/pull.js DELETED
@@ -1,7 +0,0 @@
1
- import { $ } from 'zx';
2
-
3
- export async function pull(imageName) {
4
- const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
5
- console.log(`Pulling Docker image: ${JF_REGISTRY_FULL_URL}/${imageName}`);
6
- await $`docker pull ${JF_REGISTRY_FULL_URL}/${imageName}`;
7
- }
package/src/next/sonar.js DELETED
@@ -1,23 +0,0 @@
1
- import { $ } from 'zx';
2
-
3
- export async function sonar(GIT_SHA) {
4
- const IMAGE_NAME = `${process.env.BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
5
- const SONAR_CONTAINER_NAME = `${process.env.BITBUCKET_REPO_SLUG}-${GIT_SHA}`;
6
-
7
- console.log(`Running Sonar analysis on Docker image: ${IMAGE_NAME}`);
8
-
9
- // Remove existing container
10
- const existingContainer = (
11
- await $`docker ps -a --filter "name=${SONAR_CONTAINER_NAME}" --format "{{.Names}}"`
12
- ).stdout.trim();
13
- if (existingContainer) {
14
- await $`docker rm -f ${SONAR_CONTAINER_NAME}`;
15
- }
16
-
17
- await $`docker run --rm \
18
- -e BRANCH=${process.env.BITBUCKET_BRANCH} \
19
- -e PR_ID=${process.env.BITBUCKET_PR_ID} \
20
- -e PR_DESTINATION_BRANCH=${process.env.BITBUCKET_PR_DESTINATION_BRANCH} \
21
- -e SONAR_TOKEN=${process.env.SONAR_TOKEN} \
22
- --name ${SONAR_CONTAINER_NAME} ${IMAGE_NAME} pnpm sonar`;
23
- }