@seniorsistemas/semantic-release-maven-config 3.0.4 → 3.0.5
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/index.js +12 -79
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,96 +1,29 @@
|
|
|
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
2
|
const { execSync, spawn } = require("child_process");
|
|
6
3
|
|
|
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
|
-
}
|
|
74
|
-
|
|
75
4
|
module.exports = {
|
|
76
5
|
...commonConfig,
|
|
77
6
|
plugins: [
|
|
78
7
|
...commonConfig.plugins,
|
|
79
8
|
{
|
|
80
9
|
prepare: async (_, { nextRelease, logger }) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
throw new Error("ECOSYSTEM and TYPE environment variables are required");
|
|
10
|
+
const { SOPS_ECOSYSTEM, SOPS_TYPE } = process.env;
|
|
11
|
+
if (!SOPS_ECOSYSTEM || !SOPS_TYPE) {
|
|
12
|
+
throw new Error("SOPS_ECOSYSTEM and SOPS_TYPE environment variables are required");
|
|
85
13
|
}
|
|
86
14
|
|
|
87
|
-
logger.log("Running: seniorops generate
|
|
15
|
+
logger.log("Running: seniorops generate (ecosystem=%s, type=%s)", SOPS_ECOSYSTEM, SOPS_TYPE);
|
|
88
16
|
await new Promise((resolve, reject) => {
|
|
89
17
|
const child = spawn(
|
|
90
|
-
|
|
91
|
-
["generate"
|
|
18
|
+
"seniorops",
|
|
19
|
+
["generate"],
|
|
92
20
|
{
|
|
93
|
-
env: {
|
|
21
|
+
env: {
|
|
22
|
+
...process.env,
|
|
23
|
+
GITHUB_REF_NAME: nextRelease.version,
|
|
24
|
+
GITHUB_REF: `refs/tags/${nextRelease.version}`,
|
|
25
|
+
GITHUB_REF_TYPE: "tag",
|
|
26
|
+
},
|
|
94
27
|
}
|
|
95
28
|
);
|
|
96
29
|
child.stdout.on("data", (data) => logger.log(data.toString()));
|
package/package.json
CHANGED