Publish SEO Master to npm #10
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: Publish SEO Master to npm | |
on: | |
workflow_dispatch: | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
# Set up Node.js environment | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "20" | |
cache: "npm" | |
# Add npm authentication for publishing | |
- name: Authenticate with npm | |
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
# Install dependencies | |
- name: Install dependencies | |
run: npm install | |
# Build the project | |
- name: Build the project | |
run: npm run build | |
# Verify version change in package.json | |
- name: Check if version has changed | |
id: version-check | |
run: | | |
NEW_VERSION=$(node -p "require('./package.json').version") | |
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV | |
# Publish to npm if it's a new version and a tagged release | |
- name: Publish to npm | |
run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
# Clean up after the build | |
- name: Clean node_modules | |
run: rm -rf node_modules |