Create automatic releases #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create a new release and a publish to GitHub Package Registry | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- 'main' | |
jobs: | |
release: | |
name: Create a new release | |
runs-on: ubuntu-latest | |
outputs: | |
tag: "${{ steps.version.outputs.tag }}" | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: 'Get Previous tag' | |
id: previoustag | |
uses: "WyriHaximus/github-action-get-previous-tag@v1" | |
env: | |
GITHUB_TOKEN: "${{ secrets.GH_PAT }}" | |
- name: 'Get next minor version' | |
id: semvers | |
uses: "WyriHaximus/github-action-next-semvers@v1" | |
with: | |
version: ${{ steps.previoustag.outputs.tag }} | |
- name: 'Set the next version to use' | |
id: version | |
run: | | |
if [[ "${{ steps.semvers.outputs.patch }}" == *.9 ]] | |
then | |
echo "tag=${{ steps.semvers.outputs.minor }}" >> $GITHUB_OUTPUT | |
else | |
echo "tag=${{ steps.semvers.outputs.patch }}" >> $GITHUB_OUTPUT | |
fi | |
- name: 'Create a tag and release' | |
uses: "softprops/action-gh-release@v1" | |
env: | |
GITHUB_TOKEN: "${{ secrets.GH_PAT }}" | |
with: | |
tag_name: "${{ steps.version.outputs.tag }}" | |
build: | |
needs: release | |
runs-on: ubuntu-latest | |
env: | |
VERSION: ${{ needs.release.outputs.tag }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- run: npm version "$VERSION" -m "Release $VERSION 📣" | |
- run: npm ci | |
- run: npm test | |
publish-gpr: | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
registry-url: https://npm.pkg.github.com/ | |
- run: npm ci | |
- name: Authenticate with the GitHub Package Registry | |
run: echo "//npm.pkg.github.com:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc | |
- run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} |