Skip to content

Publish to NPM

Publish to NPM #7

Workflow file for this run

name: Publish to NPM
on:
push:
tags:
- 'v*'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run test -- --run
- name: Build
run: npm run build
- name: Set package version from tag
id: set-version
run: |
RAW_TAG="${GITHUB_REF_NAME}"
VERSION="${RAW_TAG#v}"
if [ -z "$VERSION" ]; then
echo "Unable to derive version from tag: $RAW_TAG" >&2
exit 1
fi
npm pkg set version="$VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Configure NPM registry
run: |
echo "//${{ secrets.NPM_REGISTRY_HOST || 'registry.npmjs.org' }}/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
npm config set registry ${{ secrets.NPM_REGISTRY_URL || 'https://registry.npmjs.org/' }}
- name: Publish to NPM
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
body: |
## πŸŽ‰ Release ${{ github.ref_name }}
Published to NPM: [${{ secrets.NPM_REGISTRY_URL || 'https://registry.npmjs.org/' }}](https://www.npmjs.com/package/@tml/tml-ui)
### Installation
```bash
npm install @tml/tml-ui@${{ steps.set-version.outputs.version }}
```
draft: false
prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'rc') }}