|
| 1 | +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +/* |
| 5 | + First run `make setup_semantic_release` to install the required dependencies. |
| 6 | +
|
| 7 | + Using this config semantic-release will search for the latest tag |
| 8 | + evaluate all commits after that tag |
| 9 | + generate release notes and a version bump. |
| 10 | + It will commit these changes, push these changes, and publish a new version tag. |
| 11 | +
|
| 12 | + This file requires a `--branches` option to function. |
| 13 | + This is to facilitate point releases if needed. |
| 14 | +
|
| 15 | + `npx semantic-release --branches main` |
| 16 | +*/ |
| 17 | + |
| 18 | +const fs = require("fs"); |
| 19 | + |
| 20 | +/** |
| 21 | + * Function to parse a simple properties file |
| 22 | + * @param {string} filePath - Path to the properties file |
| 23 | + * @returns {Object} Parsed properties as key-value pairs |
| 24 | + */ |
| 25 | +function parsePropertiesFile(filePath) { |
| 26 | + const content = fs.readFileSync(filePath, "utf8"); |
| 27 | + const properties = {}; |
| 28 | + |
| 29 | + content.split("\n").forEach((line) => { |
| 30 | + if (line && !line.startsWith("#") && line.includes("=")) { |
| 31 | + const [key, ...valueParts] = line.split("="); |
| 32 | + properties[key.trim()] = valueParts.join("=").trim(); |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | + return properties; |
| 37 | +} |
| 38 | + |
| 39 | +// Read your project.properties file |
| 40 | +const props = parsePropertiesFile("./project.properties"); |
| 41 | + |
| 42 | +// This project has several runtimes |
| 43 | +// each one has files that need to be updated. |
| 44 | +// We model all the files and the runtimes here in this structure |
| 45 | +const Runtimes = { |
| 46 | + net: { |
| 47 | + "DynamoDbEncryption/runtimes/net/DynamoDbEncryption.csproj": { |
| 48 | + dependencies: [], |
| 49 | + assemblyInfo: "DynamoDbEncryption/runtimes/net/AssemblyInfo.cs", |
| 50 | + }, |
| 51 | + }, |
| 52 | +}; |
| 53 | + |
| 54 | +/** |
| 55 | + * @type {import('semantic-release').GlobalConfig} |
| 56 | + */ |
| 57 | +module.exports = { |
| 58 | + branches: ["main"], |
| 59 | + repositoryUrl: "git@github.com:aws/aws-database-encryption-sdk-dynamodb.git", |
| 60 | + tagFormat: "v${version}-net", |
| 61 | + plugins: [ |
| 62 | + // Check the commits since the last release |
| 63 | + [ |
| 64 | + "@semantic-release/commit-analyzer", |
| 65 | + { |
| 66 | + preset: "conventionalcommits", |
| 67 | + parserOpts: { |
| 68 | + noteKeywords: ["DOTNET-BREAKING-CHANGE", "DOTNET-BREAKING-CHANGES"], |
| 69 | + }, |
| 70 | + presetConfig: { |
| 71 | + types: [ |
| 72 | + { type: "feat", section: "Features" }, |
| 73 | + { type: "fix", section: "Fixes" }, |
| 74 | + { type: "chore", section: "Maintenance" }, |
| 75 | + { type: "docs", section: "Maintenance" }, |
| 76 | + { type: "revert", section: "Fixes" }, |
| 77 | + { type: "style", hidden: true }, |
| 78 | + { type: "refactor", hidden: true }, |
| 79 | + { type: "perf", hidden: true }, |
| 80 | + { type: "test", hidden: true }, |
| 81 | + ], |
| 82 | + }, |
| 83 | + releaseRules: [ |
| 84 | + { type: "docs", release: "patch" }, |
| 85 | + { type: "revert", release: "patch" }, |
| 86 | + { type: "chore", release: "patch" }, |
| 87 | + ], |
| 88 | + }, |
| 89 | + ], |
| 90 | + // Based on the commits generate release notes |
| 91 | + [ |
| 92 | + "@semantic-release/release-notes-generator", |
| 93 | + { |
| 94 | + preset: "conventionalcommits", |
| 95 | + parserOpts: { |
| 96 | + noteKeywords: ["DOTNET-BREAKING-CHANGE", "DOTNET-BREAKING-CHANGES"], |
| 97 | + }, |
| 98 | + presetConfig: { |
| 99 | + types: [ |
| 100 | + { |
| 101 | + type: "feat", |
| 102 | + scope: "dafny", |
| 103 | + section: "Features -- All Languages", |
| 104 | + hidden: false, |
| 105 | + }, |
| 106 | + { |
| 107 | + type: "feat", |
| 108 | + scope: "dotnet", |
| 109 | + section: "Features -- DotNet", |
| 110 | + hidden: false, |
| 111 | + }, |
| 112 | + { |
| 113 | + type: "fix", |
| 114 | + scope: "dafny", |
| 115 | + section: "Fixes -- All Languages", |
| 116 | + hidden: false, |
| 117 | + }, |
| 118 | + { |
| 119 | + type: "fix", |
| 120 | + scope: "dotnet", |
| 121 | + section: "Fixes -- DotNet", |
| 122 | + hidden: false, |
| 123 | + }, |
| 124 | + { |
| 125 | + type: "chore", |
| 126 | + scope: "dafny", |
| 127 | + section: "Maintenance -- All Languages", |
| 128 | + hidden: false, |
| 129 | + }, |
| 130 | + { |
| 131 | + type: "chore", |
| 132 | + scope: "dotnet", |
| 133 | + section: "Maintenance -- DotNet", |
| 134 | + hidden: false, |
| 135 | + }, |
| 136 | + { |
| 137 | + type: "docs", |
| 138 | + scope: "dafny", |
| 139 | + section: "Maintenance -- All Languages", |
| 140 | + hidden: false, |
| 141 | + }, |
| 142 | + { |
| 143 | + type: "docs", |
| 144 | + scope: "dotnet", |
| 145 | + section: "Maintenance -- DotNet", |
| 146 | + hidden: false, |
| 147 | + }, |
| 148 | + { |
| 149 | + type: "revert", |
| 150 | + scope: "dafny", |
| 151 | + section: "Fixes -- All Languages", |
| 152 | + hidden: false, |
| 153 | + }, |
| 154 | + { |
| 155 | + type: "revert", |
| 156 | + scope: "dotnet", |
| 157 | + section: "Fixes -- DotNet", |
| 158 | + hidden: false, |
| 159 | + }, |
| 160 | + { type: "style", section: "Miscellaneous", hidden: false }, |
| 161 | + { type: "refactor", section: "Miscellaneous", hidden: false }, |
| 162 | + { type: "perf", section: "Miscellaneous", hidden: false }, |
| 163 | + { type: "test", section: "Miscellaneous", hidden: false }, |
| 164 | + ], |
| 165 | + }, |
| 166 | + }, |
| 167 | + ], |
| 168 | + // Update the change log with the generated release notes |
| 169 | + [ |
| 170 | + "@semantic-release/changelog", |
| 171 | + { |
| 172 | + changelogFile: "CHANGELOG.md", |
| 173 | + changelogTitle: "# Changelog", |
| 174 | + }, |
| 175 | + ], |
| 176 | + |
| 177 | + // Bump the various versions |
| 178 | + [ |
| 179 | + "semantic-release-replace-plugin", |
| 180 | + { |
| 181 | + replacements: [ |
| 182 | + // Update the version for all DotNet projects |
| 183 | + // Does not update the dependencies |
| 184 | + { |
| 185 | + files: Object.keys(Runtimes.net), |
| 186 | + from: "<Version>.*</Version>", |
| 187 | + to: "<Version>${nextRelease.version}</Version>", |
| 188 | + results: Object.keys(Runtimes.net).map(CheckResults), |
| 189 | + countMatches: true, |
| 190 | + }, |
| 191 | + { |
| 192 | + files: Object.keys(Runtimes.net), |
| 193 | + from: '<ProjectReference Include="../../../submodules/MaterialProviders/AwsCryptographicMaterialProviders/runtimes/net/MPL.csproj"/>', |
| 194 | + to: `<PackageReference Include="AWS.Cryptography.MaterialProviders" Version="[${props.mplDependencyNetVersion}]" />`, |
| 195 | + results: Object.keys(Runtimes.net).map(CheckResults), |
| 196 | + countMatches: true, |
| 197 | + }, |
| 198 | + // Update the AssmeblyInfo.cs file of the DotNet projects |
| 199 | + ...Object.entries(Runtimes.net).flatMap( |
| 200 | + ([file, { assemblyInfo }]) => ({ |
| 201 | + files: assemblyInfo, |
| 202 | + from: "assembly: AssemblyVersion(.*)", |
| 203 | + to: 'assembly: AssemblyVersion("${nextRelease.version}")]', |
| 204 | + results: [CheckResults(assemblyInfo)], |
| 205 | + countMatches: true, |
| 206 | + }), |
| 207 | + ), |
| 208 | + ], |
| 209 | + }, |
| 210 | + ], |
| 211 | + // Commit and push changes the changelog and versions bumps |
| 212 | + [ |
| 213 | + "@semantic-release/git", |
| 214 | + { |
| 215 | + assets: [ |
| 216 | + "CHANGELOG.md", |
| 217 | + ...Object.values(Runtimes).flatMap((r) => Object.keys(r)), |
| 218 | + ...Object.values(Runtimes.net).flatMap((r) => r.assemblyInfo), |
| 219 | + ], |
| 220 | + message: |
| 221 | + "chore(release): ${nextRelease.version} \n\n${nextRelease.notes}", |
| 222 | + }, |
| 223 | + ], |
| 224 | + ], |
| 225 | +}; |
| 226 | + |
| 227 | +function CheckResults(file) { |
| 228 | + return { |
| 229 | + file, |
| 230 | + hasChanged: true, |
| 231 | + numMatches: 1, |
| 232 | + numReplacements: 1, |
| 233 | + }; |
| 234 | +} |
0 commit comments