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