Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub actions to recipes #1317

Merged
merged 17 commits into from
Oct 23, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 24 additions & 32 deletions docs/recipes/github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

The [Authentication](../usage/ci-configuration.md#authentication) environment variables can be configured with [Secret variables](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables).

For this example, you'll need to setup a `NPM_TOKEN` to publish your package to NPM registry and a `GH_TOKEN` to generate a release at GitHub.

alissonperez marked this conversation as resolved.
Show resolved Hide resolved
## Node project configuration

[GitHub Actions](https://github.com/features/actions) supports [Workflows](https://help.github.com/en/articles/configuring-workflows) allowing to test on multiple Node versions and publishing a release only when all test pass.
Expand Down Expand Up @@ -40,51 +38,45 @@ jobs:
run: npx semantic-release
```

Anoter option is to use a trigger [`repository_dispatch`](https://help.github.com/en/articles/events-that-trigger-workflows#external-events-repository_dispatch) to have control when you want to generate a release only making a HTTP request, e.g.:

```yaml
name: Release
on: [repository_dispatch]
jobs:
# ...
```

So you just call (with your personal `GH_TOKEN` or from a generic/ci user):

```
$ curl -v -H "Accept: application/vnd.github.everest-preview+json" -H "Authorization: token ${GH_TOKEN}" https://api.github.com/repos/[org-name-or-username]/[repository]/dispatches -d '{ "event_type": "any" }'
```

And `Release` workflow will be triggered.

### `package.json` configuration

A `package.json` is required only for [local](../usage/installation.md#local-installation) **semantic-release** installation.

Package [`@semantic-release/git`](https://github.com/semantic-release/git) is optional but **recommended** to push your `package.json` version changes to master before generate GitHub release.

```json
{
"release":{
"plugins":[
"@semantic-release/commit-analyzer",
"@semantic-release/github",
"@semantic-release/npm",
"@semantic-release/release-notes-generator",
[
"@semantic-release/git",
{
"assets":[
"package.json"
],
"message":"chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
"@semantic-release/release-notes-generator"
]
},
alissonperez marked this conversation as resolved.
Show resolved Hide resolved
"devDependencies":{
"@semantic-release/git":"^7.0.16",
"semantic-release":"^15.13.18"
}
}
```

## Pushing `package.json` changes to `master` branch

If you want to keep your `package.json` updated in your code versioning with your released version you could use [`@semantic-release/git`](https://github.com/semantic-release/git) plugin. To use it you'll need to generate a `GH_TOKEN` with [permission to push changes to `master` branch](https://help.github.com/en/articles/enabling-branch-restrictions).

## Trigger semantic-release on demand

There is a way to trigger semantic-relase on demand, we can just use [`repository_dispatch`](https://help.github.com/en/articles/events-that-trigger-workflows#external-events-repository_dispatch) to have control when you want to generate a release only making a HTTP request, e.g.:

```yaml
name: Release
on: [repository_dispatch]
jobs:
# ...
```

So just call (with your personal `GH_TOKEN` or from a generic/ci user):

```
$ curl -v -H "Accept: application/vnd.github.everest-preview+json" -H "Authorization: token ${GH_TOKEN}" https://api.github.com/repos/[org-name-or-username]/[repository]/dispatches -d '{ "event_type": "any" }'
alissonperez marked this conversation as resolved.
Show resolved Hide resolved
```

And `Release` workflow will be triggered.