@seniorsistemas/semantic-release-maven-config 3.0.0 → 3.0.2

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.
Files changed (2) hide show
  1. package/index.js +135 -25
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,32 +1,142 @@
1
1
  const commonConfig = require("@seniorsistemas/semantic-release-common-config");
2
+ const https = require("https");
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { execSync, execFileSync } = require("child_process");
6
+
7
+ const NEXUS_BASE = "https://nexus.senior.com.br";
8
+ const SEARCH_PATH =
9
+ "/service/rest/v1/search/assets?repository=raw-hosted&name=*seniorops-linux-amd64*";
10
+ const BIN_DIR = path.join(__dirname, ".bin");
11
+ const BINARY_PATH = path.join(BIN_DIR, "seniorops");
12
+
13
+ function request(url, options = {}) {
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
+ }
2
74
 
3
75
  module.exports = {
4
76
  ...commonConfig,
5
- ...{
6
- plugins: [
7
- ...commonConfig.plugins,
8
- ...[
9
- [
10
- "@semantic-release/exec",
11
- {
12
- prepareCmd:
13
- "CI_COMMIT_TAG=${nextRelease.version} python3 senior-ci/src/main/generate.py && find . -type f -name 'pom.xml' -exec sed -i 's|nexus.senior.com.br/repository|maven.senior.com.br/artifactory|g' {} +",
14
- },
15
- ],
16
- [
17
- "@semantic-release/git",
18
- {
19
- assets: [
20
- "sdl.properties",
21
- "**/**/pom.xml",
22
- "**/**/feature.xml",
23
- "**/**/category.xml",
24
- "**/**/MANIFEST.MF",
25
- ],
26
- message: ":pencil2: chore: bump ${nextRelease.version}",
27
- },
77
+ plugins: [
78
+ ...commonConfig.plugins,
79
+ {
80
+ prepare: async (_, { nextRelease, logger }) => {
81
+ await setupSeniorops();
82
+ const { ECOSYSTEM, TYPE } = process.env;
83
+ if (!ECOSYSTEM || !TYPE) {
84
+ throw new Error("ECOSYSTEM and TYPE environment variables are required");
85
+ }
86
+
87
+ logger.log("Running: seniorops generate --ecosystem %s --type %s", ECOSYSTEM, TYPE);
88
+ try {
89
+ const generateOutput = execFileSync(
90
+ BINARY_PATH,
91
+ ["generate"],
92
+ {
93
+ env: { ...process.env, ECOSYSTEM, TYPE, GITHUB_REF_NAME: nextRelease.version, GITHUB_REF: `refs/tags/${nextRelease.version}`, GITHUB_REF_TYPE: "tag" },
94
+ stdio: "pipe",
95
+ }
96
+ );
97
+ if (generateOutput && generateOutput.length) {
98
+ logger.log("seniorops output:\n%s", generateOutput.toString());
99
+ }
100
+ } catch (err) {
101
+ const stdout = err.stdout ? err.stdout.toString() : "";
102
+ const stderr = err.stderr ? err.stderr.toString() : "";
103
+ logger.error("seniorops generate failed (exit code %d)", err.status);
104
+ if (stdout) logger.error("stdout:\n%s", stdout);
105
+ if (stderr) logger.error("stderr:\n%s", stderr);
106
+ throw err;
107
+ }
108
+
109
+ logger.log("Replacing Nexus URLs in pom.xml files");
110
+ try {
111
+ const sedOutput = execSync(
112
+ "find . -type f -name 'pom.xml' -exec sed -i 's|nexus.senior.com.br/repository|maven.senior.com.br/artifactory|g' {} +",
113
+ { stdio: "pipe" }
114
+ );
115
+ if (sedOutput && sedOutput.length) {
116
+ logger.log("sed output:\n%s", sedOutput.toString());
117
+ }
118
+ } catch (err) {
119
+ const stdout = err.stdout ? err.stdout.toString() : "";
120
+ const stderr = err.stderr ? err.stderr.toString() : "";
121
+ logger.error("pom.xml URL replacement failed (exit code %d)", err.status);
122
+ if (stdout) logger.error("stdout:\n%s", stdout);
123
+ if (stderr) logger.error("stderr:\n%s", stderr);
124
+ throw err;
125
+ }
126
+ },
127
+ },
128
+ [
129
+ "@semantic-release/git",
130
+ {
131
+ assets: [
132
+ "sdl.properties",
133
+ "**/**/pom.xml",
134
+ "**/**/feature.xml",
135
+ "**/**/category.xml",
136
+ "**/**/MANIFEST.MF",
28
137
  ],
29
- ],
138
+ message: ":pencil2: chore: bump ${nextRelease.version}",
139
+ },
30
140
  ],
31
- },
141
+ ],
32
142
  };
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.0",
4
+ "version": "3.0.2",
5
5
  "main": "index.js",
6
6
  "files": [
7
7
  "index.js"