blob: 9e54c7be7b60d83604e5504c58870f23af467596 [file] [log] [blame]
Chris Kay025c87f2021-11-09 20:05:38 +00001/*
Harrison Mutaib378ad42023-02-16 10:20:48 +00002 * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
Chris Kay025c87f2021-11-09 20:05:38 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/* eslint-env es6 */
8
9"use strict";
10
Chris Kay82117d72021-12-01 16:34:55 +000011const fs = require("fs");
12const yaml = require("js-yaml");
Chris Kay025c87f2021-11-09 20:05:38 +000013
14/*
Chris Kay82117d72021-12-01 16:34:55 +000015 * 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 Kay025c87f2021-11-09 20:05:38 +000018 */
Chris Kay025c87f2021-11-09 20:05:38 +000019
Chris Kay82117d72021-12-01 16:34:55 +000020let changelog;
Chris Kay025c87f2021-11-09 20:05:38 +000021
Chris Kay82117d72021-12-01 16:34:55 +000022try {
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
37function 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
47function 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
59const types = getTypes(changelog.sections);
60const sections = getSections(changelog.subsections);
Chris Kay025c87f2021-11-09 20:05:38 +000061
62module.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 Kay78748c92021-12-01 17:47:51 +000067 "compareUrlFormat": "https://review.trustedfirmware.org/plugins/gitiles/TF-A/trusted-firmware-a/+/refs/tags/{{previousTag}}..refs/tags/{{currentTag}}",
Chris Kay025c87f2021-11-09 20:05:38 +000068 "userUrlFormat": "https://github.com/{{user}}",
69
70 "types": types,
Chris Kay82117d72021-12-01 16:34:55 +000071 "sections": sections,
Chris Kay025c87f2021-11-09 20:05:38 +000072 },
Chris Kaya1e89a72021-12-03 11:22:09 +000073 "infile": "docs/change-log.md",
74 "skip": {
75 "commit": true,
76 "tag": true
77 },
Chris Kay025c87f2021-11-09 20:05:38 +000078 "bumpFiles": [
79 {
Chris Kaya1e89a72021-12-03 11:22:09 +000080 "filename": "package.json",
81 "type": "json"
82 },
83 {
Harrison Mutaib378ad42023-02-16 10:20:48 +000084 "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 }
97
98 },
99 },
100 {
Chris Kaya1e89a72021-12-03 11:22:09 +0000101 "filename": "package-lock.json",
102 "type": "json"
103 },
104 {
105 "filename": "tools/conventional-changelog-tf-a/package.json",
106 "type": "json"
107 },
108 {
Chris Kay025c87f2021-11-09 20:05:38 +0000109 "filename": "Makefile",
110 "updater": {
111 "readVersion": function (contents) {
112 const major = contents.match(/^VERSION_MAJOR\s*:=\s*(\d+?)$/m)[1];
113 const minor = contents.match(/^VERSION_MINOR\s*:=\s*(\d+?)$/m)[1];
114
115 return `${major}.${minor}.0`;
116 },
117
118 "writeVersion": function (contents, version) {
119 const major = version.split(".")[0];
120 const minor = version.split(".")[1];
121
122 contents = contents.replace(/^(VERSION_MAJOR\s*:=\s*)(\d+?)$/m, `$1${major}`);
123 contents = contents.replace(/^(VERSION_MINOR\s*:=\s*)(\d+?)$/m, `$1${minor}`);
124
125 return contents;
126 }
127 }
128 }
129 ]
130};