Skip to content

Commit

Permalink
docs(recipes): add GitHub actions to recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alisson R. Perez committed Oct 14, 2019
1 parent dc19dfa commit 9642d4a
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/recipes/README.md
Expand Up @@ -4,6 +4,7 @@
- [CircleCI 2.0 workflows](circleci-workflows.md)
- [Travis CI](travis.md)
- [GitLab CI](gitlab-ci.md)
- [GitHub Actions](github-actions.md)

## Git hosted services
- [Git authentication with SSH keys](git-auth-ssh-keys.md)
Expand Down
92 changes: 92 additions & 0 deletions docs/recipes/github-actions.md
@@ -0,0 +1,92 @@
# Using semantic-release with [GitHub Actions](https://help.github.com/en/categories/automating-your-workflow-with-github-actions)

## Environment variables

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.

If you want to push changes in your `package.json` to your `master` branch before generate release, what is recommended, you may need to add [`@semantic-release/git`](https://github.com/semantic-release/git). With this plugin your `GH_TOKEN` must have permission to push commits to `master` branch.

## 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.

**Note**: The publish pipeline must run a [Node >= 8 version](../support/FAQ.md#why-does-semantic-release-require-node-version--83).

### `.github/workflows/release.yml` configuration for Node projects

This example is a minimal configuration for [`semantic-release`](https://github.com/semantic-release/semantic-release) with a build running Node 12 when receives a new commit at `master` branch. See [Configuring a workflow](https://help.github.com/en/articles/configuring-a-workflow) for additional configuration options.

```yaml
name: Release
on:
push:
branches:
- master
jobs:
install:
name: "Generate release"
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@master
with:
node-version: '12.4.0'
- name: Install
run: npm i
- name: Generate release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
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}"
}
]
]
},
"devDependencies":{
"@semantic-release/git":"^7.0.16",
"semantic-release":"^15.13.18"
}
}
```
1 change: 1 addition & 0 deletions docs/usage/ci-configuration.md
Expand Up @@ -6,6 +6,7 @@ The `semantic-release` command must be executed only after all the tests in the
Here is a few example of the CI services that can be used to achieve this:
- [Travis Build Stages](https://docs.travis-ci.com/user/build-stages)
- [CircleCI Workflows](https://circleci.com/docs/2.0/workflows)
- [GitHub Actions](https://github.com/features/actions)
- [Codeship Deployment Pipelines](https://documentation.codeship.com/basic/builds-and-configuration/deployment-pipelines)
- [GitLab Pipelines](https://docs.gitlab.com/ee/ci/pipelines.html#introduction-to-pipelines-and-jobs)
- [Codefresh Pipelines](https://codefresh.io/docs/docs/configure-ci-cd-pipeline/introduction-to-codefresh-pipelines)
Expand Down

0 comments on commit 9642d4a

Please sign in to comment.