Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 1 | /* |
Harrison Mutai | b378ad4 | 2023-02-16 10:20:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2021-2023, Arm Limited. All rights reserved. |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | /* eslint-env es6 */ |
| 8 | |
| 9 | "use strict"; |
| 10 | |
Chris Kay | 82117d7 | 2021-12-01 16:34:55 +0000 | [diff] [blame] | 11 | const fs = require("fs"); |
| 12 | const yaml = require("js-yaml"); |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 13 | |
| 14 | /* |
Chris Kay | 82117d7 | 2021-12-01 16:34:55 +0000 | [diff] [blame] | 15 | * The types and scopes accepted by both Commitlint and Commitizen are defined by the changelog |
| 16 | * configuration file - `changelog.yaml` - as they decide which section of the changelog commits |
| 17 | * with a given type and scope are placed in. |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 18 | */ |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 19 | |
Chris Kay | 82117d7 | 2021-12-01 16:34:55 +0000 | [diff] [blame] | 20 | let changelog; |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 21 | |
Chris Kay | 82117d7 | 2021-12-01 16:34:55 +0000 | [diff] [blame] | 22 | try { |
| 23 | const contents = fs.readFileSync("changelog.yaml", "utf8"); |
| 24 | |
| 25 | changelog = yaml.load(contents); |
| 26 | } catch (err) { |
| 27 | console.log(err); |
| 28 | |
| 29 | throw err; |
| 30 | } |
| 31 | |
| 32 | /* |
| 33 | * The next couple of functions are just used to transform the changelog YAML configuration |
| 34 | * structure into one accepted by the Conventional Changelog adapter (conventional-changelog-tf-a). |
| 35 | */ |
| 36 | |
| 37 | function getTypes(sections) { |
| 38 | return sections.map(section => { |
| 39 | return { |
| 40 | "type": section.type, |
| 41 | "section": section.hidden ? undefined : section.title, |
| 42 | "hidden": section.hidden || false, |
| 43 | }; |
| 44 | }) |
| 45 | } |
| 46 | |
| 47 | function getSections(subsections) { |
| 48 | return subsections.flatMap(subsection => { |
| 49 | const scope = subsection.scope ? [ subsection.scope ] : []; |
| 50 | |
| 51 | return { |
| 52 | "title": subsection.title, |
| 53 | "sections": getSections(subsection.subsections || []), |
| 54 | "scopes": scope.concat(subsection.deprecated || []), |
| 55 | }; |
| 56 | }) |
| 57 | }; |
| 58 | |
| 59 | const types = getTypes(changelog.sections); |
| 60 | const sections = getSections(changelog.subsections); |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 61 | |
| 62 | module.exports = { |
| 63 | "header": "# Change Log & Release Notes\n\nThis document contains a summary of the new features, changes, fixes and known\nissues in each release of Trusted Firmware-A.\n", |
| 64 | "preset": { |
| 65 | "name": "tf-a", |
| 66 | "commitUrlFormat": "https://review.trustedfirmware.org/plugins/gitiles/TF-A/trusted-firmware-a/+/{{hash}}", |
Chris Kay | 78748c9 | 2021-12-01 17:47:51 +0000 | [diff] [blame] | 67 | "compareUrlFormat": "https://review.trustedfirmware.org/plugins/gitiles/TF-A/trusted-firmware-a/+/refs/tags/{{previousTag}}..refs/tags/{{currentTag}}", |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 68 | "userUrlFormat": "https://github.com/{{user}}", |
| 69 | |
| 70 | "types": types, |
Chris Kay | 82117d7 | 2021-12-01 16:34:55 +0000 | [diff] [blame] | 71 | "sections": sections, |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 72 | }, |
Chris Kay | a1e89a7 | 2021-12-03 11:22:09 +0000 | [diff] [blame] | 73 | "infile": "docs/change-log.md", |
| 74 | "skip": { |
| 75 | "commit": true, |
| 76 | "tag": true |
| 77 | }, |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 78 | "bumpFiles": [ |
| 79 | { |
Chris Kay | a1e89a7 | 2021-12-03 11:22:09 +0000 | [diff] [blame] | 80 | "filename": "package.json", |
| 81 | "type": "json" |
| 82 | }, |
| 83 | { |
Harrison Mutai | b378ad4 | 2023-02-16 10:20:48 +0000 | [diff] [blame] | 84 | "filename": "pyproject.toml", |
| 85 | "updater": { |
| 86 | "readVersion": function (contents) { |
| 87 | const _ver = contents.match(/version\s=.*"(\d)\.(\d)\.(\d)/); |
| 88 | |
| 89 | return `${_ver[1]}.${_ver[2]}.${_ver[2]}`; |
| 90 | }, |
| 91 | |
| 92 | "writeVersion": function (contents, version) { |
| 93 | const _ver = 'version = "' + version + '"' |
| 94 | |
| 95 | return contents.replace(/^(version\s=\s")((\d).?)*$/m, _ver) |
| 96 | } |
Harrison Mutai | b378ad4 | 2023-02-16 10:20:48 +0000 | [diff] [blame] | 97 | }, |
| 98 | }, |
| 99 | { |
Chris Kay | a1e89a7 | 2021-12-03 11:22:09 +0000 | [diff] [blame] | 100 | "filename": "package-lock.json", |
| 101 | "type": "json" |
| 102 | }, |
| 103 | { |
Harrison Mutai | fa9b14d | 2023-05-31 10:18:49 +0100 | [diff] [blame] | 104 | "filename": "docs/conf.py", |
| 105 | "updater": { |
| 106 | "readVersion": function (contents) { |
| 107 | const _ver = contents.match(/version\s=.*"(\d)\.(\d)\.(\d)/); |
| 108 | |
| 109 | return `${_ver[1]}.${_ver[2]}.${_ver[2]}`; |
| 110 | }, |
| 111 | |
| 112 | "writeVersion": function (contents, version) { |
| 113 | const _ver = 'version = "' + version + '"' |
| 114 | const _rel = 'release = "' + version + '"' |
| 115 | |
| 116 | contents = contents.replace(/^(version\s=\s")((\d).?)*$/m, _ver) |
| 117 | contents = contents.replace(/^(release\s=\s")((\d).?)*$/m, _rel) |
| 118 | return contents |
| 119 | } |
| 120 | }, |
| 121 | }, |
| 122 | { |
Chris Kay | a1e89a7 | 2021-12-03 11:22:09 +0000 | [diff] [blame] | 123 | "filename": "tools/conventional-changelog-tf-a/package.json", |
| 124 | "type": "json" |
| 125 | }, |
| 126 | { |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 127 | "filename": "Makefile", |
| 128 | "updater": { |
| 129 | "readVersion": function (contents) { |
| 130 | const major = contents.match(/^VERSION_MAJOR\s*:=\s*(\d+?)$/m)[1]; |
| 131 | const minor = contents.match(/^VERSION_MINOR\s*:=\s*(\d+?)$/m)[1]; |
Yann Gautier | 57078a9 | 2023-10-03 11:09:07 +0200 | [diff] [blame] | 132 | const patch = contents.match(/^VERSION_PATCH\s*:=\s*(\d+?)$/m)[1]; |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 133 | |
Yann Gautier | 57078a9 | 2023-10-03 11:09:07 +0200 | [diff] [blame] | 134 | return `${major}.${minor}.${patch}`; |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 135 | }, |
| 136 | |
| 137 | "writeVersion": function (contents, version) { |
| 138 | const major = version.split(".")[0]; |
| 139 | const minor = version.split(".")[1]; |
Yann Gautier | 57078a9 | 2023-10-03 11:09:07 +0200 | [diff] [blame] | 140 | const patch = version.split(".")[2]; |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 141 | |
| 142 | contents = contents.replace(/^(VERSION_MAJOR\s*:=\s*)(\d+?)$/m, `$1${major}`); |
| 143 | contents = contents.replace(/^(VERSION_MINOR\s*:=\s*)(\d+?)$/m, `$1${minor}`); |
Yann Gautier | 57078a9 | 2023-10-03 11:09:07 +0200 | [diff] [blame] | 144 | contents = contents.replace(/^(VERSION_PATCH\s*:=\s*)(\d+?)$/m, `$1${patch}`); |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 145 | |
| 146 | return contents; |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | ] |
| 151 | }; |