diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..3f252de --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,99 @@ +# 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: Configure Git + 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 + 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 examples + run: | + npm ci && cd examples + cd room-manager && npm i @fishjam-dev/js-server-sdk && cd .. + + # Commit changes + - name: Commit package.json and example's lockfile changes and create tag + run: | + git add package.json examples/room-manager/package-lock.json + 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: + tag_name: ${{ env.TAG_NAME }} + prerelease: ${{ startsWith(github.event.inputs.release-type, 'pre') }} + generate_release_notes: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index a947166..0672b51 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,11 @@ See [examples](https://github.com/fishjam-dev/js-server-sdk/tree/main/examples) We welcome contributions to this SDK. Please report any bugs or issues you find or feel free to make a pull request with your own bug fixes or features. +### Releasing new versions + +To release a new version of the package, go to `Actions` > `Release package` workflow and trigger it with the chosen release type. +The workflow will bump the package version in `package.json`, release the package to NPM, create a new git tag and a GitHub release. + ## Copyright and License Copyright 2024, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=fishjam)