Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: setup ci #4

Merged
merged 8 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"unicorn",
"prettier"
],
"parserOptions": {
"sourceType": "module",
"project": ["tsconfig.json"]
},
"overrides": [
{
"files": [
"src/**/*.ts"
],
"files": ["src/**/*.ts"],
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:jsonc/recommended-with-jsonc",
Expand All @@ -27,11 +29,6 @@
"plugin:@cspell/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": [
"tsconfig.json"
]
},
"rules": {
"prettier/prettier": "error",
"unicorn/switch-case-braces": "off",
Expand Down Expand Up @@ -62,18 +59,14 @@
"unicorn/prefer-event-target": "off",
"simple-import-sort/imports": "warn",
"simple-import-sort/exports": "warn",
"no-console": [
"error"
],
"no-console": ["error"],
"@typescript-eslint/no-unnecessary-type-constraint": "off",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-explicit-any": "error"
}
},
{
"files": [
"*.spec.ts"
],
"files": ["*.spec.ts", "*.test.ts"],
"env": {
"jest": true
},
Expand All @@ -85,16 +78,8 @@
}
},
{
"files": [
"metrics.helper.ts",
"*.module.ts"
],
"files": ["metrics.helper.ts", "*.module.ts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": [
"tsconfig.json"
]
},
"rules": {
"@typescript-eslint/no-magic-numbers": "off"
}
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PR 🚀

on:
push:
branches: [main]

jobs:
checks:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v1

- name: Install deps
run: bun install --frozen-lockfile

- name: Formatting
run: bun run prettier --check .

- name: Code style
run: bun run lint

- name: Tests
run: bun run coverage

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Build
run: bun run build
35 changes: 35 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PR 🚀

on:
pull_request:
branches: [main]

jobs:
checks:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v1

- name: Install deps
run: bun install --frozen-lockfile

- name: Formatting
run: bun run prettier --check .

- name: Code style
run: bun run lint

- name: Tests
run: bun run coverage

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Build
run: bun run build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/build
/coverage
/dist
/node_modules
/deploy
Expand Down
8 changes: 8 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# If tty is available, apply fix from https://github.com/typicode/husky/issues/968#issuecomment-1176848345
if sh -c ": >/dev/tty" >/dev/null 2>/dev/null; then exec >/dev/tty 2>&1; fi

# Heavy checks should only be done on staged files123
bun run lint-staged
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Welcome to the Digital Alchemy standalone automation repository!

## Purpose

This repository is designed to work both locally and deployed as a docker container. The container will interact with the HomeAssistant websocket to fulfill its automation goals.
This repository is designed to work both locally and deployed as a docker container. The container
will interact with the HomeAssistant websocket to fulfill its automation goals.

## Community

Expand Down Expand Up @@ -98,9 +99,11 @@ bun run publish

### Deploy

For now, this will be considered a manual step. Basically all you have to do is pull the image that you've just pushed.
For now, this will be considered a manual step. Basically all you have to do is pull the image that
you've just pushed.

> _**Note:** make sure that the same variables from `.env.dist` are passed into the container at runtime._
> _**Note:** make sure that the same variables from `.env.dist` are passed into the container at
> runtime._

## 📄 License

Expand Down
Binary file modified bun.lockb
Binary file not shown.
39 changes: 39 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
codecov:
require_ci_to_pass: true

coverage:
precision: 2
round: down
range: '70...100'

status:
patch:
default:
# basic
target: auto
threshold: 100% # don't require patch to have coverage per se
base: auto

project:
default:
# basic
target: auto
threshold: 5%
base: auto
flags:
- unit
paths:
- 'src'

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

comment:
layout: 'reach,diff,flags,files,tree'
behavior: default
require_changes: false
2 changes: 1 addition & 1 deletion cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "0.2"
version: '0.2'
ignorePaths: []
dictionaryDefinitions: []
dictionaries: []
Expand Down
41 changes: 34 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,36 @@
"version": "0.1.0",
"homepage": "https://docs.digital-alchemy.app/",
"description": "A quick start demo workspace to building code with @digital-alchemy. Tuned for supervised Home Assistant installs",
"license": "MIT",
"type": "module",
"scripts": {
"dev": "bun --watch src/main.ts",
"dev": "bun --hot --watch src/main.ts",
"build": "bun build src/main.ts --target=bun --outfile=dist/server.js",
"start": "bun run dist/server.js",
"lint": "eslint src/",
"lint:fix": "eslint --fix src/",
"type-writer": "type-writer"
"test": "vitest",
"coverage": "vitest --coverage",
"lint": "eslint src/ --ext .js,.ts,.tsx,.mts --max-warnings 0",
"format": "prettier --write .",
"fix": "bun run format && bun run lint --fix",
"typecheck": "tsc --noEmit",
"types": "bun --env-file .env type-writer",
"prepare": "husky install"
},
"trustedDependencies": [
"husky"
],
"lint-staged": {
"*.@(sh|bash|zsh|fish)": [
"shellcheck",
"git update-index --chmod=+x"
],
"*.@(ts|tsx|mts)": "bash -c 'bun tsc --skipLibCheck --noEmit'",
"*.@(ts|tsx|mts|js|jsx|mjs|cjs)": [
"bun eslint --max-warnings 0",
"vitest related --run"
],
"*.@(ts|tsx|mts|js|jsx|mjs|cjs|json|jsonc|json5|md|mdx|yaml|yml)": "prettier --write"
},
"license": "MIT",
"dependencies": {
"@digital-alchemy/core": "^0.3.11",
"@digital-alchemy/hass": "^0.3.14",
Expand All @@ -22,9 +43,10 @@
"@digital-alchemy/type-writer": "^0.3.8",
"@types/async": "^3.2.24",
"@types/bun": "^1",
"@types/node": "^20.12.7",
"@types/jest": "^29.5.12",
"@typescript-eslint/eslint-plugin": "7.6.0",
"@typescript-eslint/parser": "7.6.0",
"@vitest/coverage-v8": "^0.34.6",
"bun": "^1.1.4",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
Expand All @@ -37,10 +59,15 @@
"eslint-plugin-sonarjs": "^0.25.1",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"eslint-plugin-unicorn": "^52.0.0",
"eslint-plugin-vitest": "^0.3.25",
"husky": "^8.0.3",
"lint-staged": "^15.1.0",
"prettier": "^3.2.5",
"shellcheck": "^2.2.0",
"tsx": "^4.7.2",
"type-fest": "^4.15.0",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"vitest": "^1.5.0"
},
"volta": {
"node": "20.12.2",
Expand Down
23 changes: 23 additions & 0 deletions src/entity-list.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, it, vi } from 'vitest'

import { EntityList } from './entity-list'
describe('EntityList', () => {
it('compiles', () => {
const hass = {
socket: {
onConnect: vi.fn(),
onDisconnect: vi.fn(),
onUpdate: vi.fn(),
},
}
const logger = { debug: vi.fn(), info: vi.fn() }
const home_automation = {
helper: { doStuff: vi.fn(), theChosenEntity: { onUpdate: vi.fn() } },
}

// @ts-expect-error these are not fully fledged out as this is a quick example
EntityList({ hass, home_automation, logger })
expect(hass.socket.onConnect).toHaveBeenCalledTimes(1)
expect(home_automation.helper.theChosenEntity.onUpdate).toHaveBeenCalledTimes(1)
})
})
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"importHelpers": true,
"isolatedModules": true,
"lib": ["ESNext"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"noImplicitAny": false,
"noImplicitReturns": false,
"rootDir": "./src",
Expand Down
10 changes: 10 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'vitest/config'

export default {
test: {
coverage: {
provider: 'v8',
reporter: ['html', 'lcov', 'clover'],
},
},
}
Loading