Skip to content

Commit

Permalink
refactor(ci): abstract away install bs (#674)
Browse files Browse the repository at this point in the history
* refactor(ci): abstract away install bs

* feat(action.yaml): add GitHub Action workflow to install repository dependencies

This commit adds a new GitHub Action workflow file, `action.yaml`, which is responsible for installing the repository dependencies. The workflow consists of the following steps:

1. Setup Node: This step sets up the Node.js environment using the `actions/setup-node` action, with the specified Node version as `lts/*`.

2. Setup pnpm: This step uses the `pnpm/action-setup` action to set up pnpm, the package manager, with the latest version. The `run_install` option is set to `false` to skip the installation step.

3. Get pnpm store directory: This step retrieves the path to the pnpm store directory and stores it in the `STORE_PATH` variable.

4. Setup pnpm cache: This step uses the `actions/cache` action to cache the pnpm store directory. The cache key is generated based on the operating system and the hash of the

* chore(action.yaml): change shell to bash for installing dependencies

* chore(action.yaml): update pnpm/action-setup version to v2.4.0

* chore(action.yaml): add description to the action.yaml file

* chore(ci.yaml): remove unused steps in the CI workflow
chore(ci.yaml): update test step to use 'pnpm turbo run test' command

* chore(pnpm): add bun and wrangler as global dependencies
chore(ci): remove empty line in build_packages job
fix(deploy-api): remove 'npx' prefix from wrangler deploy command
chore(semantic-pull-requests): rename workflow to "Lint PR title"

* test: fix failing unit tests

* fix(action.yaml): add --recursive flag to pnpm install command
chore(action.yaml): install bun and wrangler globally

* chore(hono): update "@unkey/api" dependency to version "^0.13.1"

* chore(ci.yaml): update test job to build specific packages

The test job in the ci.yaml file has been updated to build specific packages based on the matrix configuration. This change allows for more granular testing of individual packages within the project.

* chore(ci.yaml): rename build job to test job
chore(ci.yaml): add build and test steps to the test job
chore(hono): update @unkey/api dependency to workspace version

* chore(ci.yaml): remove "api" from the list of jobs

* fix(ci.yaml): fix typo in package name, change "@unkey/key" to "@unkey/keys"
  • Loading branch information
chronark authored Dec 12, 2023
1 parent 472a84b commit 465f3d2
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 251 deletions.
37 changes: 37 additions & 0 deletions .github/actions/pnpm/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Install Repo
description: Install the ts toolchain and dependencies

runs:
using: "composite"

steps:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: lts/*

- uses: pnpm/[email protected]
with:
version: latest
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
shell: bash
run: |
pnpm install --recursive
npm i -g bun
npm i -g wrangler
19 changes: 4 additions & 15 deletions .github/workflows/changesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,12 @@ jobs:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Use PNPM
uses: pnpm/[email protected]
with:
version: latest

- name: Use Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20
cache: "pnpm"

- name: Install
run: pnpm install
uses: ./.github/actions/pnpm

- name: Build packages
run: pnpm turbo run build --filter='./packages/*'
run: pnpm turbo run build --filter='./packages/*'

- name: Create Version PR or Publish to NPM
id: changesets
uses: changesets/[email protected]
Expand All @@ -43,4 +32,4 @@ jobs:
publish: pnpm changeset publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
166 changes: 75 additions & 91 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Check Pull Request

on:
pull_request:
Expand Down Expand Up @@ -41,39 +41,18 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: '^1.20'
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Run Planetscale Proxy
run: |
go install github.com/mattrobenolt/ps-http-sim@latest
# start the proxy in the background
ps-http-sim -mysql-dbname=unkey -listen-addr=0.0.0.0 > pscale.logs &
- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 8
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install
uses: ./.github/actions/pnpm

- name: Install dependencies
run: |
pnpm install
npm i -g bun
- name: Install bun
run: npm i -g bun

- name: Load Schema into MySQL
run: pnpm drizzle-kit push:mysql
Expand Down Expand Up @@ -105,57 +84,43 @@ jobs:
- uses: actions/checkout@v3


- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: lts/*

- uses: pnpm/action-setup@v2
with:
version: latest
run_install: false

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

- name: Format
run: pnpm biome ci .

test_nuxt:

name: Test Nuxt
runs-on: ubuntu-latest

test:
strategy:
matrix:
package:
- "@unkey/billing"
- "@unkey/hash"
- "@unkey/keys"
- "@unkey/api"
- "@unkey/nextjs"
- "@unkey/hono"
- "@unkey/nuxt"

name: Test ${{matrix.package}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: 18
cache: "pnpm"

- name: 📦 Install dependencies
run: pnpm install
- name: Install
uses: ./.github/actions/pnpm

- name: Build
run: pnpm turbo run build --filter=${{matrix.package}}

- name: Test
run: pnpm turbo run test --filter=${{matrix.package}}



- name: 🧪 Test project
run: pnpm turbo test --filter=@unkey/nuxt
env:
NUXT_TEST_KEY: ${{secrets.NUXT_TEST_KEY}}

# tinybird:
#
Expand All @@ -169,7 +134,6 @@ jobs:
# tb_host: https://api.tinybird.co

build_packages:

strategy:
matrix:
package: ["@unkey/api", "@unkey/nextjs", "@unkey/hono", "@unkey/nuxt"]
Expand All @@ -179,32 +143,52 @@ jobs:
- uses: actions/checkout@v3


- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: lts/*
- name: Install
uses: ./.github/actions/pnpm

- uses: pnpm/action-setup@v2
with:
version: latest
run_install: false
- name: Build packages
run: pnpm turbo run build --filter=${{matrix.package}}

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install
run: pnpm install

- name: Build packages
run: pnpm turbo run build --filter=${{matrix.package}}
validate-pr-title:
permissions:
pull-requests: write
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
id: lint_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: marocchino/sticky-pull-request-comment@v2
# When the previous steps fails, the workflow would stop. By adding this
# condition you can continue the execution with the populated error message.
if: always() && (steps.lint_pr_title.outputs.error_message != null)
with:
header: pr-title-lint-error
message: |
Hey there and thank you for opening this pull request! 👋🏼
We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted.
Here is an example:
```
<type>[optional scope]: <description>
fix: I fixed something for Unkey
```
Details:
```
${{ steps.lint_pr_title.outputs.error_message }}
```
# Delete a previous comment when the issue has been resolved
- if: ${{ steps.lint_pr_title.outputs.error_message == null }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-title-lint-error
message: |
Thank you for following the naming conventions for pull request titles! 🙏
Loading

0 comments on commit 465f3d2

Please sign in to comment.