Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Add a GitHub workflow to automate release process (#58)
Browse files Browse the repository at this point in the history
## Description

The new workflow will be triggered by workflow dispatch. It bumps the
package version, publishes it to NPM and creates a new GitHub release.

Requirements before merging:
- [x] Add `NPM_TOKEN` GitHub secret to this repository
- [x] Create a (public) deploy key in repository settings and grant it
write access
- [x] Add the private key as a repo secret `DEPLOY_KEY`
- [x] Adjust the workflow to use `yarn`

## Motivation and Context

We want to release new versions via CI and standardize the way we do it
across other JS repos.

## How has this been tested?

Successfully published other JS clients releases.

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to
      not work as expected)

## Checklist:

- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.

---------

Co-authored-by: Karol Kąkol <[email protected]>
  • Loading branch information
balins and karkakol authored Jun 4, 2024
1 parent 2d73ce2 commit a56524b
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 102 deletions.
111 changes: 111 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# For details see: https://superface.ai/blog/npm-publish-gh-actions-changelog
name: Release package

on:
workflow_dispatch:
inputs:
release-type:
type: choice
required: true
description:
'The release type that will be passed to npm version command'
options:
[
'patch',
'minor',
'major',
'prepatch',
'preminor',
'premajor',
'prerelease',
]

jobs:
release:
name: Release
runs-on: ubuntu-latest

steps:
- name: Ensure running on main branch
if: github.ref_name != github.event.repository.default_branch
run: |
echo "This workflow must not be triggered on a branch other than main"
exit 1
# Checkout project repository
- name: Checkout
uses: actions/checkout@v4
with:
# Using deploy key to push changes to repository
# See: https://stackoverflow.com/a/76135647
ssh-key: ${{ secrets.DEPLOY_KEY }}

# Configure Git
- name: Git configuration
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
# Setup Node.js environment
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'
registry-url: https://registry.npmjs.org/

# Bump package version
# Use tag 'latest'
- name: Bump release version
if: startsWith(github.event.inputs.release-type, 'pre') != true
run: |
echo "TAG_NAME=$(npm --no-git-tag-version version $RELEASE_TYPE)" >> $GITHUB_ENV
echo "RELEASE_TAG=latest" >> $GITHUB_ENV
env:
RELEASE_TYPE: ${{ github.event.inputs.release-type }}

# Bump package pre-release version
# Use tag 'beta'
- name: Bump pre-release version
if: startsWith(github.event.inputs.release-type, 'pre')
run: |
echo "TAG_NAME=$(npm --no-git-tag-version --preid=beta version $RELEASE_TYPE)" >> $GITHUB_ENV
echo "RELEASE_TAG=beta" >> $GITHUB_ENV
env:
RELEASE_TYPE: ${{ github.event.inputs.release-type }}

- name: Build and bump package version in the example
run: |
yarn install --frozen-lockfile && cd example
yarn upgrade @fishjam-dev/react-native-client && cd ..
# Commit changes
- name: Commit changed files and create a new tag
run: |
git add package.json yarn.lock example/yarn.lock
git commit -m "Release ${{ env.TAG_NAME }}"
git tag ${{ env.TAG_NAME }}
# Publish version to public repository
- name: Publish
run: npm publish --verbose --access public --tag ${{ env.RELEASE_TAG }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

# Push repository changes
- name: Push changes to repository
run: |
git push origin && git push --tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Create GitHub release with autogenerated notes
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
name: 'Release ${{ env.TAG_NAME }}'
tag_name: ${{ env.TAG_NAME }}
prerelease: ${{ startsWith(github.event.inputs.release-type, 'pre') }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 12 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,20 @@ Our pre-commit hooks verify that the linter and tests pass when committing.

### Publishing to npm

#### Releasing via GitHub Actions

To release a new version of the package, navigate to `Actions` >
`Release package` workflow and trigger it with the chosen release type. The
workflow will update the package version in `package.json`, release the package
to NPM, create a new git tag and a GitHub release.

#### Releasing manually

We use [release-it](https://github.com/release-it/release-it) to make it easier
to publish new versions. It handles common tasks like bumping version based on
semver, creating tags and releases etc.
to publish new versions manually. It handles common tasks like bumping version
based on semver, creating tags and releases etc.

To publish new versions, run the following:
To publish a new version, run the following:

```sh
yarn release
Expand Down
Loading

0 comments on commit a56524b

Please sign in to comment.