Skip to content

Commit

Permalink
ci: add checks to actions and husky pre-commit (#55)
Browse files Browse the repository at this point in the history
* ci: prettier_action

* fix: do not run on ci on pr edited

* fix: use strict

* docs: mention husky in readme

---------

Co-authored-by: Nicolai Rosdahl Tellefsen <niccofyren@gmail.com>
  • Loading branch information
olemathias and niccofyren authored Oct 11, 2024
1 parent 93f4499 commit ec1ed3e
Show file tree
Hide file tree
Showing 8 changed files with 335 additions and 7 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,31 @@ name: ci

on:
pull_request:
types: [opened, reopened, synchronize, edited]
types: [opened, reopened, synchronize]
workflow_call:
workflow_dispatch:

jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Astro check
run: pnpm astro check
- name: Prettier check
run: pnpm exec prettier --check .
build-test:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npx lint-staged
pnpm astro check
9 changes: 6 additions & 3 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ For basic installation of backend repo see [backend repo](https://github.com/gat
1. Clone this repo
2. Make sure you have the correct node version installed (`nvm use` then `nvm install`)
3. Run `pnpm install`
4. Run `pnpm dev`
5. Frontend should now be available on `localhost:4321` serving content from `https://dev.tg.no`
4. Run `pnpm prepare` # Setup Husky for pre-commit
5. Run `pnpm dev`
6. Frontend should now be available on `localhost:4321` serving content from `https://dev.tg.no`

We use [husky](https://typicode.github.io/husky/) pre-commit for making sure all code conforms to the same formatting. This happens automatically on commit after this first time setup, if it doesn't work try a fresh `pnpm install`

## Using local backend

Expand All @@ -24,7 +27,7 @@ Same procedure as above, but with a few extra steps:

## Using production backend

Identical to using local backend section above, but use `https://prod.tg.no/`/`https://tg.no/` instead of `http://localhost:8000/`
Identical to using local backend section above, but use `https://www.tg.no/` instead of `http://localhost:8000/`

## Common issues

Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
COPY package.json pnpm-lock.yaml /app/
WORKDIR /app
RUN pnpm install --prod
# --ignore-scripts is used to prevent https://github.com/pnpm/pnpm/issues/7068
RUN pnpm install --prod --ignore-scripts
COPY . /app
RUN pnpm build

Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"start": "astro dev",
"build": "astro check && export $(grep -v '^\\s*$\\|^\\s*\\#' .env.runtime) && astro build",
"preview": "astro preview",
"astro": "astro"
"astro": "astro",
"prepare": "husky"
},
"dependencies": {
"@astrojs/check": "^0.9.4",
Expand All @@ -22,7 +23,12 @@
},
"devDependencies": {
"@types/dompurify": "^3.0.5",
"husky": ">=7",
"lint-staged": ">=10",
"prettier": "^3.3.3",
"prettier-plugin-astro": "^0.14.1"
},
"lint-staged": {
"*.{js,ts,mjs,css,md,astro,yaml,json}": "prettier --write"
}
}
Loading

0 comments on commit ec1ed3e

Please sign in to comment.