@seniorsistemas/semantic-release-maven-config 3.0.5 → 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.
Files changed (3) hide show
  1. package/README.md +0 -1
  2. package/index.js +105 -29
  3. 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,5 +1,15 @@
1
1
  const commonConfig = require("@seniorsistemas/semantic-release-common-config");
2
- const { execSync, spawn } = require("child_process");
2
+ const { execSync, execFileSync, spawn } = require("child_process");
3
+ const { readFileSync } = require("fs");
4
+ const { join } = require("path");
5
+
6
+ const RELEASE_ASSETS = [
7
+ "sdl.properties",
8
+ "**/pom.xml",
9
+ "**/feature.xml",
10
+ "**/category.xml",
11
+ "**/MANIFEST.MF",
12
+ ];
3
13
 
4
14
  module.exports = {
5
15
  ...commonConfig,
@@ -9,23 +19,25 @@ module.exports = {
9
19
  prepare: async (_, { nextRelease, logger }) => {
10
20
  const { SOPS_ECOSYSTEM, SOPS_TYPE } = process.env;
11
21
  if (!SOPS_ECOSYSTEM || !SOPS_TYPE) {
12
- throw new Error("SOPS_ECOSYSTEM and SOPS_TYPE environment variables are required");
22
+ throw new Error(
23
+ "SOPS_ECOSYSTEM and SOPS_TYPE environment variables are required",
24
+ );
13
25
  }
14
26
 
15
- logger.log("Running: seniorops generate (ecosystem=%s, type=%s)", SOPS_ECOSYSTEM, SOPS_TYPE);
27
+ logger.log(
28
+ "Running: seniorops generate (ecosystem=%s, type=%s)",
29
+ SOPS_ECOSYSTEM,
30
+ SOPS_TYPE,
31
+ );
16
32
  await new Promise((resolve, reject) => {
17
- const child = spawn(
18
- "seniorops",
19
- ["generate"],
20
- {
21
- env: {
22
- ...process.env,
23
- GITHUB_REF_NAME: nextRelease.version,
24
- GITHUB_REF: `refs/tags/${nextRelease.version}`,
25
- GITHUB_REF_TYPE: "tag",
26
- },
27
- }
28
- );
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
+ });
29
41
  child.stdout.on("data", (data) => logger.log(data.toString()));
30
42
  child.stderr.on("data", (data) => logger.error(data.toString()));
31
43
  child.on("error", reject);
@@ -42,7 +54,7 @@ module.exports = {
42
54
  try {
43
55
  const sedOutput = execSync(
44
56
  "find . -type f -name 'pom.xml' -exec sed -i 's|nexus.senior.com.br/repository|maven.senior.com.br/artifactory|g' {} +",
45
- { stdio: "pipe" }
57
+ { stdio: "pipe" },
46
58
  );
47
59
  if (sedOutput && sedOutput.length) {
48
60
  logger.log("sed output:\n%s", sedOutput.toString());
@@ -50,25 +62,89 @@ module.exports = {
50
62
  } catch (err) {
51
63
  const stdout = err.stdout ? err.stdout.toString() : "";
52
64
  const stderr = err.stderr ? err.stderr.toString() : "";
53
- logger.error("pom.xml URL replacement failed (exit code %d)", err.status);
65
+ logger.error(
66
+ "pom.xml URL replacement failed (exit code %d)",
67
+ err.status,
68
+ );
54
69
  if (stdout) logger.error("stdout:\n%s", stdout);
55
70
  if (stderr) logger.error("stderr:\n%s", stderr);
56
71
  throw err;
57
72
  }
58
73
  },
59
74
  },
60
- [
61
- "@semantic-release/git",
62
- {
63
- assets: [
64
- "sdl.properties",
65
- "**/**/pom.xml",
66
- "**/**/feature.xml",
67
- "**/**/category.xml",
68
- "**/**/MANIFEST.MF",
69
- ],
70
- message: ":pencil2: chore: bump ${nextRelease.version}",
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
+ );
71
147
  },
72
- ],
148
+ },
73
149
  ],
74
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.5",
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",