|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// |
| 3 | +// semantic-release configuration. |
| 4 | +// |
| 5 | +// This is an ESM (.mjs) config rather than .releaserc.json because the |
| 6 | +// release-notes-generator needs a `writerOpts.transform` function to strip git |
| 7 | +// trailers (e.g. `Signed-off-by:`) that the conventional-commits parser folds |
| 8 | +// into `BREAKING CHANGE` notes. JSON cannot carry functions. |
| 9 | +// |
| 10 | +// This config defaults to a dry run as a fail-safe: the publishing plugins |
| 11 | +// (@semantic-release/github, @semantic-release/git) and the verify/publish exec |
| 12 | +// commands are only included when RELEASE_DRY_RUN=false. ci/release/run.sh opts |
| 13 | +// in to a real release that way; every other invocation stays harmless. |
| 14 | + |
| 15 | +import { createRequire } from "node:module"; |
| 16 | +import { pathToFileURL } from "node:url"; |
| 17 | + |
| 18 | +const loadPreset = async () => { |
| 19 | + try { |
| 20 | + return (await import("conventional-changelog-conventionalcommits")).default; |
| 21 | + } catch { |
| 22 | + const require = createRequire(pathToFileURL(process.argv[1])); |
| 23 | + const resolved = pathToFileURL( |
| 24 | + require.resolve("conventional-changelog-conventionalcommits") |
| 25 | + ).href; |
| 26 | + return (await import(resolved)).default; |
| 27 | + } |
| 28 | +}; |
| 29 | +const conventionalcommits = await loadPreset(); |
| 30 | + |
| 31 | +const TRAILER_KEYS = [ |
| 32 | + "Signed-off-by", |
| 33 | + "Co-authored-by", |
| 34 | + "Co-developed-by", |
| 35 | + "Reviewed-by", |
| 36 | + "Acked-by", |
| 37 | + "Tested-by", |
| 38 | + "Reported-by", |
| 39 | + "Suggested-by", |
| 40 | + "Helped-by", |
| 41 | + "Cc", |
| 42 | +]; |
| 43 | +const TRAILER = new RegExp(`^(?:${TRAILER_KEYS.join("|")}):\\s`, "i"); |
| 44 | + |
| 45 | +const stripTrailers = (text) => { |
| 46 | + if (!text) { |
| 47 | + return text; |
| 48 | + } |
| 49 | + |
| 50 | + const lines = text.split("\n"); |
| 51 | + while (lines.length) { |
| 52 | + const last = lines[lines.length - 1].trim(); |
| 53 | + if (last === "" || TRAILER.test(last)) { |
| 54 | + lines.pop(); |
| 55 | + } else { |
| 56 | + break; |
| 57 | + } |
| 58 | + } |
| 59 | + return lines.join("\n"); |
| 60 | +}; |
| 61 | + |
| 62 | +const preset = await conventionalcommits(); |
| 63 | +const presetTransform = preset.writer.transform; |
| 64 | +const dryRun = process.env.RELEASE_DRY_RUN !== "false"; |
| 65 | + |
| 66 | +export default { |
| 67 | + branches: [ |
| 68 | + { name: "+([0-9])?(.{+([0-9]),x}).x" }, |
| 69 | + { name: "main" }, |
| 70 | + { name: "next" }, |
| 71 | + { name: "next-major" }, |
| 72 | + { name: "beta", prerelease: true }, |
| 73 | + { name: "alpha", prerelease: true }, |
| 74 | + ], |
| 75 | + preset: "conventionalcommits", |
| 76 | + dryRun, |
| 77 | + plugins: [ |
| 78 | + [ |
| 79 | + "@semantic-release/release-notes-generator", |
| 80 | + { |
| 81 | + writerOpts: { |
| 82 | + transform(commit, context) { |
| 83 | + const out = presetTransform(commit, context); |
| 84 | + if (out && Array.isArray(out.notes)) { |
| 85 | + out.notes = out.notes.map((note) => ({ |
| 86 | + ...note, |
| 87 | + text: stripTrailers(note.text), |
| 88 | + })); |
| 89 | + } |
| 90 | + return out; |
| 91 | + }, |
| 92 | + }, |
| 93 | + }, |
| 94 | + ], |
| 95 | + [ |
| 96 | + "@semantic-release/commit-analyzer", |
| 97 | + { |
| 98 | + releaseRules: [{ breaking: true, release: "minor" }], |
| 99 | + }, |
| 100 | + ], |
| 101 | + [ |
| 102 | + "@semantic-release/exec", |
| 103 | + dryRun |
| 104 | + ? {} |
| 105 | + : { |
| 106 | + verifyConditionsCmd: "ci/release/verify.sh", |
| 107 | + prepareCmd: "ci/release/prepare.sh ${nextRelease.version}", |
| 108 | + publishCmd: "ci/release/publish.sh", |
| 109 | + }, |
| 110 | + ], |
| 111 | + [ |
| 112 | + "@semantic-release/changelog", |
| 113 | + { |
| 114 | + changelogTitle: "Release Notes\n---", |
| 115 | + changelogFile: "CHANGELOG.md", |
| 116 | + }, |
| 117 | + ], |
| 118 | + ...(dryRun |
| 119 | + ? [] |
| 120 | + : [ |
| 121 | + [ |
| 122 | + "@semantic-release/github", |
| 123 | + { |
| 124 | + assets: [ |
| 125 | + { |
| 126 | + path: "native/libs/isthmus-macOS-latest", |
| 127 | + name: "isthmus-macOS-${nextRelease.version}", |
| 128 | + label: "Isthmus Native Image - macOS", |
| 129 | + }, |
| 130 | + { |
| 131 | + path: "native/libs/isthmus-ubuntu-latest", |
| 132 | + name: "isthmus-ubuntu-${nextRelease.version}", |
| 133 | + label: "Isthmus Native Image - Linux", |
| 134 | + }, |
| 135 | + ], |
| 136 | + successComment: false, |
| 137 | + }, |
| 138 | + ], |
| 139 | + [ |
| 140 | + "@semantic-release/git", |
| 141 | + { |
| 142 | + assets: ["gradle.properties", "CHANGELOG.md"], |
| 143 | + message: "chore(release): ${nextRelease.version}", |
| 144 | + }, |
| 145 | + ], |
| 146 | + ]), |
| 147 | + ], |
| 148 | +}; |
0 commit comments