forked from mekomsolutions/openmrs-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.js
133 lines (112 loc) · 3.81 KB
/
default.js
1
2
3
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"use strict";
const fs = require("fs");
const path = require("path");
const _ = require("lodash");
const log = require("npmlog");
const cst = require("../../const");
const model = require("../../utils/model");
const utils = require("../../utils/utils");
const cmns = require("../commons");
const config = require("../../utils/config");
const db = require(cst.DBPATH);
const thisType = "default";
module.exports = {
getInstance: function() {
var projectBuild = new model.ProjectBuild();
var ocd3Yaml = utils.convertYaml(config.getOCD3YamlFilePath());
projectBuild.getBuildScript = function() {
return getBuildScript(ocd3Yaml);
};
projectBuild.getDeployScript = function(artifact) {
return getDeployScript(artifact, ocd3Yaml);
};
projectBuild.getArtifact = function(args) {
if (!_.isEmpty(args.pom)) {
var artifact = cmns.getMavenProjectArtifact(args.pom, null, null);
return artifact;
} else {
var artifact = ocd3Yaml.deploy.artifact;
var _default = {
groupId: "net.mekomsolutions",
version: args.commitMetadata.branchName
? args.commitMetadata.branchName
: (artifact.version = args.commitMetadata.commitId),
artifactId: args.commitMetadata.repoName
};
artifact = { ..._default, ...artifact };
// encapsulating the Maven project
var mavenProject = new model.MavenProject();
mavenProject.groupId = artifact.groupId;
mavenProject.artifactId = artifact.artifactId;
mavenProject.version = artifact.version;
// 'packaging' is not needed in any further step. Dropping support.
mavenProject.packaging = null;
artifact.mavenProject = mavenProject;
return artifact;
}
};
projectBuild.postBuildActions = function(args) {
// Verify if a pom is provided (ie, is a Maven project)
if (!_.isEmpty(args.pom)) {
// Verify if "rebuildOnDependencyChanges" is set or not. If so, parse and save dependencies to later rebuild, when neeeded.
if (
!_.isEmpty(ocd3Yaml.rebuildOnDependencyChanges) &&
ocd3Yaml.rebuildOnDependencyChanges
) {
var artifactKey = utils.toArtifactKey(
args.pom.groupId,
args.pom.artifactId,
args.pom.version
);
// Saving/updating the list of dependencies in the database.
db.saveArtifactDependencies(
artifactKey,
utils.parseDependencies(args.pom)
);
// Keeping track of the params of the latest built job (so, the current one).
db.saveArtifactBuildParams(
artifactKey,
utils.getBuildParams(process.env, config)
);
}
cmns.mavenPostBuildActions(
args.pom.groupId,
args.artifactsIds,
args.pom.version
);
} else {
cmns.mavenPostBuildActions(
args.pseudoPom.groupId,
[args.pseudoPom.artifactId],
args.pseudoPom.version
);
}
};
return projectBuild;
}
};
var getBuildScript = function(ocd3Yaml) {
var script = new model.Script();
script.type = "#!/bin/bash";
script.body = ocd3Yaml.build.bash_commands;
script.headComment =
"# Custom build instructions provided in '.ocd3.yml' file.";
return script;
};
var getDeployScript = function(artifact, ocd3Yaml) {
if (_.isUndefined(artifact)) {
log.error(
"",
"An artifact parameter must be provided to construct the '" +
thisType +
"' deploy script."
);
throw new Error();
}
var script = new model.Script();
script.type = "#!/bin/bash";
script.body = ocd3Yaml.deploy.bash_commands;
script.headComment =
"# Custom deploy instructions provided in '.ocd3.yml' file.";
return script;
};