@seniorsistemas/semantic-release-maven-config 3.0.4 → 3.1.0
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 +0 -1
- package/index.js +106 -97
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -12,7 +12,6 @@ This shareable configuration use the following plugins:
|
|
|
12
12
|
- [`@semantic-release/commit-analyzer`](https://github.com/semantic-release/commit-analyzer)
|
|
13
13
|
- [`semantic-release-jira-notes`](https://github.com/iamludal/semantic-release-jira-notes)
|
|
14
14
|
- [`@semantic-release/exec`](https://github.com/semantic-release/exec)
|
|
15
|
-
- [`@semantic-release/git`](https://github.com/semantic-release/git)
|
|
16
15
|
- [`@semantic-release/gitlab`](https://github.com/semantic-release/gitlab)
|
|
17
16
|
|
|
18
17
|
## Options
|
package/index.js
CHANGED
|
@@ -1,76 +1,15 @@
|
|
|
1
1
|
const commonConfig = require("@seniorsistemas/semantic-release-common-config");
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const { execSync, spawn } = require("child_process");
|
|
2
|
+
const { execSync, execFileSync, spawn } = require("child_process");
|
|
3
|
+
const { readFileSync } = require("fs");
|
|
4
|
+
const { join } = require("path");
|
|
6
5
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
const req = https.get(url, options, (res) => {
|
|
16
|
-
if (
|
|
17
|
-
res.statusCode >= 301 &&
|
|
18
|
-
res.statusCode <= 303 &&
|
|
19
|
-
res.headers.location
|
|
20
|
-
) {
|
|
21
|
-
resolve(request(res.headers.location, options));
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (res.statusCode !== 200) {
|
|
25
|
-
reject(new Error(`HTTP ${res.statusCode} for ${url}`));
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const chunks = [];
|
|
29
|
-
res.on("data", (chunk) => chunks.push(chunk));
|
|
30
|
-
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
31
|
-
res.on("error", reject);
|
|
32
|
-
});
|
|
33
|
-
req.on("error", reject);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function setupSeniorops() {
|
|
38
|
-
const { NEXUS_USERNAME, NEXUS_PASSWORD } = process.env;
|
|
39
|
-
if (!NEXUS_USERNAME || !NEXUS_PASSWORD) {
|
|
40
|
-
throw new Error(
|
|
41
|
-
"NEXUS_USERNAME and NEXUS_PASSWORD environment variables are required"
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const auth = `Basic ${Buffer.from(`${NEXUS_USERNAME}:${NEXUS_PASSWORD}`).toString("base64")}`;
|
|
46
|
-
const headers = { Authorization: auth };
|
|
47
|
-
|
|
48
|
-
const searchData = await request(`${NEXUS_BASE}${SEARCH_PATH}`, { headers });
|
|
49
|
-
const { items } = JSON.parse(searchData.toString());
|
|
50
|
-
const asset = items
|
|
51
|
-
.sort((a, b) => new Date(a.lastModified) - new Date(b.lastModified))
|
|
52
|
-
.pop();
|
|
53
|
-
|
|
54
|
-
const version = asset.path.split("/").find((p) => p.startsWith("v"));
|
|
55
|
-
const cacheMarker = path.join(BIN_DIR, ".seniorops-version");
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
fs.existsSync(BINARY_PATH) &&
|
|
59
|
-
fs.existsSync(cacheMarker) &&
|
|
60
|
-
fs.readFileSync(cacheMarker, "utf8").trim() === version
|
|
61
|
-
) {
|
|
62
|
-
console.log(`SeniorOps ${version} already cached at ${BINARY_PATH}`);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.log(`Downloading SeniorOps ${version} from ${asset.downloadUrl}`);
|
|
67
|
-
const binary = await request(asset.downloadUrl, { headers });
|
|
68
|
-
|
|
69
|
-
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
70
|
-
fs.writeFileSync(BINARY_PATH, binary, { mode: 0o755 });
|
|
71
|
-
fs.writeFileSync(cacheMarker, version, "utf8");
|
|
72
|
-
console.log(`SeniorOps ${version} installed at ${BINARY_PATH}`);
|
|
73
|
-
}
|
|
6
|
+
const RELEASE_ASSETS = [
|
|
7
|
+
"sdl.properties",
|
|
8
|
+
"**/pom.xml",
|
|
9
|
+
"**/feature.xml",
|
|
10
|
+
"**/category.xml",
|
|
11
|
+
"**/MANIFEST.MF",
|
|
12
|
+
];
|
|
74
13
|
|
|
75
14
|
module.exports = {
|
|
76
15
|
...commonConfig,
|
|
@@ -78,21 +17,27 @@ module.exports = {
|
|
|
78
17
|
...commonConfig.plugins,
|
|
79
18
|
{
|
|
80
19
|
prepare: async (_, { nextRelease, logger }) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
20
|
+
const { SOPS_ECOSYSTEM, SOPS_TYPE } = process.env;
|
|
21
|
+
if (!SOPS_ECOSYSTEM || !SOPS_TYPE) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
"SOPS_ECOSYSTEM and SOPS_TYPE environment variables are required",
|
|
24
|
+
);
|
|
85
25
|
}
|
|
86
26
|
|
|
87
|
-
logger.log(
|
|
27
|
+
logger.log(
|
|
28
|
+
"Running: seniorops generate (ecosystem=%s, type=%s)",
|
|
29
|
+
SOPS_ECOSYSTEM,
|
|
30
|
+
SOPS_TYPE,
|
|
31
|
+
);
|
|
88
32
|
await new Promise((resolve, reject) => {
|
|
89
|
-
const child = spawn(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
33
|
+
const child = spawn("seniorops", ["generate"], {
|
|
34
|
+
env: {
|
|
35
|
+
...process.env,
|
|
36
|
+
GITHUB_REF_NAME: nextRelease.version,
|
|
37
|
+
GITHUB_REF: `refs/tags/${nextRelease.version}`,
|
|
38
|
+
GITHUB_REF_TYPE: "tag",
|
|
39
|
+
},
|
|
40
|
+
});
|
|
96
41
|
child.stdout.on("data", (data) => logger.log(data.toString()));
|
|
97
42
|
child.stderr.on("data", (data) => logger.error(data.toString()));
|
|
98
43
|
child.on("error", reject);
|
|
@@ -109,7 +54,7 @@ module.exports = {
|
|
|
109
54
|
try {
|
|
110
55
|
const sedOutput = execSync(
|
|
111
56
|
"find . -type f -name 'pom.xml' -exec sed -i 's|nexus.senior.com.br/repository|maven.senior.com.br/artifactory|g' {} +",
|
|
112
|
-
{ stdio: "pipe" }
|
|
57
|
+
{ stdio: "pipe" },
|
|
113
58
|
);
|
|
114
59
|
if (sedOutput && sedOutput.length) {
|
|
115
60
|
logger.log("sed output:\n%s", sedOutput.toString());
|
|
@@ -117,25 +62,89 @@ module.exports = {
|
|
|
117
62
|
} catch (err) {
|
|
118
63
|
const stdout = err.stdout ? err.stdout.toString() : "";
|
|
119
64
|
const stderr = err.stderr ? err.stderr.toString() : "";
|
|
120
|
-
logger.error(
|
|
65
|
+
logger.error(
|
|
66
|
+
"pom.xml URL replacement failed (exit code %d)",
|
|
67
|
+
err.status,
|
|
68
|
+
);
|
|
121
69
|
if (stdout) logger.error("stdout:\n%s", stdout);
|
|
122
70
|
if (stderr) logger.error("stderr:\n%s", stderr);
|
|
123
71
|
throw err;
|
|
124
72
|
}
|
|
125
73
|
},
|
|
126
74
|
},
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
"
|
|
136
|
-
|
|
137
|
-
|
|
75
|
+
{
|
|
76
|
+
// Replaces @semantic-release/git: that plugin runs a local `git commit`, which is
|
|
77
|
+
// never signed. createCommitOnBranch makes GitHub sign the commit (Verified).
|
|
78
|
+
prepare: async (
|
|
79
|
+
_,
|
|
80
|
+
{ nextRelease, branch, options, env, cwd, logger },
|
|
81
|
+
) => {
|
|
82
|
+
const git = (...args) =>
|
|
83
|
+
execFileSync("git", args, { cwd, env, encoding: "utf8" }).trim();
|
|
84
|
+
const files = git(
|
|
85
|
+
"ls-files",
|
|
86
|
+
"-m",
|
|
87
|
+
"-z",
|
|
88
|
+
"--",
|
|
89
|
+
...RELEASE_ASSETS.map((a) => `:(glob)${a}`),
|
|
90
|
+
)
|
|
91
|
+
.split("\0")
|
|
92
|
+
.filter(Boolean);
|
|
93
|
+
if (files.length === 0) return;
|
|
94
|
+
|
|
95
|
+
const token = env.GITHUB_TOKEN;
|
|
96
|
+
if (!token || !env.GITHUB_REPOSITORY) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
"GITHUB_TOKEN and GITHUB_REPOSITORY are required to create the signed release commit",
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const message = `:pencil2: chore: bump ${nextRelease.version}`;
|
|
103
|
+
const response = await fetch("https://api.github.com/graphql", {
|
|
104
|
+
method: "POST",
|
|
105
|
+
headers: {
|
|
106
|
+
Authorization: `Bearer ${token}`,
|
|
107
|
+
"Content-Type": "application/json",
|
|
108
|
+
},
|
|
109
|
+
body: JSON.stringify({
|
|
110
|
+
query: `mutation($input: CreateCommitOnBranchInput!) {
|
|
111
|
+
createCommitOnBranch(input: $input) { commit { oid } }
|
|
112
|
+
}`,
|
|
113
|
+
variables: {
|
|
114
|
+
input: {
|
|
115
|
+
branch: {
|
|
116
|
+
repositoryNameWithOwner: env.GITHUB_REPOSITORY,
|
|
117
|
+
branchName: branch.name,
|
|
118
|
+
},
|
|
119
|
+
message: { headline: message },
|
|
120
|
+
expectedHeadOid: git("rev-parse", "HEAD"),
|
|
121
|
+
fileChanges: {
|
|
122
|
+
additions: files.map((path) => ({
|
|
123
|
+
path,
|
|
124
|
+
contents: readFileSync(join(cwd, path)).toString("base64"),
|
|
125
|
+
})),
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
}),
|
|
130
|
+
});
|
|
131
|
+
const body = await response.json();
|
|
132
|
+
if (!response.ok || body.errors) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`createCommitOnBranch failed: ${JSON.stringify(body.errors || body)}`,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// The new commit exists only on the remote; sync so the tag push that
|
|
139
|
+
// semantic-release runs next is not behind it.
|
|
140
|
+
git("fetch", options.repositoryUrl, branch.name);
|
|
141
|
+
git("reset", "--hard", "FETCH_HEAD");
|
|
142
|
+
logger.log(
|
|
143
|
+
"Created signed release commit %s: %s",
|
|
144
|
+
body.data.createCommitOnBranch.commit.oid,
|
|
145
|
+
message,
|
|
146
|
+
);
|
|
138
147
|
},
|
|
139
|
-
|
|
148
|
+
},
|
|
140
149
|
],
|
|
141
150
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seniorsistemas/semantic-release-maven-config",
|
|
3
3
|
"description": "semantic-release shareable config to create maven packages with Senior GitLab",
|
|
4
|
-
"version": "3.0
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"index.js"
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@semantic-release/exec": "^6.0.3",
|
|
23
|
-
"@semantic-release/git": "^10.0.1",
|
|
24
23
|
"@semantic-release/gitlab": "13.3.0",
|
|
25
24
|
"@seniorsistemas/semantic-release-common-config": "^2.0.0",
|
|
26
25
|
"conventional-changelog-gitmoji-config": "^1.5.2",
|