Skip to content

Publish

Publish #26

Workflow file for this run

name: Publish
on:
workflow_dispatch:
inputs:
bump:
type: choice
description: "Semver version"
required: true
options:
- patch
- minor
- major
jobs:
publish:
timeout-minutes: 15
runs-on: ubuntu-latest
permissions:
packages: write
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.12.1
registry-url: https://registry.npmjs.org/
- run: npm install
- name: Update versions
id: update-versions
uses: ./.github/actions/bump-version
with:
bump: ${{ inputs.bump }}
- uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Commit and push to main branch
if: github.ref_name == 'main'
run: |
git config --global user.name "GitHub Action"
git config --global user.email "username@users.noreply.github.com"
git commit -a -m "Update package.json to next ${{ inputs.bump }} version"
git tag -a ${{ steps.update-versions.outputs.version }} -m "Version ${{ steps.update-versions.outputs.version }}"
git push origin ${{ steps.update-versions.outputs.version }}
git push origin main
# Append -{{ ref_name }} to version number if not on production branch
- name: Add pre-release flag
if: github.ref_name != 'main'
run: |
full_version=$(echo "-${{ github.ref_name }}" | sed 's/\//-/g')
jq --arg v "${full_version}" '.version += $v' package.json > tmp.json
mv tmp.json package.json
- run: npm run build
- name: Publish to registry
if: github.ref_name == 'main'
run: npm publish
working-directory: dist/
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to registry pre-release
if: github.ref_name != 'main'
run: npm publish --tag ${{ github.ref_name }}
working-directory: dist/
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Release
uses: softprops/action-gh-release@v2
if: github.ref_name == 'main'
with:
tag_name: ${{ steps.update-versions.outputs.version }}
generate_release_notes: true
make_latest: "true"
prerelease: false
draft: false