@thisismanta/semantic-version 2.0.0-8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,4 @@
1
- Once installed, this package verifies your upcoming **Git commit messages** against the convention and automatically runs `npm version` after a commit if needed.
2
-
3
- ## Git commit message convention
1
+ Once installed, this package verifies your upcoming **Git commit messages** against the convention below.
4
2
 
5
3
  ```
6
4
  <type>[!]: <subject>
@@ -10,11 +8,36 @@ Where
10
8
  - `!` indicates that the commit contains breaking changes.
11
9
  - `<subject>` is the actual commit message where the first word must be written in lower cases.
12
10
 
13
- ## Versioning
11
+ ---
12
+
13
+ Additionally, you can run `npx auto-npm-version` on **GitHub Actions** to trigger `npm version` based on your commit messages and create a GitHub release (optional).
14
14
 
15
15
  |Commit message type|Post-commit command|
16
16
  |---|---|
17
17
  |`!`|`npm version major`|
18
18
  |`feat`|`npm version minor`|
19
19
  |`fix`|`npm version patch`|
20
- |Others|Does not run `npm version`|
20
+ |Others|Does not run `npm version`|
21
+
22
+ Here's an example of **GitHub Actions** workflow file:
23
+
24
+ ```yml
25
+ on:
26
+ push:
27
+ branches: [master]
28
+ jobs:
29
+ release:
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - uses: actions/checkout@v3
33
+ with:
34
+ fetch-depth: 0 # Ensure Git tags are fetched
35
+ - uses: actions/setup-node@v3
36
+ with:
37
+ node-version-file: 'package.json'
38
+ cache: npm
39
+ - run: npm ci # Install semantic-version as part of the dependencies
40
+ - run: npx auto-npm-version
41
+ env:
42
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Make it possible to create a new release using GitHub API
43
+ ```
@@ -37,7 +37,7 @@ async function main() {
37
37
  JSON.parse(await run('npm pkg get version')));
38
38
  (0, debug_1.debug)('lastVersion »', JSON.stringify(lastVersion));
39
39
  if (!lastVersion) {
40
- throw new Error('Expect to have a valid "version" field in package.json.');
40
+ throw new Error('Could not find last version.');
41
41
  }
42
42
  const commits = (await run(`git log v${lastVersion}..HEAD --format=%H%s`))
43
43
  .split('\n')
@@ -75,13 +75,13 @@ async function main() {
75
75
  console.log('Exited without releasing a new version');
76
76
  return;
77
77
  }
78
- const nextVersion = await run(`npm version --json --no-commit-hooks ${releaseType}`);
79
- (0, debug_1.debug)('nextVersion »', nextVersion);
80
- console.log(`Created version ${releaseType}`);
78
+ const nextVersion = semver_1.default.valid(await run(`npm version --json --no-commit-hooks ${releaseType}`));
79
+ (0, debug_1.debug)('nextVersion »', JSON.stringify(nextVersion));
80
+ console.log(`Created tag ${releaseType}`);
81
81
  await run(`git push --follow-tags origin`);
82
82
  console.log(`Pushed Git tags`);
83
- if (semver_1.default.valid(nextVersion) && process.env.GITHUB_TOKEN) {
84
- const commitGroups = {
83
+ if (nextVersion && process.env.GITHUB_TOKEN) {
84
+ const groups = {
85
85
  'BREAKING CHANGES': [],
86
86
  'Features': [],
87
87
  'Bug Fixes': [],
@@ -89,31 +89,31 @@ async function main() {
89
89
  };
90
90
  for (const commit of commits) {
91
91
  if (commit.breaking) {
92
- commitGroups['BREAKING CHANGES'].push(commit);
92
+ groups['BREAKING CHANGES'].push(commit);
93
93
  }
94
94
  else if (commit.type === 'feat') {
95
- commitGroups['Features'].push(commit);
95
+ groups['Features'].push(commit);
96
96
  }
97
97
  else if (commit.type === 'bug') {
98
- commitGroups['Bug Fixes'].push(commit);
98
+ groups['Bug Fixes'].push(commit);
99
99
  }
100
100
  else {
101
- commitGroups['Others'].push(commit);
101
+ groups['Others'].push(commit);
102
102
  }
103
103
  }
104
- const releaseNote = Object.entries(commitGroups)
104
+ const releaseNote = Object.entries(groups)
105
105
  .filter(([title, commits]) => commits.length > 0)
106
106
  .map(([title, commits]) => `### ${title}\n\n` +
107
107
  commits.map(({ subject, hash }) => `- ${subject} (${hash})`).join('\n'))
108
108
  .join('\n\n');
109
109
  (0, debug_1.debug)('releaseNote »', releaseNote);
110
110
  const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
111
- github.context.payload.ref;
112
111
  // See https://octokit.github.io/rest.js/v19#repos-create-release
113
112
  const releaseRespond = await octokit.rest.repos.createRelease({
114
113
  ...github.context.repo,
115
- tag_name: nextVersion,
114
+ tag_name: 'v' + nextVersion,
116
115
  body: releaseNote,
116
+ make_latest: true, // TODO: compare with the latest release
117
117
  });
118
118
  (0, debug_1.debug)('releaseRespond »', JSON.stringify(releaseRespond, null, 2));
119
119
  console.log('Created a new release on GitHub');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thisismanta/semantic-version",
3
- "version": "2.0.0-8",
3
+ "version": "2.0.0",
4
4
  "author": "Anantachai Saothong <thisismanta@gmail.com>",
5
5
  "license": "ISC",
6
6
  "engines": {