Skip to content

Commit

Permalink
Create release-to-npm.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohswedd authored Nov 30, 2024
1 parent 49f5cb1 commit bd9bf21
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/release-to-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Release to NPM

on:
release:
types: [published]

jobs:
release:
runs-on: ubuntu-latest

steps:
# Step 1: Check out the repository
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'npm'

# Step 3: Install dependencies
- name: Install dependencies
run: npm install

# Step 4: Sync package.json version with release
- name: Sync version with release tag
run: |
RELEASE_VERSION=${GITHUB_REF#refs/tags/}
echo "Updating package.json to version ${RELEASE_VERSION}"
npm version ${RELEASE_VERSION} --no-git-tag-version
# Step 5: Generate/update changelog
- name: Update changelog
run: npx standard-version --skip.tag --skip.commit

# Step 6: Authenticate with npm
- name: Authenticate with npm
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

# Step 7: Publish package to npm
- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

# Step 8: Push updated files back to repository
- name: Push updated files back
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add package.json CHANGELOG.md
git commit -m "chore(release): ${GITHUB_REF#refs/tags/} [skip ci]"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit bd9bf21

Please sign in to comment.