Skip to content

Commit d0b304e

Browse files
committed
feat: get last release with git tags
- Remove the `getLastRelease` plugin type - Retrieve the last release based on Git tags - Create the next release Git tag before calling the `publish` plugins BREAKING CHANGE: Remove the `getLastRelease` plugin type The `getLastRelease` plugins will not be called anymore. BREAKING CHANGE: Git repository authentication is now mandatory The Git authentication is now mandatory and must be set via `GH_TOKEN`, `GITHUB_TOKEN`, `GL_TOKEN`, `GITLAB_TOKEN` or `GIT_CREDENTIALS` as described in [CI configuration](https://github.com/semantic-release/semantic-release/blob/caribou/docs/usage/ci-configuration.md#authentication).
1 parent fb0caa0 commit d0b304e

29 files changed

+1068
-1178
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ After running the tests the command `semantic-release` will execute the followin
8080
| Step | Description |
8181
|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
8282
| Verify Conditions | Verify all the conditions to proceed with the release with the [verify conditions plugins](docs/usage/plugins.md#verifyconditions-plugin). |
83-
| Get last release | Obtain last release with the [get last release plugin](docs/usage/plugins.md#getlastrelease-plugin). |
83+
| Get last release | Obtain the commit corresponding to the last release by analyzing [Git tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging). |
8484
| Analyze commits | Determine the type of release to do with the [analyze commits plugin](docs/usage/plugins.md#analyzecommits-plugin) based on the commits added since the last release. |
8585
| Verify release | Verify the release conformity with the [verify release plugins](docs/usage/plugins.md#verifyrelease-plugin). |
8686
| Generate notes | Generate release notes with the [generate notes plugin](docs/usage/plugins.md#generatenotes-plugin) for the commits added since the last release. |
87+
| Create Git tag | Create a Git tag corresponding the new release version |
8788
| Publish | Publish the release with the [publish plugins](docs/usage/plugins.md#publish-plugin). |
8889

8990
## Documentation

cli.js

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ module.exports = async () => {
1717
'Comma separated list of paths or packages name for the verifyConditions plugin(s)',
1818
list
1919
)
20-
.option('--get-last-release <path>', 'Path or package name for the getLastRelease plugin')
2120
.option('--analyze-commits <path>', 'Path or package name for the analyzeCommits plugin')
2221
.option(
2322
'--verify-release <paths>',

docs/extending/plugins-list.md

-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
- [publish](https://github.com/semantic-release/github#publish): Publish a [GitHub release](https://help.github.com/articles/about-releases)
88
- [@semantic-release/npm](https://github.com/semantic-release/npm)
99
- [verifyConditions](https://github.com/semantic-release/npm#verifyconditions): Verify the presence and the validity of the npm authentication and release configuration
10-
- [getLastRelease](https://github.com/semantic-release/npm#getlastrelease): Determine the last release of the package on the npm registry
1110
- [publish](https://github.com/semantic-release/npm#publish): Publish the package on the npm registry
1211

1312
## Official plugins
@@ -17,14 +16,12 @@
1716
- [publish](https://github.com/semantic-release/gitlab#publish): Publish a [GitLab release](https://docs.gitlab.com/ce/workflow/releases.html)
1817
- [@semantic-release/git](https://github.com/semantic-release/git)
1918
- [verifyConditions](https://github.com/semantic-release/git#verifyconditions): Verify the presence and the validity of the Git authentication and release configuration
20-
- [getLastRelease](https://github.com/semantic-release/git#getlastrelease): Determine the last release via Git tags on the repository
2119
- [publish](https://github.com/semantic-release/git#publish): Push a release commit and tag, including configurable files
2220
- [@semantic-release/changelog](https://github.com/semantic-release/changelog)
2321
- [verifyConditions](https://github.com/semantic-release/changelog#verifyconditions): Verify the presence and the validity of the configuration
2422
- [publish](https://github.com/semantic-release/changelog#publish): Create or update the changelog file in the local project repository
2523
- [@semantic-release/exec](https://github.com/semantic-release/exec)
2624
- [verifyConditions](https://github.com/semantic-release/exec#verifyconditions): Execute a shell command to verify if the release should happen
27-
- [getLastRelease](https://github.com/semantic-release/exec#getlastrelease): Execute a shell command to determine the last release
2825
- [analyzeCommits](https://github.com/semantic-release/exec#analyzecommits): Execute a shell command to determine the type of release
2926
- [verifyRelease](https://github.com/semantic-release/exec#verifyrelease): Execute a shell command to verifying a release that was determined before and is about to be published.
3027
- [generateNotes](https://github.com/semantic-release/exec#analyzecommits): Execute a shell command to generate the release note

docs/recipes/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
- [Travis CI with build stages](travis-build-stages.md)
77
- [GitLab CI](gitlab-ci.md)
88

9+
## Git hosted services
10+
- [Git authentication with SSH keys](git-auth-ssh-keys.md)
11+
912
## Package managers and languages

docs/recipes/git-auth-ssh-keys.md

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Git authentication with SSH keys
2+
3+
When using [environment variables](../usage/ci-configuration.md#authentication) to set up the Git authentication, the remote Git repository will automatically be accessed via [https](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#_the_http_protocols), independently of the [`repositoryUrl`](../usage/configuration.md#repositoryurl) format configured in the **semantic-release** [Configuration](../usage/configuration.md#configuration) (the format will be automatically converted as needed).
4+
5+
Alternatively the Git repository can be accessed via [SSH](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#_the_ssh_protocol) by creating SSH keys, adding the public one to your Git hosted account and making the private one available on the CI environment.
6+
7+
## Generating the SSH keys
8+
9+
In your local repository root:
10+
11+
```bash
12+
$ ssh-keygen -t rsa -b 4096 -C "<your_email>" -f git_deploy_key -N "<ssh_passphrase>"
13+
```
14+
15+
`your_email` must be the email associated with your Git hosted account. `ssh_passphrase` must be a long and hard to guess string. It will be used later.
16+
17+
This will generate a public key in `git_deploy_key.pub` and a private key in `git_deploy_key`.
18+
19+
## Adding the SSH public key to the Git hosted account
20+
21+
Step by step instructions are provided for the following Git hosted services:
22+
- [GitHub](#adding-the-ssh-public-key-to-github)
23+
24+
### Adding the SSH public key to GitHub
25+
26+
Open the `git_deploy_key.pub` file (public key) and copy the entire content.
27+
28+
In GitHub **Settings**, click on **SSH and GPG keys** in the sidebar, then on the **New SSH Key** button.
29+
30+
Paste the entire content of `git_deploy_key.pub` file (public key) and click the **Add SSH Key** button.
31+
32+
Delete the `git_deploy_key.pub` file:
33+
34+
```bash
35+
$ rm git_deploy_key.pub
36+
```
37+
38+
See [Adding a new SSH key to your GitHub account](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/) for more details.
39+
40+
## Adding the SSH private key to the CI environment
41+
42+
In order to be available on the CI environment, the SSH private key must be encrypted, committed to the Git repository and decrypted by the CI service.
43+
44+
Step by step instructions are provided for the following environments:
45+
- [Travis CI](#adding-the-ssh-private-key-to-travis-ci)
46+
- [Circle CI](#adding-the-ssh-private-key-to-circle-ci)
47+
48+
### Adding the SSH private key to Travis CI
49+
50+
Install the [Travis CLI](https://github.com/travis-ci/travis.rb#installation):
51+
52+
```bash
53+
$ gem install travis
54+
```
55+
56+
[Login](https://github.com/travis-ci/travis.rb#login) to Travis with the CLI:
57+
58+
```bash
59+
$ travis login
60+
```
61+
62+
Add the [environment](https://github.com/travis-ci/travis.rb#env) variable `SSH_PASSPHRASE` to Travis with the value set during the [SSH keys generation](#generating-the-ssh-keys) step:
63+
64+
```bash
65+
$ travis env set SSH_PASSPHRASE <ssh_passphrase>
66+
```
67+
68+
[Encrypt](https://github.com/travis-ci/travis.rb#encrypt) the `git_deploy_key` (private key) using a symmetric encryption (AES-256), and store the secret in a secure environment variable in the Travis environment:
69+
70+
```bash
71+
$ travis encrypt-file git_deploy_key
72+
```
73+
74+
The `travis encrypt-file` will encrypt the private key into the `git_deploy_key.enc` file and output in the console the command to add to your `.travis.yml` file. It should look like `openssl aes-256-cbc -K $encrypted_KKKKKKKKKKKK_key -iv $encrypted_VVVVVVVVVVVV_iv -in git_deploy_key.enc -out git_deploy_key -d`.
75+
76+
Copy this command to your `.travis.yml` file in the `before_install` step. Change the output path to write the unencrypted key in `/tmp`: `-out git_deploy_key` => `/tmp/git_deploy_key`. This will avoid to commit / modify / delete the unencrypted key by mistake on the CI. Then add the commands to decrypt the ssh private key and make it available to `git`:
77+
78+
```yaml
79+
before_install:
80+
# Decrypt the git_deploy_key.enc key into /tmp/git_deploy_key
81+
- openssl aes-256-cbc -K $encrypted_KKKKKKKKKKKK_key -iv $encrypted_VVVVVVVVVVVV_iv -in git_deploy_key.enc -out /tmp/git_deploy_key -d
82+
# Make sure only the current user can read the private key
83+
- chmod 600 /tmp/git_deploy_key
84+
# Create a script to return the passphrase environment variable to ssh-add
85+
- echo 'echo ${SSH_PASSPHRASE}' > /tmp/askpass && chmod +x /tmp/askpass
86+
# Start the authentication agent
87+
- eval "$(ssh-agent -s)"
88+
# Add the key to the authentication agent
89+
- DISPLAY=":0.0" SSH_ASKPASS="/tmp/askpass" setsid ssh-add /tmp/git_deploy_key </dev/null
90+
```
91+
92+
See [Encrypting Files](https://docs.travis-ci.com/user/encrypting-files) for more details.
93+
94+
Delete the local private key as it won't be used anymore:
95+
96+
```bash
97+
$ rm git_deploy_key
98+
```
99+
100+
Commit the encrypted private key and the `.travis.yml` file to your repository:
101+
102+
```bash
103+
$ git add git_deploy_key.enc .travis.yml
104+
$ git commit -m "ci(travis): Add the encrypted private ssh key"
105+
$ git push
106+
```
107+
108+
### Adding the SSH private key to Circle CI
109+
110+
First we encrypt the `git_deploy_key` (private key) using a symmetric encryption (AES-256). Run the following `openssl` command and *make sure to note the output which we'll need later*:
111+
112+
```bash
113+
$ openssl aes-256-cbc -e -p -in git_deploy_key -out git_deploy_key.enc -K `openssl rand -hex 32` -iv `openssl rand -hex 16`
114+
salt=SSSSSSSSSSSSSSSS
115+
key=KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
116+
iv =VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
117+
```
118+
119+
Add the following [environment variables](https://circleci.com/docs/2.0/env-vars/#adding-environment-variables-in-the-app) to Circle CI:
120+
- `SSL_PASSPHRASE` - the value set during the [SSH keys generation](#generating-the-ssh-keys) step.
121+
- `REPO_ENC_KEY` - the `key` (KKK) value from the `openssl` step above.
122+
- `REPO_ENC_IV` - the `iv` (VVV) value from the `openssl` step above.
123+
124+
Then add to your `.circleci/config.yml` the commands to decrypt the ssh private key and make it available to `git`:
125+
126+
```yaml
127+
version: 2
128+
jobs:
129+
coverage_test_publish:
130+
# docker, working_dir, etc
131+
steps:
132+
- run:
133+
# Decrypt the git_deploy_key.enc key into /tmp/git_deploy_key
134+
- openssl aes-256-cbc -d -K $REPO_ENC_KEY -iv $REPO_ENC_IV -in git_deploy_key.enc -out /tmp/git_deploy_key
135+
# Make sure only the current user can read the private key
136+
- chmod 600 /tmp/git_deploy_key
137+
# Create a script to return the passphrase environment variable to ssh-add
138+
- echo 'echo ${SSH_PASSPHRASE}' > /tmp/askpass && chmod +x /tmp/askpass
139+
# Start the authentication agent
140+
- eval "$(ssh-agent -s)"
141+
# Add the key to the authentication agent
142+
- DISPLAY=":0.0" SSH_ASKPASS="/tmp/askpass" setsid ssh-add /tmp/git_deploy_key </dev/null
143+
# checkout, restore_cache, run: yarn install, save_cache, etc.
144+
# Run semantic-release after all the above is set.
145+
```
146+
147+
The unencrypted key is written to `/tmp` to avoid to commit / modify / delete the unencrypted key by mistake on the CI environment.
148+
149+
Delete the local private key as it won't be used anymore:
150+
151+
```bash
152+
$ rm git_deploy_key
153+
```
154+
155+
Commit the encrypted private key and the `.circleci/config.yml` file to your repository:
156+
157+
```bash
158+
$ git add git_deploy_key.enc .circleci/config.yml
159+
$ git commit -m "ci(cicle): Add the encrypted private ssh key"
160+
$ git push
161+
```

docs/usage/ci-configuration.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,29 @@ See [CI configuration recipes](../recipes/README.md#ci-configurations) for more
88

99
## Authentication
1010

11-
Most **semantic-release** [plugins](plugins.md) require to set up authentication in order to publish to your package manager's registry or to access your project's Git hosted service. The authentication token/credentials have to be made available in the CI serice via environment variables.
11+
**semantic-release** requires push access to the project Git repository in order to create [Git tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging). The Git authentication can be set with one of the following environment variables:
1212

13-
See each plugin documentation for the environment variable to set up.
13+
| Variable | Description |
14+
|------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
15+
| `GH_TOKEN` or `GITHUB_TOKEN` | A GitHub [personal access token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line). |
16+
| `GL_TOKEN` or `GITLAB_TOKEN` | A GitLab [personal access token](https://docs.gitlab.com/ce/user/profile/personal_access_tokens.html). |
17+
| `GIT_CREDENTIALS` | [URL encoded basic HTTP Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication#URL_encoding) credentials). |
1418

15-
The default [npm](https://github.com/semantic-release/npm#environment-variables) and [github](https://github.com/semantic-release/github#environment-variables) plugins require the following environment variables:
19+
`GIT_CREDENTIALS` can be the Git username and password in the format `<username>:<password>` or a token for certain Git providers like [Bitbucket](https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html).
20+
21+
Alternatively the Git authentication can be set up via [SSH keys](../recipes/git-auth-ssh-keys.md).
22+
23+
Most **semantic-release** [plugins](plugins.md) require to set up authentication in order to publish to a package manager registry. The default [npm](https://github.com/semantic-release/npm#environment-variables) and [github](https://github.com/semantic-release/github#environment-variables) plugins require the following environment variables:
1624

1725
| Variable | Description |
1826
|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1927
| `NPM_TOKEN` | npm token created via [npm token create](https://docs.npmjs.com/getting-started/working_with_tokens#how-to-create-new-tokens).<br/>**Note**: Only the `auth-only` [level of npm two-factor authentication](https://docs.npmjs.com/getting-started/using-two-factor-authentication#levels-of-authentication) is supported. |
2028
| `GH_TOKEN` | GitHub authentication token.<br/>**Note**: Only the [personal token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line) authentication is supported. |
2129

30+
See each plugin documentation for the environment variables to set up.
31+
32+
The authentication token/credentials have to be made available in the CI service via environment variables.
33+
2234
See [CI configuration recipes](../recipes/README.md#ci-configurations) for more details on how to configure environment variables in your CI service.
2335

2436
## Automatic setup with `semantic-release-cli`

docs/usage/configuration.md

-12
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,6 @@ Define the list of [verify conditions plugins](plugins.md#verifyconditions-plugi
107107

108108
See [Plugins configuration](plugins.md#configuration) for more details.
109109

110-
### getLastRelease
111-
112-
Type: `String`, `Object`
113-
114-
Default: `['@semantic-release/npm']`
115-
116-
CLI argument: `--get-last-release`
117-
118-
Define the [get last release plugin](plugins.md#getlastrelease-plugin).
119-
120-
See [Plugins configuration](plugins.md#configuration) for more details.
121-
122110
### analyzeCommits
123111

124112
Type: `String`, `Object`

docs/usage/plugins.md

-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ Plugin responsible for verifying all the conditions to proceed with the release:
1010

1111
Default implementation: [npm](https://github.com/semantic-release/npm#verifyconditions) and [github](https://github.com/semantic-release/github#verifyconditions).
1212

13-
### getLastRelease plugin
14-
15-
Plugin responsible for determining the version of the package last release.
16-
17-
Default implementation: [@semantic-release/npm](https://github.com/semantic-release/npm#getlastrelease).
18-
1913
### analyzeCommits plugin
2014

2115
Plugin responsible for determining the type of the next release (`major`, `minor` or `patch`).

0 commit comments

Comments
 (0)