Skip to content

Commit 83bb60e

Browse files
authored
Merge pull request #2 from Anshgrover23/add-workflows
add format and type check workflows
2 parents fa891b4 + a2fca20 commit 83bb60e

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

.github/workflows/bun-typecheck.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
2+
name: Type Check
3+
4+
on:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
branches: [main]
9+
10+
jobs:
11+
type-check:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Setup bun
18+
uses: oven-sh/setup-bun@v2
19+
with:
20+
bun-version: latest
21+
22+
- name: Install dependencies
23+
run: bun i
24+
25+
- name: Run type check
26+
run: bunx tsc --noEmit

.github/workflows/formatbot.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Format PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
7+
jobs:
8+
format:
9+
name: Format code
10+
runs-on: ubuntu-latest
11+
if: github.event.pull_request.draft == false
12+
13+
steps:
14+
- name: Determine if fork
15+
id: check_fork
16+
run: |
17+
if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
18+
echo "is_fork=false" >> $GITHUB_OUTPUT
19+
else
20+
echo "is_fork=true" >> $GITHUB_OUTPUT
21+
fi
22+
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
with:
26+
token: ${{ steps.check_fork.outputs.is_fork == 'true' && secrets.GITHUB_TOKEN || secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}
27+
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v3
30+
with:
31+
node-version: '20'
32+
33+
- name: Get @biomejs/biome version
34+
id: get-biome-version
35+
run: echo "BIOME_VERSION=$(node -p "require('./package.json').devDependencies['@biomejs/biome']")" >> $GITHUB_OUTPUT
36+
37+
- name: Install @biomejs/biome
38+
run: npm install @biomejs/biome@${{ steps.get-biome-version.outputs.BIOME_VERSION }}
39+
40+
- name: Run Formatter and autofix
41+
if: steps.check_fork.outputs.is_fork == 'false'
42+
run: npx @biomejs/biome format . --write
43+
44+
- name: Format Check (cannot autofix against forks)
45+
if: steps.check_fork.outputs.is_fork == 'true'
46+
run: npx @biomejs/biome format .
47+
48+
- name: Restore lock files
49+
if: steps.check_fork.outputs.is_fork == 'false'
50+
run: |
51+
git checkout -- *lock.json || true
52+
git checkout -- *.lock || true
53+
git checkout -- *.lockb || true
54+
55+
- name: Commit changes
56+
if: steps.check_fork.outputs.is_fork == 'false'
57+
uses: stefanzweifel/git-auto-commit-action@v4
58+
with:
59+
commit_message: "formatbot: Automatically format code"
60+
branch: ${{ github.head_ref }}
61+
commit_user_name: tscircuitbot
62+
commit_user_email: [email protected]
63+
commit_author: tscircuitbot <[email protected]>

lib/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log("Hello via Bun!");
1+
console.log("Hello via Bun!")

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"version": "0.0.1",
55
"type": "module",
66
"scripts": {
7-
"build": "tsup-node ./lib/index.ts --dts --format esm --sourcemap inline -d dist"
7+
"build": "tsup-node ./lib/index.ts --dts --format esm --sourcemap inline -d dist",
8+
"format": "biome format --write .",
9+
"format:check": "biome format .",
10+
"typecheck": "tsc --noEmit"
811
},
912
"devDependencies": {
1013
"@biomejs/biome": "^1.9.4",

0 commit comments

Comments
 (0)