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
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions docs/recipes/README.md
Original file line number Diff line number Diff line change
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
64 changes: 64 additions & 0 deletions docs/recipes/github-actions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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`](https://docs.npmjs.com/creating-and-viewing-authentication-tokens) to publish your package to NPM registry and a [`GH_TOKEN`](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) to generate a release at GitHub.

## 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'
alissonperez marked this conversation as resolved.
Show resolved Hide resolved
- name: Install
run: npm ci
- name: Generate release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
alissonperez marked this conversation as resolved.
Show resolved Hide resolved
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
```

## 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.
1 change: 1 addition & 0 deletions docs/usage/ci-configuration.md
Original file line number Diff line number Diff line change
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