Skip to content

patch workflow

patch workflow #1

Workflow file for this run

name: Publish to npm
on:
push:
tags:
- 'v*.*.*' # Matches version tags like v1.0.0, v2.1.3, etc.
jobs:
publish:
name: Publish to npm
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for tags
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build project
run: npm run build
- name: Extract version from tag
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: Update package.json version
run: |
npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version
echo "Updated package.json version to ${{ steps.get_version.outputs.version }}"
- name: Verify package.json version matches tag
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
TAG_VERSION="${{ steps.get_version.outputs.version }}"
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
echo "Error: package.json version ($PACKAGE_VERSION) does not match tag version ($TAG_VERSION)"
exit 1
fi
echo "Version verification successful: $PACKAGE_VERSION"
- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: Release ${{ steps.get_version.outputs.version }}
body: |
## Release ${{ steps.get_version.outputs.version }}
Automated release from GitHub Actions.
### Installation
```bash
npm install simbrief-api@${{ steps.get_version.outputs.version }}
```
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}