Skip to content

Commit

Permalink
Merge branch 'master' into feature/es-modules
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/plugin/github/GitHub.js
#	package.json
  • Loading branch information
webpro committed Apr 18, 2022
2 parents bbee9bb + 5e843f1 commit d411f8c
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 20 deletions.
1 change: 1 addition & 0 deletions .npmrc
@@ -1 +1,2 @@
save-exact=true
engine-strict=true
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -255,7 +255,7 @@ will run one after another. Some example release-it configuration:
The variables can be found in the [default configuration](./config/release-it.json). Additionally, the following
variables are exposed:

```
```text
version
latestVersion
changelog
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/release-it.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/ci.md
Expand Up @@ -41,7 +41,7 @@ Replace `[user]` and `[project]` with the actual values.
To run release-it from a GitHub Action, here's an example job (fragment) to configure a Git user (to push the release
commit), and expose the `GITHUB_TOKEN` for the GitHub Release:

```
```yaml
jobs:
release:
runs-on: ubuntu-latest
Expand All @@ -68,7 +68,7 @@ To publish a package to the (or any) npm registry from within a CI or CD environ
`NPM_TOKEN` available in the `.npmrc` file. This file should look like this before release-it attempts to publish the
package:

```
```text
//registry.npmjs.org/:_authToken=$NPM_TOKEN
```

Expand All @@ -78,7 +78,7 @@ One way to achieve this is to set the `NPM_TOKEN` in the CI environment, and fro
npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
```

This will create/update the `.npmrc` file and add the token there. Ideally you should either `.gitignore` this file,
This will create/update the `.npmrc` file and add the token there. Ideally you should either `.gitignore` this file,
otherwise you might end up committing it to your repo if you are using release-it's `git` options.

Since release-it executes `npm whoami` as a [prerequisite check](./npm.md#prerequisite-checks), which does not seem to
Expand Down
14 changes: 9 additions & 5 deletions docs/git.md
Expand Up @@ -40,14 +40,18 @@ different git url.
Use `git.tagName` to set a custom tag, not strictly equal to the (prefixed) version. When the latest tag has the `v`
prefix, it will be used again. No need to configure `git.tagName: "v${version}"` in this case.

Example: `git.tagName=${name}@${version}`
Example: `--git.tagName=${name}@${version}`

## Tag Match

Use `git.tagMatch` to override the normal matching behavior to find the latest tag. This can be useful when using a
plugin to determine the next tag.
Use `git.tagMatch` to override the normal matching behavior to find the latest tag. For instance, when doing a major
release to find and set the latest major tag, and include all commits in the changelog since this matching tag.

Example: `git.tagMatch='[0-9][0-9].[0-1][0-9].[0-9]*'`
Example: `git.tagMatch: "[0-9]+\\.[0-9]+\\.[0-9]+"`

This can be useful when using a plugin to determine the next tag:

Example: `git.tagMatch: "[0-9][0-9].[0-1][0-9].[0-9]*"`

## Extra arguments

Expand Down Expand Up @@ -102,7 +106,7 @@ Use an array to allow releases from more branch names. Wildcards are also allowe

The working directory should be clean (i.e. `git status` should say something like this:

```
```bash
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins.md
Expand Up @@ -314,7 +314,7 @@ Use template variables to render replacements. For instance, the command `git lo
`git log v1.2.3...HEAD` before being executed. The replacements are all configuration options (with the default values
in [config/release-it.json](../config/release-it.json)), plus the following additional variables:

```
```text
version
latestVersion
latestTag
Expand Down
8 changes: 8 additions & 0 deletions docs/pre-releases.md
Expand Up @@ -43,6 +43,14 @@ release-it major

<img src="./assets/release-it-prerelease.gif?raw=true" height="524">

When all commits since the latest major tag should be added to the changelog, use `--git.tagMatch`:

```bash
release-it major --git.tagMatch='[0-9]+\\.[0-9]+\\.[0-9]+'
```

This will find the latest major matching tag, skipping the pre-release tags.

Let's go back to when the latest release was `2.0.0-rc.0`. We added new features, which we don't want in the v2 release
yet, but instead in a later v2.1. A new pre-release id can be made for the minor release after in `2.1.0-alpha.0`:

Expand Down
3 changes: 2 additions & 1 deletion lib/plugin/github/GitHub.js
Expand Up @@ -7,6 +7,7 @@ import mime from 'mime-types';
import _ from 'lodash';
import retry from 'async-retry';
import newGithubReleaseUrl from 'new-github-release-url';
import ProxyAgent from 'proxy-agent';
import { format, parseVersion, readJSON, e } from '../../util.js';
import Release from '../GitRelease.js';
import prompts from './prompts.js';
Expand Down Expand Up @@ -168,7 +169,7 @@ class GitHub extends Release {
};

if (proxy) {
options.proxy = proxy;
options.request.agent = new ProxyAgent(proxy);
}

const client = new Octokit(options);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -80,7 +80,8 @@
"os-name": "5.0.1",
"parse-json": "5.2.0",
"promise.allsettled": "1.0.5",
"semver": "7.3.6",
"proxy-agent": "5.0.0",
"semver": "7.3.5",
"shelljs": "0.8.5",
"update-notifier": "5.1.0",
"url-join": "5.0.0",
Expand Down
26 changes: 19 additions & 7 deletions test/git.init.js
Expand Up @@ -156,19 +156,13 @@ test.serial('should get the latest custom tag after fetch when tagName is config
test.serial('should get the latest tag based on tagMatch', async t => {
const shell = factory(Shell);
const gitClient = factory(Git, {
options: { git: { tagMatch: '[0-9][0-9].[0-1][0-9].[0-9]*' } },
options: { git: { tagMatch: '[0-9][0-9]\\.[0-1][0-9]\\.[0-9]*' } },
container: { shell }
});
const { bare, target } = t.context;
const other = mkTmpDir();
sh.exec('git push');
sh.exec(`git clone ${bare} ${other}`);
sh.pushd('-q', other);
sh.exec('git tag 1.0.0');
sh.exec('git tag 21.04.3');
sh.exec('git tag 1.0.1');
sh.exec('git push --tags');
sh.pushd('-q', target);
await gitClient.init();
t.is(gitClient.config.getContext('latestTag'), '21.04.3');
});
Expand All @@ -182,3 +176,21 @@ test.serial('should generate correct changelog', async t => {
const changelog = await gitClient.getChangelog();
t.regex(changelog, /\* Add file \(\w{7}\)\n\* Add file \(\w{7}\)/);
});

test.serial.only('should get the full changelog since latest major tag', async t => {
const shell = factory(Shell);
const gitClient = factory(Git, {
options: { git: { tagMatch: '[0-9]\\.[0-9]\\.[0-9]', changelog: git.changelog } },
container: { shell }
});
sh.exec('git tag 1.0.0');
gitAdd('line', 'file', 'Add file');
sh.exec('git tag 2.0.0-rc.0');
gitAdd('line', 'file', 'Add file');
sh.exec('git tag 2.0.0-rc.1');
gitAdd('line', 'file', 'Add file');
await gitClient.init();
t.is(gitClient.config.getContext('latestTag'), '1.0.0');
const changelog = await gitClient.getChangelog();
t.regex(changelog, /\* Add file \(\w{7}\)\n\* Add file \(\w{7}\)\n\* Add file \(\w{7}\)/);
});
1 change: 1 addition & 0 deletions test/github.js
Expand Up @@ -241,6 +241,7 @@ test('should release to alternative host and proxy', async t => {
const { isReleased, releaseUrl } = github.getContext();
t.true(isReleased);
t.is(releaseUrl, `https://custom.example.org/user/repo/releases/tag/1.0.1`);
t.is(github.options.proxy, 'http://proxy:8080');
exec.restore();
});

Expand Down

0 comments on commit d411f8c

Please sign in to comment.