Skip to content

Commit

Permalink
feat(release): add custom release-notes generator
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-koval committed Oct 4, 2019
1 parent 931153a commit ed4a8e5
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 22 deletions.
25 changes: 16 additions & 9 deletions .github/workflows/test-release.yml
Expand Up @@ -6,16 +6,23 @@ jobs:
test_publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
-
uses: actions/checkout@v1
-
uses: actions/setup-node@v1
with:
node-version: 12
- env:
-
env:
CI: true
run: npm ci
- env:
run: "npm ci"
-
env:
CI: true
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: ./scripts/dry-run.sh
GH_TOKEN: "${{ secrets.GH_TOKEN }}"
GITHUB_HEAD_REF: $GITHUB_HEAD_REF
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"
run: |
echo "//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN" > /home/runner/work/_temp/.npmrc
npx semantic-release --dry-run --debug -b $GITHUB_HEAD_REF
9 changes: 5 additions & 4 deletions package.json
Expand Up @@ -8,12 +8,12 @@
"@semantic-release/npm": "^5.1.15",
"@semantic-release/release-notes-generator": "^7.3.0"
},
"description": "Semantic-release shareable configuration for easy publishing to NPM, Github or Github Package Registry.",
"description": "Semantic-release shareable configuration for easy publishing to NPM & Github",
"devDependencies": {
"semantic-release": "^15.13.24"
},
"files": [
".releaserc.json"
"release.config.js"
],
"keywords": [
"changelog",
Expand All @@ -28,10 +28,11 @@
"release",
"semantic-release-config",
"semantic-release",
".releaserc.json"
".releaserc.json",
"release.config.js"
],
"license": "MIT",
"main": ".releaserc.json",
"main": "release.config.js",
"name": "semantic-release-npm-github-publish",
"peerDependencies": {
"semantic-release": ">=15.13.24"
Expand Down
File renamed without changes.
93 changes: 93 additions & 0 deletions release.config.js
@@ -0,0 +1,93 @@
const plugins = require("./plugins.json");

parserOpts = {
mergePattern: /^Merge pull request #(\d+) from (.*)$/,
mergeCorrespondence: ["id", "source"]
};

releaseRules = [{ type: "refactor", release: "patch" }];

customTransform = (commit, context) => {
const issues = [];

commit.notes.forEach(note => {
note.title = `BREAKING CHANGES`;
});

if (commit.type === `feat`) {
commit.type = `Features`;
} else if (commit.type === `fix`) {
commit.type = `Bug Fixes`;
} else if (commit.type === `perf`) {
commit.type = `Performance Improvements`;
} else if (commit.type === `revert`) {
commit.type = `Reverts`;
} else if (commit.type === `docs`) {
commit.type = `Documentation`;
} else if (commit.type === `style`) {
commit.type = `Styles`;
} else if (commit.type === `refactor`) {
commit.type = `Code Refactoring`;
} else if (commit.type === `test`) {
commit.type = `Tests`;
} else if (commit.type === `build`) {
commit.type = `Build System`;
} else if (commit.type === `ci`) {
commit.type = `Continuous Integration`;
} else {
return;
}

if (commit.scope === `*`) {
commit.scope = ``;
}

if (typeof commit.hash === `string`) {
commit.shortHash = commit.hash.substring(0, 7);
}

if (typeof commit.subject === `string`) {
let url = context.repository
? `${context.host}/${context.owner}/${context.repository}`
: context.repoUrl;
if (url) {
url = `${url}/issues/`;
// Issue URLs.
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
issues.push(issue);
return `[#${issue}](${url}${issue})`;
});
}
if (context.host) {
// User URLs.
commit.subject = commit.subject.replace(
/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g,
(_, username) => {
if (username.includes("/")) {
return `@${username}`;
}

return `[@${username}](${context.host}/${username})`;
}
);
}
}

// remove references that already appear in the subject
commit.references = commit.references.filter(reference => {
if (issues.indexOf(reference.issue) === -1) {
return true;
}

return false;
});

return commit;
};

module.exports = {
releaseRules,
parserOpts,
writerOpts: { transform: customTransform },
...plugins
};
9 changes: 0 additions & 9 deletions scripts/dry-run.sh

This file was deleted.

0 comments on commit ed4a8e5

Please sign in to comment.