@docupace/pipeline 1.0.110 → 1.0.112

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @docupace/pipeline
2
2
 
3
+ ## 1.0.112
4
+
5
+ ### Patch Changes
6
+
7
+ - 30d5209: Added to install latest
8
+ - 664ac05: Fix to build
9
+ - e738539: Add deploy for specific version from pipeline
10
+
11
+ ## 1.0.111
12
+
13
+ ### Patch Changes
14
+
15
+ - 471bab7: Fix pipeline
16
+
3
17
  ## 1.0.110
4
18
 
5
19
  ### Patch Changes
@@ -16,7 +16,7 @@ definitions:
16
16
  - npm config set //registry.npmjs.org/:_authToken $DOCUPACE_NPM_TOKEN
17
17
  - pnpm install --frozen-lockfile
18
18
  - export HOME=/tmp
19
- - node src/changeset/cli.js version-commit-tag
19
+ - node src/changeset/cli.js version-commit-tag --install-latest
20
20
 
21
21
  pipelines:
22
22
  pull-requests:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.110",
3
+ "version": "1.0.112",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -148,9 +148,13 @@ program
148
148
  program
149
149
  .command('version-commit-tag')
150
150
  .description('Run versioning and commit-and-tag in sequence')
151
- .action(async () => {
151
+ .option(
152
+ '--install-latest',
153
+ 'Install the latest version of @docupace/pipeline instead of the current version',
154
+ )
155
+ .action(async (options) => {
152
156
  console.log('📦 Running all steps...');
153
- const releases = await versionCommand();
157
+ const releases = await versionCommand(false, options.installLatest);
154
158
  await updateJiraWithVersion(releases);
155
159
  await updateWikiWithVersion(releases);
156
160
  await commitTagCommand(releases);
@@ -15,7 +15,7 @@ const getPackageVersion = () => {
15
15
  return packageJson.version;
16
16
  };
17
17
 
18
- const changeSetPackage = `{
18
+ const getChangeSetPackage = (installLatest = false) => `{
19
19
  "name": "changeset-package",
20
20
  "version": "1.0.0",
21
21
  "description": "",
@@ -28,7 +28,7 @@ const changeSetPackage = `{
28
28
  "dependencies": {},
29
29
  "devDependencies": {
30
30
  "@changesets/cli": "^2.27.10",
31
- "@docupace/pipeline": "${getPackageVersion()}"
31
+ "@docupace/pipeline": "${installLatest ? 'latest' : getPackageVersion()}"
32
32
  }
33
33
  }
34
34
  `;
@@ -65,13 +65,19 @@ export async function versionStatus(sinceBranch) {
65
65
  return jsonOutput.releases;
66
66
  }
67
67
 
68
- export async function versionCommand(closeVersion = false) {
68
+ export async function versionCommand(
69
+ closeVersion = false,
70
+ installLatest = false,
71
+ ) {
69
72
  console.log('📦 Running Changeset versioning...');
70
73
  if (!process.env.IS_DEV) {
71
74
  await setGitInfo();
72
75
  await $`mv package.json package.json.bak`;
73
76
  await $`mv pnpm-lock.yaml pnpm-lock.yaml.bak`;
74
- await fs.promises.writeFile('package.json', changeSetPackage);
77
+ await fs.promises.writeFile(
78
+ 'package.json',
79
+ getChangeSetPackage(installLatest),
80
+ );
75
81
  await $`npm config set //registry.npmjs.org/:_authToken ${process.env.DOCUPACE_NPM_TOKEN}`;
76
82
  await $`pnpm install`;
77
83
  await $`rm package.json pnpm-lock.yaml`;
package/src/next/cli.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  deployTemplate,
11
11
  getDefaultDeploySite,
12
12
  getDeployTag,
13
+ updateSiteVersion,
13
14
  } from './deploy.js';
14
15
  import { copy2 } from './copy.js';
15
16
  import { vaultAddSiteData } from './vault.js';
@@ -113,6 +114,31 @@ program
113
114
  );
114
115
  });
115
116
 
117
+ program
118
+ .command('update-site-version <env> <site>')
119
+ .description('Update specific version components for a site')
120
+ .option('-u, --ui-version <uiVersion>', 'UI image tag')
121
+ .option('-g, --graph-version <graphVersion>', 'Graphql-server image tag')
122
+ .option(
123
+ '-S, --standard-config <standardConfig>',
124
+ 'Standard config remote branch',
125
+ )
126
+ .option('-s, --site-config <siteConfig>', 'Site config remote branch')
127
+ .option('-j, --jira-ticket [jiraTicket]', 'JIRA ticket (required for prod)')
128
+ .action(async (env, site, options) => {
129
+ const { uiVersion, graphVersion, standardConfig, siteConfig, jiraTicket } =
130
+ options;
131
+ await updateSiteVersion(
132
+ env,
133
+ site,
134
+ uiVersion,
135
+ graphVersion,
136
+ standardConfig,
137
+ siteConfig,
138
+ jiraTicket,
139
+ );
140
+ });
141
+
116
142
  program
117
143
  .command('deploy-template [tagPrefix]')
118
144
  .description('Deploy an standard configuration for configured sites')
@@ -777,6 +777,258 @@ async function validateDeployVersionConsistency(env, site, deployedApps) {
777
777
  `✅ Version consistency validated for ${env}/${site}: all ${appVersions.length} component(s) aligned on ${uniqueMajorMinors[0] ?? 'n/a'}`,
778
778
  );
779
779
  }
780
+ export async function updateSiteVersion(
781
+ env,
782
+ site,
783
+ uiVersion,
784
+ graphVersion,
785
+ standardConfig,
786
+ siteConfig,
787
+ jiraTicket,
788
+ ) {
789
+ if (!uiVersion && !graphVersion && !standardConfig && !siteConfig) {
790
+ console.error(
791
+ '❌ At least one of --ui-version, --graph-version, --standard-config, or --site-config must be provided',
792
+ );
793
+ process.exit(1);
794
+ }
795
+
796
+ console.log(
797
+ `Updating site versions for ${env}/${site}${jiraTicket ? ` approved by JIRA ticket ${jiraTicket}` : ''}`,
798
+ );
799
+
800
+ if (env === 'prod') {
801
+ if (!jiraTicket) {
802
+ console.error(
803
+ 'The deployment to prod environment requires a JIRA ticket to be provided',
804
+ );
805
+ process.exit(1);
806
+ }
807
+
808
+ try {
809
+ const response = await makeJiraRequest(`/rest/api/2/issue/${jiraTicket}`);
810
+ const docupacecInstance = response.fields.customfield_10045.value;
811
+ const siteUrl = response.fields.customfield_10041;
812
+ const status = response.fields.status.name;
813
+ const jiraBaseUrl = response.self.split('/rest/api')[0];
814
+ const jiraTicketUrl = `${jiraBaseUrl}/browse/${response.key}`;
815
+
816
+ console.log(`Docupace Instance: ${docupacecInstance}`);
817
+ console.log(`Docupace Site URL: ${siteUrl}`);
818
+ console.log(`JIRA Ticket Status: ${status}`);
819
+ console.log(`JIRA Ticket URL: ${jiraTicketUrl}`);
820
+
821
+ const allowedStatuses = ['To Do', 'In Progress', 'In Deployment'];
822
+ if (!allowedStatuses.includes(status)) {
823
+ console.error(
824
+ `The JIRA ticket status must be "To Do" or "In Progress" or "In Deployment", but got "${status}"`,
825
+ );
826
+ console.error(`Please check the JIRA ticket: ${jiraTicketUrl}`);
827
+ process.exit(1);
828
+ }
829
+
830
+ if (!siteUrl.includes(site)) {
831
+ console.error(
832
+ `The site "${site}" must be present in the Docupace Site URL: "${siteUrl}"`,
833
+ );
834
+ console.error(`Please check the JIRA ticket: ${jiraTicketUrl}`);
835
+ process.exit(1);
836
+ }
837
+
838
+ if (docupacecInstance !== 'Production') {
839
+ console.error(
840
+ `The deployment to prod environment requires Docupace Instance to be "Production", but got "${docupacecInstance}"`,
841
+ );
842
+ console.error(`Please check the JIRA ticket: ${jiraTicketUrl}`);
843
+ process.exit(1);
844
+ }
845
+
846
+ console.log('Production deployment validations passed');
847
+ } catch (error) {
848
+ console.error(`Failed to make a Jira request: ${error.message}`);
849
+ process.exit(1);
850
+ }
851
+ } else if (jiraTicket) {
852
+ try {
853
+ const response = await makeJiraRequest(`/rest/api/2/issue/${jiraTicket}`);
854
+ const siteUrl = response.fields.customfield_10041;
855
+ const status = response.fields.status.name;
856
+ const jiraBaseUrl = response.self.split('/rest/api')[0];
857
+ const jiraTicketUrl = `${jiraBaseUrl}/browse/${response.key}`;
858
+
859
+ console.log(`Docupace Site URL: ${siteUrl}`);
860
+ console.log(`JIRA Ticket Status: ${status}`);
861
+ console.log(`JIRA Ticket URL: ${jiraTicketUrl}`);
862
+
863
+ const allowedStatuses = ['To Do', 'In Progress', 'In Deployment'];
864
+ if (!allowedStatuses.includes(status)) {
865
+ console.error(
866
+ `The JIRA ticket status must be "To Do" or "In Progress" or "In Deployment", but got "${status}"`,
867
+ );
868
+ console.error(`Please check the JIRA ticket: ${jiraTicketUrl}`);
869
+ process.exit(1);
870
+ }
871
+
872
+ if (!siteUrl.includes(site)) {
873
+ console.error(
874
+ `The site "${site}" must be present in the Docupace Site URL: "${siteUrl}"`,
875
+ );
876
+ console.error(`Please check the JIRA ticket: ${jiraTicketUrl}`);
877
+ process.exit(1);
878
+ }
879
+ } catch (error) {
880
+ console.error(`Failed to make a Jira request: ${error.message}`);
881
+ process.exit(1);
882
+ }
883
+ }
884
+
885
+ const toRepoPath = await cloneEnvRepository(env);
886
+
887
+ if (env !== 'dev') {
888
+ await cloneEnvRepository('dev');
889
+ }
890
+
891
+ let changesMade = false;
892
+ let oldVersion = null;
893
+ let newVersion = null;
894
+
895
+ if (uiVersion) {
896
+ const uiAppDetails = appInfo['ui'];
897
+
898
+ if (env !== 'dev') {
899
+ await copy2(
900
+ uiAppDetails.repositoryName,
901
+ 'dev',
902
+ env,
903
+ uiVersion,
904
+ uiAppDetails.imageName,
905
+ );
906
+ }
907
+
908
+ const { deployConfig, deployConfigFilePath } = await readDeployConfig(
909
+ 'ui',
910
+ env,
911
+ site,
912
+ 'values',
913
+ );
914
+ if (deployConfig) {
915
+ if (!oldVersion) oldVersion = deployConfig.image?.tag;
916
+ newVersion = uiVersion;
917
+
918
+ deployConfig.image.tag = uiVersion;
919
+
920
+ if (uiAppDetails.updateConfigFunction) {
921
+ uiAppDetails.updateConfigFunction(deployConfig);
922
+ }
923
+
924
+ const { deployConfig: appConfig, deployConfigFilePath: appFilePath } =
925
+ await readDeployConfig('ui', env, site, 'app');
926
+ if (appConfig) {
927
+ appConfig.revision = uiAppDetails.getAppRevision
928
+ ? uiAppDetails.getAppRevision(deployConfig)
929
+ : deployConfig.image.tag;
930
+ writeDeployConfig(appFilePath, appConfig);
931
+ }
932
+
933
+ writeDeployConfig(deployConfigFilePath, deployConfig);
934
+ changesMade = true;
935
+ }
936
+ }
937
+
938
+ if (graphVersion || standardConfig || siteConfig) {
939
+ const { deployConfig, deployConfigFilePath } = await readDeployConfig(
940
+ 'graphql-server',
941
+ env,
942
+ site,
943
+ 'values',
944
+ );
945
+ if (deployConfig) {
946
+ if (graphVersion) {
947
+ const gsAppDetails = appInfo['graphql-server'];
948
+
949
+ if (env !== 'dev') {
950
+ await copy2(
951
+ gsAppDetails.repositoryName,
952
+ 'dev',
953
+ env,
954
+ graphVersion,
955
+ gsAppDetails.imageName,
956
+ );
957
+ }
958
+
959
+ if (!oldVersion) oldVersion = deployConfig.image?.tag;
960
+ if (!newVersion) newVersion = graphVersion;
961
+
962
+ deployConfig.image.tag = graphVersion;
963
+
964
+ const { deployConfig: appConfig, deployConfigFilePath: appFilePath } =
965
+ await readDeployConfig('graphql-server', env, site, 'app');
966
+ if (appConfig) {
967
+ appConfig.revision = graphVersion;
968
+ writeDeployConfig(appFilePath, appConfig);
969
+ }
970
+ }
971
+
972
+ if (standardConfig) {
973
+ deployConfig.graphqlServer = deployConfig.graphqlServer ?? {};
974
+ deployConfig.graphqlServer.standardConfigRemoteBranch = standardConfig;
975
+ }
976
+
977
+ if (siteConfig) {
978
+ deployConfig.graphqlServer = deployConfig.graphqlServer ?? {};
979
+ deployConfig.graphqlServer.siteConfigRemoteBranch = siteConfig;
980
+ }
981
+
982
+ writeDeployConfig(deployConfigFilePath, deployConfig);
983
+ changesMade = true;
984
+ }
985
+ }
986
+
987
+ let autoDeployUpdated = false;
988
+ if (oldVersion && newVersion && oldVersion !== newVersion) {
989
+ autoDeployUpdated = await updateAutoDeployVersion(
990
+ env,
991
+ env,
992
+ site,
993
+ oldVersion,
994
+ newVersion,
995
+ );
996
+ if (autoDeployUpdated) {
997
+ console.log(
998
+ `Info: auto-deploy.yaml updated for ${env}/${site}: ${oldVersion} → ${newVersion}`,
999
+ );
1000
+ changesMade = true;
1001
+ }
1002
+ }
1003
+
1004
+ if (changesMade) {
1005
+ const { applications } = getAppTypesFromRepo(env, site);
1006
+ const deployedApps = Object.fromEntries(
1007
+ applications
1008
+ .filter((app) => Object.prototype.hasOwnProperty.call(appInfo, app))
1009
+ .map((app) => [app, appInfo[app]]),
1010
+ );
1011
+ await validateDeployVersionConsistency(env, site, deployedApps);
1012
+
1013
+ await pushDeployConfig(
1014
+ toRepoPath,
1015
+ `Update site versions for ${env}/${site}`,
1016
+ );
1017
+
1018
+ if (autoDeployUpdated && env !== 'dev') {
1019
+ const { repoPath: devRepoPath } = getRepoLocalPath('dev');
1020
+ await pushDeployConfig(
1021
+ devRepoPath,
1022
+ `Update auto-deploy version for ${env}/${site}`,
1023
+ );
1024
+ }
1025
+
1026
+ console.log('All configurations updated and pushed successfully.');
1027
+ } else {
1028
+ console.log('No changes detected. Nothing to push.');
1029
+ }
1030
+ }
1031
+
780
1032
  export async function deployFromSite(
781
1033
  fromEnv,
782
1034
  fromSite,