Skip to content

Commit

Permalink
ci: add release action to publish to NPM
Browse files Browse the repository at this point in the history
  • Loading branch information
matcastaneda committed Oct 22, 2024
1 parent 0175941 commit d4eb1c4
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/changeset-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// ORIGINALLY FROM CLOUDFLARE WRANGLER:
// https://github.com/cloudflare/wrangler2/blob/main/.github/changeset-version.js
import { exec } from 'child_process';

// This script is used by the `release.yml` workflow to update the version of the packages being released.
// The standard step is only to run `changeset version` but this does not update the lockfile.
// So we also run `pnpm install`, which does this update.
// This is a workaround until this is handled automatically by `changeset version`.
// See https://github.com/changesets/changesets/issues/421.
exec('npx changeset version');
exec('npm install');
64 changes: 64 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Release

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

env:
PNPM_VERSION: 9.12.2

jobs:
release:
name: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup & Install Node.js
uses: actions/setup-node@v3
with:
node-version-file: .node-version

- name: Install pnpm
uses: pnpm/action-setup@v4
id: pnpm-install
with:
version: ${{ env.PNPM_VERSION }}
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --ignore-scripts --frozen-lockfile

- name: Build the project
run: pnpm build

- name: Create Version PR or Publish to NPM
id: changesets
uses: changesets/[email protected]
with:
commit: 'chore(release): version packages'
title: 'chore(release): version packages'
version: node .github/changeset-version.js
publish: npx changeset publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
NODE_ENV: 'production'

0 comments on commit d4eb1c4

Please sign in to comment.