diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..2933c97 --- /dev/null +++ b/.github/workflows/publish.yml @@ -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 diff --git a/README.md b/README.md index 29d8453..5ad2956 100644 --- a/README.md +++ b/README.md @@ -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.