---
tags: CI
---
# Drone + Semantic Release
## Drone
```typescript=
//drone.yml
kind: pipeline
type: docker
name: ibus-ts
steps:
- name: build
image: node:12.14.0-buster
environment:
//environment variables
commands:
//npm install
- npm i --silent
//run semantic-release
- npx semantic-release
when:
branch:
- master
```
---
## Semantic Release
### 1. Setting environment variables
#### Authentications(for gitHub / bitbucket...)
* GITHUB_TOKEN
* GITLAB_TOKEN
* BITBUCKET_TOKEN
(bitbucket server)
* GIT_CREDENTIALS: \<username>:\<password>
(bitbucket use GIT_CREDENTIALS)
#### Setting Authentications in drone.yml
```typescript=
//drone.yml
//...
environment:
GIT_AUTHOR_NAME: <YOUR_GIT_NAME>
GIT_AUTHOR_EMAIL: <YOUR_GIT_NAME>@mail...
GIT_COMMITTER_NAME: <YOUR_GIT_NAME>
GIT_COMMITTER_EMAIL: <YOUR_GIT_NAME>@mail...
GIT_CREDENTIALS:
//YOUR_GIT_CREDENTIALS
//other environment variables...
//...
```
---
### 2. Write your .releaserc(.json/.yml)
#### Plugins
* @semantic-release/npm(default plugin):
Update version in package.json / package.lock
* @semantic-release/changelog(need install):
Auto create/update a changelog file
* @semantic-release/git(need install):
Auto push a release commit and add git tag after each release
#### releaserc.json
```javascript=
// .releaserc.json
{
"plugins": [
"@semantic-release/changelog",
["@semantic-release/npm", {
"npmPublish": false
}],
["@semantic-release/git", {
"message": "chore(release): ${nextRelease.version} [ci skip]\n\n${nextRelease.notes}"
}]
],
"repositoryUrl": "git@bitbucket.org:HARCHHI/drone-test.git",
"tagFormat": "${version}"
}
```
---
### 3. Install and run
* #### Install semantic-release and related plugins
```typescript=
//package.json
//...
"devDependencies": {
"@semantic-release/changelog": "^3.0.6",
"@semantic-release/git": "^7.0.18",
"@semantic-release/npm": "^5.3.4",
"semantic-release": "^15.14.0",
//...
},
```
* #### Git add * and push commit
Add changed files and push your commits with Commit Message Rules
[Detail Commit Message Rules](https://semantic-release.gitbook.io/semantic-release/#how-does-it-work)
[Or you can customize commit rules](https://github.com/semantic-release/commit-analyzer#options)
```default version: 1.0.0```
* Patch Release
fix(something...): ...
//update version to 1.0.1(last number)
* Feature Release
feat(something...): ...
//update version to 1.1.0(middle number)
* Breaking Release
perf(something...): ...
BREAKING CHANGE: ...
//update version to 2.0.0(first number)
and then Drone will run automatically.
---
Drone run CI

After Drone CI, Semantic-release run a new commit
(New commit including version and changelog updating is triggered by semantic-release command)

---
Done!