Skip to content

Commit

Permalink
@wesp-up/eslint-config / react
Browse files Browse the repository at this point in the history
Update ESLint to v9

- This required a lot of changes and some configs/plugins still haven't updated yet, so will have to wait until they do (e.g. eslint-plugin-jsx-a11y).
- Removed airbnb configs in favor of using default recommended rules to greatly simplify. Recommended rule sets have also gotten really good over time.
- Removed prettier plugin and config in favor of using prettier directly, which is their recommendation.
- Added a plugin that automatically adds the `.js` file extension to relative imports in modules. Disable these rules when not in a module project.

@wesp-up/tsconfig

- - Removed vitest types from the base config since the types are not always present.
  - Changed the `node.json` config from `"module": "CommonJS"` to `"module": "ESNext"` due to the major shift to ES Modules.

Housekeeping

- Updated the GitHub Actions workflow to run native rather than in an internal Docker container. Now relying on GitHub Actions cache for node modules and Turborepo to speed up the cache and decouple from Vercel. Also added a separate workflow for pull requests to validate the build.
- Fixed an issue with the `update-package-lock` npm script where using `rm` didn't actually delete the files for some reason. Switched to `rimraf` and it works.
- Updated the Docker build for better layer caching.
  • Loading branch information
wrporter committed Jul 28, 2024
1 parent 5b7e2fe commit 3bfc6a5
Show file tree
Hide file tree
Showing 45 changed files with 6,284 additions and 4,091 deletions.
32 changes: 22 additions & 10 deletions .ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
###############################################################################
# Copy all package.json files in the project
# See https://stackoverflow.com/questions/49939960/docker-copy-files-using-glob-pattern
# Base image
###############################################################################
FROM alpine:3.18 as dependencies
FROM node:20-alpine AS base

WORKDIR /app
RUN apk update && apk upgrade --no-cache
RUN npm config set update-notifier false

COPY package.json package-lock.json ./
ENV TURBO_TELEMETRY_DISABLED=1

COPY packages packages
###############################################################################
# Copy over dependency files to prepare for install
###############################################################################
FROM base AS dependencies

COPY . .

RUN apk add --no-cache sudo jq

# Find and remove non package.json files
RUN find packages \! -name "package.json" -mindepth 2 -maxdepth 2 -print | xargs rm -rf
# Only re-install dependencies when there is a change to dependency definitions
RUN sudo find . \! -name "package*.json" -mindepth 3 -maxdepth 3 -print | xargs rm -rf
RUN sudo find . \! -name "package*.json" -type f -maxdepth 1 -delete
RUN sudo find . -name "package.json" -mindepth 1 -maxdepth 3 -exec sh -c 'jq "with_entries(select(.key == \"name\" or .key == \"version\" or .key == \"workspaces\" or .key == \"dependencies\" or .key == \"devDependencies\" or .key == \"optionalDependencies\" or .key == \"peerDependencies\"))" {} > tmp.$$ && mv tmp.$$ {}' \;

###############################################################################
# Install Dependencies
# Install dependencies and build
###############################################################################
FROM node:20-alpine
FROM base AS build

RUN apk update && apk upgrade && apk add --no-cache curl bash git libc6-compat
# See https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine
# to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat

WORKDIR /app

Expand Down
1 change: 0 additions & 1 deletion .ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ echo "-- ${0} start..."
echo "-- Building docker image for production"

buildDocker \
--progress=plain \
--file .ci/Dockerfile \
--tag "${IMAGE_PATH}:${VERSION}" \
.
Expand Down
3 changes: 0 additions & 3 deletions .ci/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ docker run \
-t \
--rm \
--name=${APP_NAME} \
-e TURBO_TEAM="${TURBO_TEAM}" \
-e TURBO_TOKEN="${TURBO_TOKEN}" \
-e TURBO_REMOTE_ONLY=true \
${IMAGE_PATH}:${VERSION} \
bash -c "echo '//${REGISTRY_URL}:_authToken="${REGISTRY_AUTH_TOKEN}"' >> .npmrc \
&& echo '//${REGISTRY_URL}:email=${REGISTRY_EMAIL}' >> .npmrc \
Expand Down
3 changes: 0 additions & 3 deletions .ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ docker run \
-t \
--rm \
--name=${APP_NAME} \
-e TURBO_TEAM="${TURBO_TEAM}" \
-e TURBO_TOKEN="${TURBO_TOKEN}" \
-e TURBO_REMOTE_ONLY=true \
${IMAGE_PATH}:${VERSION} \
${@}

Expand Down
41 changes: 31 additions & 10 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ on:
jobs:
build:
name: Build and Publish
timeout-minutes: 15
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_REMOTE_ONLY: true
REGISTRY_EMAIL: ${{ secrets.REGISTRY_EMAIL }}
REGISTRY_AUTH_TOKEN: ${{ secrets.REGISTRY_AUTH_TOKEN }}

Expand All @@ -24,11 +20,36 @@ jobs:
with:
fetch-depth: 2

- name: 🔧 Build
run: .ci/build.sh
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: 💿 Restore cached turbo artifacts
uses: actions/cache@v4
with:
path: '**/.turbo'
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: 💿 Restore cached node_modules
uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}

- name: 📦 Install dependencies
run: npm install

- name: 🧪 Validate
run: .ci/run.sh npm run ci
- name: 🛠️ Build
run: npm run ci

- name: 🚀 Publish
run: .ci/publish.sh
- name: 🚀 Publish packages
run: |
REGISTRY_URL="registry.npmjs.org/"
echo '//${REGISTRY_URL}:_authToken="${REGISTRY_AUTH_TOKEN}"' >> .npmrc
echo '//${REGISTRY_URL}:email=${REGISTRY_EMAIL}' >> .npmrc
echo '//${REGISTRY_URL}:always-auth=true' >> .npmrc
npx changeset publish
42 changes: 42 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Pull Request

on:
pull_request:
types: [opened, synchronize]

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- name: 🥼 Check out code
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: 💿 Restore cached turbo artifacts
uses: actions/cache@v4
with:
path: '**/.turbo'
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: 💿 Restore cached node_modules
uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}

- name: 📦 Install dependencies
run: npm install

- name: 🛠️ Build
run: npm run ci
Loading

0 comments on commit 3bfc6a5

Please sign in to comment.