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