Skip to content

Publish to NPM

Publish to NPM #1

Workflow file for this run

name: Publish to NPM
permissions:
contents: write
packages: write
pull-requests: write
id-token: write
on:
workflow_dispatch:
inputs:
release_type:
description: 'Release Type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- 'develop'
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
release_production:
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/trunk'
environment: production
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
- name: Configure git user name and email
run: |
git config user.name "10up Bot"
git config user.email "pr@10up.com"
- name: Install all npm packages
run: npm ci
- name: npm update version and release
run: |
npm version ${{ github.event.inputs.release_type }}
npm publish --provenance --access public
- name: push release commit to repo
run: git push
release_next:
if: github.event_name == 'pull_request' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
- name: Install all npm packages
run: npm ci
- name: Build package
run: npm run build
- name: Configure git user name and email
run: |
git config user.name "10up Bot"
git config user.email "pr@10up.com"
- name: npm update version and release
run: |
npm version prerelease --preid=next
npm publish --tag next --provenance --access public
- name: push release commit to repo
run: git push
release_testing:
if: github.event_name == 'pull_request' && github.event.pull_request.merged != true
environment: testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
- name: Configure git user name and email
run: |
git config user.name "10up Bot"
git config user.email "pr@10up.com"
- name: Install all npm packages
run: npm install
- name: npm update version and release
run: |
npm version prerelease --preid=testing-${{ github.event.number}}.${{ github.run_number}}
npm publish --tag testing-${{ github.event.number}} --provenance --access public
- uses: mshick/add-pr-comment@v2
with:
message: |
:tada: A new testing version of this package has been published to NPM. You can install it with `npm install @10up/block-components@testing-${{ github.event.number}}`