.versionrc.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2021, 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": "package-lock.json",
  70. "type": "json"
  71. },
  72. {
  73. "filename": "tools/conventional-changelog-tf-a/package.json",
  74. "type": "json"
  75. },
  76. {
  77. "filename": "Makefile",
  78. "updater": {
  79. "readVersion": function (contents) {
  80. const major = contents.match(/^VERSION_MAJOR\s*:=\s*(\d+?)$/m)[1];
  81. const minor = contents.match(/^VERSION_MINOR\s*:=\s*(\d+?)$/m)[1];
  82. return `${major}.${minor}.0`;
  83. },
  84. "writeVersion": function (contents, version) {
  85. const major = version.split(".")[0];
  86. const minor = version.split(".")[1];
  87. contents = contents.replace(/^(VERSION_MAJOR\s*:=\s*)(\d+?)$/m, `$1${major}`);
  88. contents = contents.replace(/^(VERSION_MINOR\s*:=\s*)(\d+?)$/m, `$1${minor}`);
  89. return contents;
  90. }
  91. }
  92. }
  93. ]
  94. };