Skip to content

Commit

Permalink
ci: actions
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Oct 24, 2023
1 parent 1d2a669 commit 5c3e3da
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'monthly'
18 changes: 18 additions & 0 deletions .github/install-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Install dependencies"
description: "Prepare repository and all dependencies"

runs:
using: "composite"
steps:
- name: Set up pnpm
uses: pnpm/action-setup@v2

- name: Set up node
uses: actions/setup-node@v3
with:
cache: pnpm
node-version: 18

- name: Install dependencies
shell: bash
run: pnpm install
38 changes: 38 additions & 0 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Canary
on:
push:
branches: [main]
workflow_dispatch:

jobs:
canary:
name: Release canary
permissions: write-all
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Setup .npmrc file
uses: actions/setup-node@v3
with:
registry-url: 'https://registry.npmjs.org'

- name: Set version
run: |
npm --no-git-tag-version version 0.0.0
npm --no-git-tag-version version $(npm pkg get version | sed 's/"//g')-canary.$(date +'%Y%m%dT%H%M%S')
pnpm bun version:update
- name: Build
run: pnpm build

- name: Publish to npm
run: npm publish --tag canary
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
43 changes: 43 additions & 0 deletions .github/workflows/changesets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Changesets
on:
push:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
verify:
name: Verify
uses: ./.github/workflows/verify.yml
secrets: inherit

changesets:
name: Create pull request or publish
needs: verify
permissions: write-all
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Clone repository
uses: actions/checkout@v4
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Create version pull request or publish to npm
uses: changesets/action@v1
with:
title: 'chore: version packages'
commit: 'chore: version packages'
createGithubReleases: ${{ github.ref == 'refs/heads/main' }}
publish: pnpm changeset:publish
version: pnpm changeset:version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
14 changes: 14 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Pull Request
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
verify:
name: Verify
uses: ./.github/workflows/verify.yml
secrets: inherit
87 changes: 87 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Verify
on:
workflow_call:
workflow_dispatch:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Lint code
run: pnpm format && pnpm lint:fix

- name: Update package versions
run: pnpm version:update

- uses: stefanzweifel/git-auto-commit-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
commit_message: 'chore: format'
commit_user_name: 'github-actions[bot]'
commit_user_email: 'github-actions[bot]@users.noreply.github.com'

build:
name: Build
needs: lint
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Build
run: pnpm build

- name: Publint
run: pnpm test:build

- name: Check for unused files, dependencies, and exports
run: pnpm knip --production --ignore-internal

types:
name: Types
needs: lint
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Check types
run: pnpm typecheck

test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Run tests
run: pnpm test:cov

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
4 changes: 4 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
auto-install-peers=false
enable-pre-post-scripts=true
provenance=true
strict-peer-dependencies=false
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"preinstall": "npx only-allow pnpm",
"prepare": "pnpm simple-git-hooks",
"test": "vitest",
"test:cov": "vitest --coverage",
"test:cov": "vitest run --coverage",
"test:build": "publint --strict",
"typecheck": "tsc --noEmit",
"version:update": "bun .scripts/updateVersion.ts"
Expand Down Expand Up @@ -97,5 +97,8 @@
"simple-git-hooks": {
"pre-commit": "pnpm format && pnpm lint:fix"
},
"knip": {}
"knip": {
"entry": ["src/**/*.ts!", "src/exports/index.ts!"],
"project": [".scripts/**/*.ts"]
}
}
1 change: 0 additions & 1 deletion src/exports/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ test('exports', () => {
expect(Object.keys(Exports)).toMatchInlineSnapshot(`
[
"defineConfig",
"logger",
"loadEnv",
"version",
]
Expand Down

0 comments on commit 5c3e3da

Please sign in to comment.