release.config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * Semantic Release Config
  3. */
  4. const fs = require('fs').promises;
  5. const path = require('path');
  6. // Get env vars
  7. const ref = process.env.GITHUB_REF;
  8. const serverUrl = process.env.GITHUB_SERVER_URL;
  9. const repository = process.env.GITHUB_REPOSITORY;
  10. const repositoryUrl = serverUrl + '/' + repository;
  11. // Declare params
  12. const resourcePath = './.releaserc/';
  13. const templates = {
  14. main: { file: 'template.hbs', text: undefined },
  15. header: { file: 'header.hbs', text: undefined },
  16. commit: { file: 'commit.hbs', text: undefined },
  17. footer: { file: 'footer.hbs', text: undefined },
  18. };
  19. // Declare semantic config
  20. async function config() {
  21. // Get branch
  22. const branch = ref.split('/').pop();
  23. console.log(`Running on branch: ${branch}`);
  24. // Set changelog file
  25. //const changelogFile = `./changelogs/CHANGELOG_${branch}.md`;
  26. const changelogFile = `./CHANGELOG.md`;
  27. console.log(`Changelog file output to: ${changelogFile}`);
  28. // Load template file contents
  29. await loadTemplates();
  30. const config = {
  31. branches: [
  32. 'master',
  33. // { name: 'alpha', prerelease: true },
  34. // { name: 'beta', prerelease: true },
  35. // 'next-major',
  36. // Long-Term-Support branches
  37. // { name: 'release-1', range: '1.x.x', channel: '1.x' },
  38. // { name: 'release-2', range: '2.x.x', channel: '2.x' },
  39. // { name: 'release-3', range: '3.x.x', channel: '3.x' },
  40. // { name: 'release-4', range: '4.x.x', channel: '4.x' },
  41. ],
  42. dryRun: false,
  43. debug: true,
  44. ci: true,
  45. tagFormat: '${version}',
  46. plugins: [
  47. ['@semantic-release/commit-analyzer', {
  48. preset: 'angular',
  49. releaseRules: [
  50. { type: 'docs', scope: 'README', release: 'patch' },
  51. { scope: 'no-release', release: false },
  52. ],
  53. parserOpts: {
  54. noteKeywords: [ 'BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING' ],
  55. },
  56. }],
  57. ['@semantic-release/release-notes-generator', {
  58. preset: 'angular',
  59. parserOpts: {
  60. noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING']
  61. },
  62. writerOpts: {
  63. commitsSort: ['subject', 'scope'],
  64. mainTemplate: templates.main.text,
  65. headerPartial: templates.header.text,
  66. commitPartial: templates.commit.text,
  67. footerPartial: templates.footer.text,
  68. },
  69. }],
  70. ['@semantic-release/changelog', {
  71. 'changelogFile': changelogFile,
  72. }],
  73. ['@semantic-release/npm', {
  74. 'npmPublish': true,
  75. }],
  76. ['@semantic-release/git', {
  77. assets: [changelogFile, 'package.json', 'package-lock.json'],
  78. }],
  79. ['@semantic-release/github', {
  80. successComment: getReleaseComment(),
  81. labels: ['type:ci'],
  82. releasedLabels: ['state:released<%= nextRelease.channel ? `-${nextRelease.channel}` : "" %>']
  83. }],
  84. ],
  85. };
  86. return config;
  87. }
  88. async function loadTemplates() {
  89. for (const template of Object.keys(templates)) {
  90. const text = await readFile(path.resolve(__dirname, resourcePath, templates[template].file));
  91. templates[template].text = text;
  92. }
  93. }
  94. async function readFile(filePath) {
  95. return await fs.readFile(filePath, 'utf-8');
  96. }
  97. function getReleaseComment() {
  98. const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}';
  99. const comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')';
  100. return comment;
  101. }
  102. module.exports = config();