@seniorsistemas/semantic-release-maven-config 2.2.6 → 3.0.1

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 +99 -25
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -1,32 +1,106 @@
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 }) => {
81
+ await setupSeniorops();
82
+ execFileSync(BINARY_PATH, ["generate"], {
83
+ env: { ...process.env, GITHUB_REF_NAME: nextRelease.version, GITHUB_REF: `refs/tags/${nextRelease.version}`, GITHUB_REF_TYPE: "tag" },
84
+ stdio: "inherit",
85
+ });
86
+ execSync(
87
+ "find . -type f -name 'pom.xml' -exec sed -i 's|nexus.senior.com.br/repository|maven.senior.com.br/artifactory|g' {} +",
88
+ { stdio: "inherit" }
89
+ );
90
+ },
91
+ },
92
+ [
93
+ "@semantic-release/git",
94
+ {
95
+ assets: [
96
+ "sdl.properties",
97
+ "**/**/pom.xml",
98
+ "**/**/feature.xml",
99
+ "**/**/category.xml",
100
+ "**/**/MANIFEST.MF",
28
101
  ],
29
- ],
102
+ message: ":pencil2: chore: bump ${nextRelease.version}",
103
+ },
30
104
  ],
31
- },
105
+ ],
32
106
  };
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": "2.2.6",
4
+ "version": "3.0.1",
5
5
  "main": "index.js",
6
6
  "files": [
7
7
  "index.js"
@@ -22,12 +22,12 @@
22
22
  "@semantic-release/exec": "^6.0.3",
23
23
  "@semantic-release/git": "^10.0.1",
24
24
  "@semantic-release/gitlab": "13.3.0",
25
- "@seniorsistemas/semantic-release-common-config": "1.10.6",
25
+ "@seniorsistemas/semantic-release-common-config": "^2.0.0",
26
26
  "conventional-changelog-gitmoji-config": "^1.5.2",
27
27
  "semantic-release-jira-notes": "4.0.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@seniorsistemas/semantic-release-npm-config": "^1.0.3",
30
+ "@seniorsistemas/semantic-release-npm-config": "^2.0.0",
31
31
  "prettier": "3.2.5"
32
32
  },
33
33
  "overrides": {