Skip to content

Commit

Permalink
Move linting and typechecking to GitHub Actions (#734)
Browse files Browse the repository at this point in the history
* Add types of `wasm` package to repository
* Extend dev container by local GitHub Actions runner
* Remove linting and typechecking from Dockerfile
* Move only all linting and typechecking packages to `devDependencies`
* Do not install development dependencies in Dockerfile pipeline
* Shorten global yarn scripts
* Enable only specific build scripts

Signed-off-by: Marvin A. Ruder <[email protected]>
  • Loading branch information
marvinruder authored Nov 21, 2023
1 parent 4cd8828 commit 240f2ab
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 69 deletions.
12 changes: 6 additions & 6 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ENV RUSTUP_HOME="/usr/local/rustup"
RUN \
--mount=type=cache,target=/var/cache/apk \
apk add \
bash \
curl \
docker-cli \
docker-zsh-completion \
git \
Expand All @@ -22,18 +24,15 @@ RUN \
zsh-syntax-highlighting \
zsh-theme-powerlevel10k

# Install required tools and libraries for Rust
# Install required tools and libraries for Rust and setup shell and more tools
RUN \
--mount=type=cache,target=/var/cache/apk \
--mount=type=cache,target=/usr/local/cargo/registry \
apk add binaryen pkgconfig musl-dev openssl-dev && \
RUSTFLAGS="-Ctarget-feature=-crt-static" cargo install wasm-bindgen-cli && \
rustup target add wasm32-unknown-unknown && \
rustup component add rust-analyzer && \
wget -O - https://rustwasm.github.io/wasm-pack/installer/init.sh | sh

# Setup shell
RUN \
wget -O - https://rustwasm.github.io/wasm-pack/installer/init.sh | sh && \
echo "PS1='\[\e[33m\]\u@\h\[\e[0m\]:\[\e[34m\]\w\[\e[0m\] \$([[ \$? == 0 ]] && echo -e \"\\[\\e[32m\\]\" || echo -e \"\\[\\e[31m\\]\")➜\[\e[0m\] '" >> /etc/profile && \
echo "alias ls='ls --color=auto'" >> /etc/profile && \
echo "alias ll='ls -alF'" >> /etc/profile && \
Expand All @@ -47,4 +46,5 @@ RUN \
echo '[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"' >> /root/.zshrc && \
echo '[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' >> /root/.zshrc && \
find /usr/share/zsh/plugins/zsh-*/zsh-*.zsh | grep -v .plugin.zsh | sed 's/^/source /' >> /root/.zshrc && \
wget -O /tmp/rust-analyzer-no-server.vsix https://github.com/rust-lang/rust-analyzer/releases/latest/download/rust-analyzer-no-server.vsix
wget -O /tmp/rust-analyzer-no-server.vsix https://github.com/rust-lang/rust-analyzer/releases/latest/download/rust-analyzer-no-server.vsix && \
curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | bash
2 changes: 1 addition & 1 deletion .devcontainer/postCreate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
corepack enable
yarn
yarn build:wasm
yarn workspace @rating-tracker/backend prisma:generate
yarn prisma:generate
yarn sdks base
11 changes: 1 addition & 10 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: "CodeQL"

on:
push:
on: [push]

jobs:
analyze:
Expand All @@ -11,23 +10,15 @@ jobs:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ["javascript"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

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

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
45 changes: 45 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "GitHub Actions"

on: [push]

jobs:
eslint:
name: ESLint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Read Node.js version
run: echo "nodeVersion=$(cat ./docker/Dockerfile-ci | grep 'FROM node' | head -n 1 | grep -o '[0-9]*\.[0-9]*\.[0-9]*')" >> $GITHUB_OUTPUT
id: nodeVersion
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ steps.nodeVersion.outputs.nodeVersion }}
- name: Setup yarn
run: |
corepack enable
yarn --immutable --mode=skip-build
yarn prisma:generate
- name: Run ESLint
run: yarn workspaces foreach -Apv -j unlimited run lint
typecheck:
name: TypeScript
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Read Node.js version
run: echo "nodeVersion=$(cat ./docker/Dockerfile-ci | grep 'FROM node' | head -n 1 | grep -o '[0-9]*\.[0-9]*\.[0-9]*')" >> $GITHUB_OUTPUT
id: nodeVersion
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ steps.nodeVersion.outputs.nodeVersion }}
- name: Setup yarn
run: |
corepack enable
yarn --immutable --mode=skip-build
yarn prisma:generate
- name: Run TypeScript
run: yarn workspaces foreach -Apv -j unlimited run typecheck
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ packages/backend/test/*.sql
# Rust
packages/wasm/*
!packages/wasm/package.json
!packages/wasm/wasm.d.ts
wasm/target

# misc
Expand Down
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
defaultSemverRangePrefix: ""

enableScripts: false

networkConcurrency: 1024

packageExtensions:
Expand Down
4 changes: 1 addition & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ node('rating-tracker-build') {
// Change config files for use in CI, copy global cache to workspace and install dependencies
sh """
echo \"globalFolder: /workdir/cache/yarn/global\" >> .yarnrc.yml
mkdir -p \$HOME/.cache/yarn/global \$HOME/.cache/rating-tracker ./cache/yarn/global ./cache/rating-tracker
mkdir -p \$HOME/.cache/yarn/global ./cache/yarn/global
cp -arln \$HOME/.cache/yarn/global ./cache/yarn || :
cp -arlf \$HOME/.cache/rating-tracker ./cache || :
docker build $DOCKER_CI_FLAGS --target=yarn .
"""
}
Expand Down Expand Up @@ -140,7 +139,6 @@ node('rating-tracker-build') {
stage ('Cleanup') {
// Upload cache to external storage and remove build artifacts
sh """#!/bin/bash
cp -arlf ./cache/rating-tracker \$HOME/.cache
cp -arln ./cache/yarn \$HOME/.cache
putcache
PGPORT=$PGPORT REDISPORT=$REDISPORT docker compose -p rating-tracker-test-job$JOB_ID -f packages/backend/test/docker-compose.yml down -t 0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ An environment with all tools required for developing Rating Tracker and the ser

- Clone the repository and open it in Visual Studio Code. When prompted, select “Reopen in Container”. This will create a Docker container with all required tools, recommended extensions and dependencies installed.
- Check your environment. SSL Certificates and the Redis ACL file must be provided beforehand, and a Signal account must be created before starting the server (see [section Setup steps](#setup-steps) for details). The NGINX configuration might require adjustment to your situation.
- Run `yarn workspace @rating-tracker/backend prisma:migrate:deploy` to initialize the PostgreSQL database.
- Run `yarn prisma:migrate:deploy` to initialize the PostgreSQL database.
- Run `yarn dev` to start the backend server as well as the Vite frontend development server.

Environment variables not included in the development container configuration can easily be defined in an `.env` file:
Expand Down
30 changes: 3 additions & 27 deletions docker/Dockerfile-ci
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ RUN \
--mount=type=bind,source=packages/frontend/package.json,target=packages/frontend/package.json \
--mount=type=bind,source=packages/wasm/package.json,target=packages/wasm/package.json \
corepack enable && \
yarn --immutable
yarn workspaces focus -A --production

# Generate Prisma client
COPY packages/backend/prisma ./packages/backend/prisma
Expand All @@ -64,28 +64,7 @@ RUN \
--mount=type=bind,source=.yarnrc.yml,target=.yarnrc.yml \
--mount=type=bind,source=yarn.lock,target=yarn.lock \
--mount=type=bind,source=packages/backend/package.json,target=packages/backend/package.json \
yarn workspace @rating-tracker/backend prisma:generate


FROM node:21.2.0-alpine as validator
ENV FORCE_COLOR true

WORKDIR /workdir

# Run validations
RUN \
--mount=type=bind,target=.,rw \
--mount=type=bind,from=wasm,source=/workdir/pkg,target=packages/wasm \
--mount=type=bind,from=yarn,source=/usr/local/lib/node_modules/corepack,target=/usr/local/lib/node_modules/corepack \
--mount=type=bind,from=yarn,source=/workdir/.yarn,target=.yarn \
--mount=type=bind,from=yarn,source=/workdir/cache/yarn,target=cache/yarn \
--mount=type=bind,from=yarn,source=/workdir/.pnp.cjs,target=.pnp.cjs \
--mount=type=bind,from=yarn,source=/workdir/.pnp.loader.mjs,target=.pnp.loader.mjs \
--mount=type=bind,from=yarn,source=/workdir/packages/backend/prisma/client,target=packages/backend/prisma/client \
corepack enable && \
mkdir -p /root/.cache && \
cp -ar ./cache/rating-tracker /root/.cache && \
yarn validate
yarn prisma:generate


FROM node:21.2.0-alpine as test
Expand Down Expand Up @@ -136,7 +115,7 @@ RUN \
# Bundle frontend and backend
yarn build && \
# Create CommonJS module containing log formatter configuration
yarn workspace @rating-tracker/backend build:logFormatterConfig && \
yarn build:logFormatterConfig && \
# Parse backend bundle for correctness and executability in Node.js
/bin/sh -c 'cd packages/backend && EXIT_AFTER_READY=1 PORT_OFFSET=4096 node -r ./test/env.ts dist/server.mjs' && \
# Create directories for target container and copy only necessary files
Expand Down Expand Up @@ -166,9 +145,6 @@ WORKDIR /coverage
# Copy coverage reports from test stage
COPY --from=test /coverage /coverage

# Add eslint and TypeScript cache
COPY --from=validator /root/.cache/rating-tracker /cache/rating-tracker

# Add yarn cache
COPY --from=yarn /workdir/cache/yarn /cache/yarn

Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
"packages/*"
],
"scripts": {
"dev": "conc --kill-others \"yarn workspace @rating-tracker/backend dev:run\" \"yarn workspace @rating-tracker/backend dev:watch\" \"yarn workspace @rating-tracker/frontend dev:vite\" -n \",≫,\" -p \"{name}\" -c #339933,#FFCF00,#61DAFB --timings",
"dev": "conc --kill-others \"yarn dev:run\" \"yarn dev:watch\" \"yarn dev:vite\" -n \",≫,\" -p \"{name}\" -c #339933,#FFCF00,#61DAFB --timings",
"test": "yarn workspaces foreach -Apv -j unlimited run test",
"build": "yarn workspaces foreach -Apv -j unlimited run build",
"build:wasm": "wasm-pack build -s rating-tracker -d ../packages/wasm --release wasm && sed -E -i.bak 's/\"module\": \"([A-Za-z0-9\\-\\.]+)\",/\"main\": \"\\1\",\\\n \"module\": \"\\1\",/g ; s/^}$/}\\\n/' packages/wasm/package.json && rm packages/wasm/package.json.bak",
"validate": "conc \"yarn workspaces foreach -Apv -j unlimited run typecheck\" \"yarn workspaces foreach -Apv -j unlimited run lint\" -n \"ﯤ,\" -p \"{name}\" -c #3178C6,#4B32C3",
"fix:swagger": "mkdir -p packages/backend/dist/public/api-docs && cp .yarn/unplugged/swagger-ui-dist-*/node_modules/swagger-ui-dist/swagger-ui{.css,-bundle.js,-standalone-preset.js} packages/backend/dist/public/api-docs/"
},
"packageManager": "[email protected]",
"dependencies": {
"concurrently": "8.2.2"
},
"devDependencies": {
"@yarnpkg/sdks": "3.1.0",
"concurrently": "8.2.2",
"eslint": "8.54.0",
"prettier": "3.1.0",
"typescript": "5.3.2"
Expand All @@ -36,6 +38,12 @@
"whatwg-url": "14.0.0"
},
"dependenciesMeta": {
"@prisma/engines": {
"built": true
},
"prisma": {
"built": true
},
"swagger-ui-dist": {
"unplugged": true
}
Expand Down
18 changes: 9 additions & 9 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
"@prisma/client": "5.6.0",
"@rating-tracker/commons": "workspace:*",
"@simplewebauthn/server": "8.3.5",
"@vitest/coverage-v8": "0.34.6",
"@xmldom/xmldom": "0.8.10",
"@yarnpkg/pnpify": "4.0.1",
"axios": "1.6.2",
"chalk": "5.3.0",
"concurrently": "8.2.2",
"cookie-parser": "1.4.6",
"cron": "3.1.6",
"esbuild": "0.19.7",
"express": "4.18.2",
"express-async-errors": "3.1.1",
"express-openapi-validator": "5.1.1",
Expand All @@ -40,11 +44,15 @@
"luxon": "3.4.4",
"pino": "8.16.2",
"pino-pretty": "10.2.3",
"prisma": "5.6.0",
"redis": "4.6.11",
"redis-om": "0.4.3",
"response-time": "2.3.2",
"supertest": "6.3.3",
"swagger-ui-dist": "5.10.0",
"swagger-ui-express": "5.0.0",
"vite": "5.0.2",
"vitest": "0.34.6",
"xpath-ts2": "1.4.2"
},
"devDependencies": {
Expand All @@ -57,21 +65,13 @@
"@types/swagger-ui-express": "4.1.6",
"@typescript-eslint/eslint-plugin": "6.12.0",
"@typescript-eslint/parser": "6.12.0",
"@vitest/coverage-v8": "0.34.6",
"@yarnpkg/pnpify": "4.0.1",
"concurrently": "8.2.2",
"esbuild": "0.19.7",
"eslint": "8.54.0",
"eslint-config-google": "0.14.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-jsdoc": "46.9.0",
"eslint-plugin-prettier": "5.0.1",
"prettier": "3.1.0",
"prisma": "5.6.0",
"supertest": "6.3.3",
"typescript": "5.3.2",
"vite": "5.0.2",
"vitest": "0.34.6"
"typescript": "5.3.2"
}
}
10 changes: 6 additions & 4 deletions packages/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@
"lint": "eslint --color --cache --cache-location $HOME/.cache/rating-tracker/commons.eslintcache --cache-strategy content --max-warnings 0 --ext .ts src/",
"lint:fix": "yarn lint --fix"
},
"dependencies": {
"@vitest/coverage-v8": "0.34.6",
"vite": "5.0.2",
"vitest": "0.34.6"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "6.12.0",
"@typescript-eslint/parser": "6.12.0",
"@vitest/coverage-v8": "0.34.6",
"eslint": "8.54.0",
"eslint-config-google": "0.14.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-jsdoc": "46.9.0",
"eslint-plugin-prettier": "5.0.1",
"prettier": "3.1.0",
"typescript": "5.3.2",
"vite": "5.0.2",
"vitest": "0.34.6"
"typescript": "5.3.2"
}
}
12 changes: 6 additions & 6 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
"@rating-tracker/commons": "workspace:*",
"@rating-tracker/wasm": "workspace:*",
"@simplewebauthn/browser": "8.3.4",
"@types/react": "18.2.38",
"@types/react-dom": "18.2.16",
"@vitejs/plugin-react": "4.2.0",
"@vitest/coverage-v8": "0.34.6",
"@vitest/web-worker": "0.34.6",
"axios": "1.6.2",
"nprogress": "0.2.0",
Expand All @@ -39,14 +38,16 @@
"react-switch-selector": "2.2.1",
"vite": "5.0.2",
"vite-plugin-html": "3.2.0",
"vite-plugin-wasm": "3.2.2"
"vite-plugin-wasm": "3.2.2",
"vitest": "0.34.6"
},
"devDependencies": {
"@types/node": "20.9.3",
"@types/nprogress": "0.2.3",
"@types/react": "18.2.38",
"@types/react-dom": "18.2.16",
"@typescript-eslint/eslint-plugin": "6.12.0",
"@typescript-eslint/parser": "6.12.0",
"@vitest/coverage-v8": "0.34.6",
"eslint": "8.54.0",
"eslint-config-google": "0.14.0",
"eslint-config-prettier": "9.0.0",
Expand All @@ -55,7 +56,6 @@
"eslint-plugin-prettier": "5.0.1",
"eslint-plugin-react": "7.33.2",
"prettier": "3.1.0",
"typescript": "5.3.2",
"vitest": "0.34.6"
"typescript": "5.3.2"
}
}
7 changes: 7 additions & 0 deletions packages/wasm/wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {Uint8Array} _array
* @returns {string}
*/
export function convert_avatar(_array: Uint8Array): string;
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,10 @@ __metadata:
prettier: "npm:3.1.0"
typescript: "npm:5.3.2"
dependenciesMeta:
"@prisma/engines":
built: true
prisma:
built: true
swagger-ui-dist:
unplugged: true
languageName: unknown
Expand Down

0 comments on commit 240f2ab

Please sign in to comment.