Skip to content

Commit

Permalink
chore: create github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemorales committed Feb 2, 2024
1 parent 3e38461 commit 7603022
Show file tree
Hide file tree
Showing 4 changed files with 382 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

const { exec } = require('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 pnpm-lock.yaml file.
// 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('bun run changeset version');
exec('bun install --frozen-lockfile');
121 changes: 121 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: ci

on: [pull_request]

jobs:
lint-title:
runs-on: ubuntu-latest
name: 🚨 Lint Pull Request title
steps:
- uses: amannn/action-semantic-pull-request@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

install-deps:
runs-on: ubuntu-latest
name: 📦 Install dependencies
steps:
- name: 🔑 Checkout Repository
uses: actions/checkout@v3

- name: 🔧 Install Bun
uses: oven-sh/setup-bun@v1
with:
version: latest

- name: ♻️ Cache node_modules
uses: actions/cache@v3
id: bun-cache
with:
path: "**/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
${{ runner.os }}-node-
if: steps.bun-cache.outputs.cache-hit != 'true'
- run: bun install --frozen-lockfile

lint-package:
runs-on: ubuntu-latest
name: 🚨 Check for errors
needs: install-deps
steps:
- name: 🔑 Checkout Repository
uses: actions/checkout@v3

- name: 🔧 Install Bun
uses: oven-sh/setup-bun@v1
with:
version: latest

- name: ♻️ Restore node_modules
uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/bun.lockb') }}

- name: ♻️ Restore ESLint Cache
uses: actions/cache@v3
id: eslint-cache
with:
path: .eslintcache
key: ${{ matrix.os }}-eslint-${{ hashFiles('**/*.ts', 'package.json', 'tsconfig.json') }}

- name: 📦 Install dependencies
if: steps.bun-cache.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile

- name: 🚨 Lint files
run: bun run lint

tests:
name: 🧪 Test package
runs-on: ubuntu-latest
needs: install-deps
steps:
- name: 🔑 Checkout Repository
uses: actions/checkout@v3

- name: 🔧 Install Bun
uses: oven-sh/setup-bun@v1
with:
version: latest

- name: ♻️ Restore node_modules
uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/bun.lockb') }}

- name: 📦 Install dependencies
if: steps.bun-cache.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile

- name: 🧪 Run tests
run: pnpm run test:ci

build:
name: 🏗️ Build package
runs-on: ubuntu-latest
needs: install-deps
steps:
- name: 🔑 Checkout Repository
uses: actions/checkout@v3

- name: 🔧 Install Bun
uses: oven-sh/setup-bun@v1
with:
version: latest

- name: ♻️ Load node_modules
uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/bun.lockb') }}

- name: 📦 Install dependencies
if: steps.bun-cache.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile

- name: 🏗️ Build package
run: bun run build
167 changes: 167 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
name: release to package managers

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

on:
push:
branches:
- main
# workflow_dispatch:
# inputs:
# forceGPR:
# description: Force GPR release
# type: boolean
# required: false
# default: false

jobs:
install-deps:
name: 📦 Install dependencies
if: github.repository == 'lukemorales/next-safe-navigation' && github.event_name != 'pull_request'
runs-on: ubuntu-latest
steps:
- name: 🔑 Checkout Repository
uses: actions/checkout@v3

- name: 🔧 Install Bun
uses: oven-sh/setup-bun@v1
with:
version: latest

- name: ♻️ Cache node_modules
uses: actions/cache@v3
id: bun-cache
with:
path: "**/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
${{ runner.os }}-node-
if: steps.bun-cache.outputs.cache-hit != 'true'
- run: bun install --frozen-lockfile

build:
name: 🏗️ Build package
runs-on: ubuntu-latest
needs: install-deps
steps:
- name: 🔑 Checkout Repository
uses: actions/checkout@v3

- name: 🔧 Install Bun
uses: oven-sh/setup-bun@v1
with:
version: latest

- name: 📦 Install dependencies
if: steps.bun-cache.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile

- name: 🚨 Check for errors
run: bun run lint

- name: 🧪 Run tests
run: bun run test:ci

- name: ⚒️ Build package
run: bun run build

release:
name: 🚀 Release to NPM
if: github.event.inputs.forceGPR != 'true'
runs-on: ubuntu-latest
needs: build
outputs:
published: ${{ steps.changesets.outputs.published }}
steps:
- name: 🔑 Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: 🔧 Install Bun
uses: oven-sh/setup-bun@v1
with:
version: latest

- name: ♻️ Load node_modules
uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/bun.lockb') }}

- name: ♻️ Load build files
uses: actions/cache@v3
with:
path: "**/dist"
key: ${{ runner.os }}-build-${{ hashFiles('**/bun.lockb') }}

- name: 🛠️ Setup Node for NPM
uses: actions/setup-node@v3
with:
node-version: latest
check-latest: true
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'

- name: 👤 Set git user
run: |
git config --global user.email "[email protected]"
git config --global user.name "Luke Morales"
- name: 🚀 Create Changesets Pull Request or Publish to NPM
id: changesets
uses: changesets/action@v1
with:
setupGitUser: false
title: "chore(changesets): bump package version"
commit: "chore: bump package version"
version: node .github/changeset-version.js
publish: bun run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

# gpr-release:
# name: 🚀 Release to GitHub Package Manager
# if: github.event.inputs.forceGPR == 'true' || needs.release.outputs.published == 'true'
# runs-on: ubuntu-latest
# needs: [build, release]
# permissions:
# contents: read
# packages: write
# steps:
# - name: 🔑 Checkout Repository
# uses: actions/checkout@v3

# - name: 🔧 Install PNPM
# uses: pnpm/[email protected]
# with:
# version: 7

# - name: ♻️ Load node_modules
# uses: actions/cache@v3
# with:
# path: "**/node_modules"
# key: ${{ runner.os }}-node-${{ hashFiles('**/bun.lockb') }}

# - name: 🛠️ Setup Node for GPR
# uses: actions/setup-node@v3
# with:
# node-version: '16.14.2'
# check-latest: true
# cache: 'pnpm'
# registry-url: 'https://npm.pkg.github.com'

# - name: 📦 Install dependencies
# if: steps.bun-cache.outputs.cache-hit != 'true'
# run: bun install --frozen-lockfile

# - name: ⚒️ Build package
# run: bun run build

# - name: 🚀 Publish to GPR
# run: pnpm publish
# env:
# NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
83 changes: 83 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: tests

on:
push:
branches:
- main

jobs:
install-deps:
runs-on: ubuntu-latest
name: 📦 Install dependencies
steps:
- name: 🔑 Checkout Repository
uses: actions/checkout@v3

- name: 🔧 Install Bun
uses: oven-sh/setup-bun@v1
with:
version: latest

- name: ♻️ Cache node_modules
uses: actions/cache@v3
id: bun-cache
with:
path: "**/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
${{ runner.os }}-node-
if: steps.bun-cache.outputs.cache-hit != 'true'
- run: bun install --frozen-lockfile

tests:
name: 🧪 Test package
runs-on: ubuntu-latest
needs: install-deps
steps:
- name: 🔑 Checkout Repository
uses: actions/checkout@v3

- name: 🔧 Install Bun
uses: oven-sh/setup-bun@v1
with:
version: latest

- name: ♻️ Load node_modules
uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/bun.lockb') }}

- name: 📦 Install dependencies
if: steps.bun-cache.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile

- name: 🧪 Run tests
run: bun run test:ci

build:
name: 🏗️ Build package
runs-on: ubuntu-latest
needs: install-deps
steps:
- name: 🔑 Checkout Repository
uses: actions/checkout@v3

- name: 🔧 Install Bun
uses: oven-sh/setup-bun@v1
with:
version: latest

- name: ♻️ Load node_modules
uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/bun.lockb') }}

- name: 📦 Install dependencies
if: steps.bun-cache.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile

- name: 🏗️ Build package
run: bun run build

0 comments on commit 7603022

Please sign in to comment.