.versionrc.js 4.6 KB

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