Skip to content

Commit

Permalink
chore: 🔧 add publish workflow
Browse files Browse the repository at this point in the history
Added GitHub Actions for publishing on every new release
  • Loading branch information
andrewdyer committed Aug 6, 2024
1 parent 84755cd commit f2dc739
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Publish Package to npmjs

on:
release:
types: [published]

jobs:
build:
if: env.PUBLISH_ENABLED == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org/'

- name: Configure npm authentication
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

- name: Install dependencies
run: npm ci

- name: Publish package
run: npm publish --provenance --access public
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,29 @@ Publishes the package to the local Yalc store for local development.
### `npm run yalc:push`

Publishes updates to the package in the local Yalc store and pushes the changes to linked projects.

## Publishing

This repository is configured to publish the package to npm, every time you publish a new release, using GitHub Actions.

### Enabling Publishing

Publishing is controlled by the `PUBLISH_ENABLED` environment variable. To enable publishing, you need to set this variable to true. You can set environment variables in your repository settings:

1. Go to your repository on GitHub.
2. Click on Settings.
3. Navigate to Secrets and variables > Actions.
4. Add a new repository variable named `PUBLISH_ENABLED` and set its value to true.

### Creating and Using an npm Token

To publish the package, you need an npm token:

1. Log in to your npm account.
2. Navigate to Access Tokens in your npm account settings.
3. Generate a new token with the Automation option, especially if you have 2FA enabled.
4. Add the token to your GitHub repository secrets:
- Go to Settings > Secrets and variables > Actions.
- Add a new secret named `NPM_TOKEN` and paste your npm token.

By configuring these settings, the GitHub Actions workflow will publish your package to npm when you create a new release.

0 comments on commit f2dc739

Please sign in to comment.