Skip to content

Commit

Permalink
Add build and code-style CI (devhatt#198)
Browse files Browse the repository at this point in the history
* Add build and code-style CI

* ajust action trigger

* fix lock file

* fix install deps

* change pnpm version in install deps

* lock pnpm version and node version

* fix listed files

* fix listed files

* remove: test ci

* ajust codestyle and fix prettier files

* eof insert in .npmrc
  • Loading branch information
PiluVitu authored Apr 24, 2024
1 parent 91e9841 commit 604580c
Show file tree
Hide file tree
Showing 13 changed files with 1,850 additions and 1,584 deletions.
44 changes: 44 additions & 0 deletions .github/actions/install-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Reusable install deps
description: This workflow installs dependencies using PNPM and caches the store directory. It is meant to be used as a reusable workflow.
inputs:
NODE_VERSION:
description: 'The version of Node.js to use'
required: true
default: '20.x'
PNPM_VERSION:
description: 'The version of PNPM to use'
required: true
default: '8.x'
runs:
using: composite
steps:
- name: Code checkout
uses: actions/checkout@v4

- name: Use Node.js ${{ inputs.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.NODE_VERSION }}

- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: ${{ inputs.PNPM_VERSION }}
run_install: false

- name: Get PNPM store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
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 dependencies
shell: bash
run: pnpm install --frozen-lockfile -r
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build project

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

permissions:
contents: read
pull-requests: write

steps:
- name: Code Checkout
uses: actions/checkout@v3

- name: Setup deps
uses: ./.github/actions/install-deps

- name: Build
run: pnpm build
75 changes: 75 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Code Style

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
code-style:
runs-on: ubuntu-latest
name: code-style
steps:
- name: Code Checkout
uses: actions/checkout@v3

- name: Setup deps
uses: ./.github/actions/install-deps

- name: Get all changed files
id: all-changed-files
uses: tj-actions/changed-files@v41
with:
files: |
!pnpm-lock.yaml
- name: Run prettier in all files
if: steps.all-changed-files.outputs.any_changed == 'true'
env:
files: ${{ steps.all-changed-files.outputs.all_changed_files }}
run: pnpm exec prettier $files --check --ignore-unknown

- name: Get specific changed files
id: changed-files
uses: tj-actions/changed-files@v41
with:
files_yaml: |
code:
- '**.js'
- '**.ts'
- '**.tsx'
- '**.jsx'
- '**.mjs'
- '**.cjs'
style:
- '**.scss'
- name: Run stylelint in scss files
if: steps.changed-files.outputs.style_any_changed == 'true'
env:
files: ${{ steps.changed-files.outputs.style_all_changed_files }}
run: pnpm exec stylelint $files --allow-empty-input

- name: Run eslint in code files
if: steps.changed-files.outputs.code_any_changed == 'true'
env:
files: ${{ steps.changed-files.outputs.code_all_changed_files }}
run: pnpm exec eslint $files --report-unused-disable-directives --max-warnings 0 --output-file eslint_report.json --format json
continue-on-error: true

- name: Annotate Code Linting Results
if: steps.changed-files.outputs.code_any_changed == 'true'
uses: ataylorme/eslint-annotate-action@v2
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
report-json: 'eslint_report.json'

- name: Upload ESLint report
if: steps.changed-files.outputs.code_any_changed == 'true'
uses: actions/upload-artifact@v4
with:
name: eslint_report.json
path: eslint_report.json
53 changes: 53 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## PNPM related ###############
## https://pnpm.io/npmrc #
###############################

# Not always possible to be strict, but if it works for you, keep it to true.
# https://pnpm.io/next/npmrc#strict-peer-dependencies
strict-peer-dependencies=true

# https://pnpm.io/npmrc#auto-install-peers
auto-install-peers=true

# Helps locating duplicates, default in v8
# https://pnpm.io/next/npmrc#use-lockfile-v6
use-lockfile-v6=true

# Will fix duplicates due to peer-dependencies (>=7.29.0), default in v8
# https://github.com/pnpm/pnpm/releases/tag/v7.29.0
dedupe-peer-dependents=true

# Helps with peer-deps (>=7.23.0), default in v8
# https://pnpm.io/npmrc#resolve-peers-from-workspace-root
resolve-peers-from-workspace-root=true

# default to 'lowest' in v8.5.0
# set to highest for reasons specified here: https://github.com/pnpm/pnpm/issues/6463
# https://pnpm.io/npmrc#resolution-mode
resolution-mode=highest

# Default in 8.1.0 to fix issues with root/workspaces hoisting
# https://pnpm.io/npmrc#dedupe-direct-deps
dedupe-direct-deps=false

# Pinlock to exact version (default is '^')
# https://pnpm.io/npmrc#save-prefix
# see also how save-workspace-protocol affect this https://pnpm.io/npmrc#save-workspace-protocol
save-prefix=''

# Most of the time, you want to use the rolling protocol for monorepos
# https://pnpm.io/npmrc#save-workspace-protocol
save-workspace-protocol=rolling

# Specifies which exact Node.js version should be used for the project's runtime.
# pnpm will automatically install the specified version of Node.js and use it
# for running pnpm run commands or the pnpm node command.
# https://pnpm.io/npmrc#save-workspace-protocol
use-node-version=20.10.0

# Prevent contributors of your project from adding new incompatible dependencies
# This way, even if someone is using Node.js v16, they will not be able to install
# a new dependency that doesn't support Node.js v20.10.0
# https://pnpm.io/npmrc#use-node-version
node-version=20.10.0
engine-strict=true
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"private": true,
"version": "0.0.0",
"type": "module",
"engines": {
"node": "^20",
"pnpm": "^8"
},
"scripts": {
"dev": "vite",
"test": "vitest",
Expand Down
Loading

0 comments on commit 604580c

Please sign in to comment.