Skip to content

Commit

Permalink
chore: upgrade to yarn 4 (#1441)
Browse files Browse the repository at this point in the history
* chore: upgrade to yarn 4

* fix: use correct cache dir command

* chore: organize pipeline

* chore: use setup-node instead of handrolling it

* fix: dependency conflicts and docker setup
  • Loading branch information
mvarendorff authored Oct 5, 2024
1 parent a882279 commit c281abc
Show file tree
Hide file tree
Showing 12 changed files with 7,844 additions and 5,188 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
build
.env
.env.example
.yarn
19 changes: 19 additions & 0 deletions .github/actions/install-yarn/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Yarn Install
description: Installs and caches yarn dependencies

runs:
using: "composite"
steps:
- name: 'Enable corepack'
shell: bash
run: corepack enable

- uses: actions/setup-node@v4
with:
cache: yarn
node-version: 21

# This step should prefer the cached dependencies and restore node_modules
- name: Install dependencies
shell: bash
run: yarn --immutable
16 changes: 16 additions & 0 deletions .github/actions/yarn-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Reusable Yarn Action
description: Runs a given yarn command after installing all dependencies including caching

inputs:
command:
description: 'The command to run (excluding the yarn prefix)'
required: true

runs:
using: "composite"
steps:
- uses: ./.github/actions/install-yarn

- name: Run command in root folder
shell: bash
run: yarn ${{ inputs.command }}
21 changes: 5 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,9 @@ jobs:
YTF_GRAPHQL_ENDPOINT: https://staging.yestheory.family/_yesbot-schema
steps:
- uses: actions/checkout@v3
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache node modules
uses: actions/cache@v2
- uses: ./.github/actions/yarn-action
name: 'Install and codegen'
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
- name: install and compile
run: |
yarn install --frozen-lockfile
yarn graphql-codegen
yarn tsc --noEmit
command: 'graphql-codegen'
- name: 'Check types'
run: yarn tsc --noEmit
3 changes: 0 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ on:
jobs:
build-and-push-image:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 16.20 ]
permissions:
contents: read
packages: write
Expand Down
18 changes: 3 additions & 15 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,7 @@ jobs:
node-version: [ 16.20 ]
steps:
- uses: actions/checkout@v3
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache node modules
uses: actions/cache@v2
- uses: ./.github/actions/yarn-action
name: 'Install and lint'
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
- name: install and lint
run: |
yarn install --frozen-lockfile
yarn run lint
command: lint
18 changes: 3 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,7 @@ jobs:
node-version: [ 16.20 ]
steps:
- uses: actions/checkout@v3
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache node modules
uses: actions/cache@v2
- uses: ./.github/actions/yarn-action
name: 'Install and test'
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
- name: install and testing
run: |
yarn install --frozen-lockfile
yarn run test
command: test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ src/**/*.generated.ts

# One off scripts that are not relevant to the repository.
src/scripts/

.yarn/
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodeLinker: node-modules
enableGlobalCache: false
17 changes: 9 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
FROM node:21.7.3-alpine AS deps
RUN apk add --no-cache libc6-compat
FROM node:21.7.3-alpine AS base
RUN apk add --no-cache libc6-compat && \
corepack enable

FROM base as deps

WORKDIR /usr/src/app
COPY package.json yarn.lock ./
COPY package.json yarn.lock .yarnrc.yml ./
COPY prisma/schema.prisma ./prisma/schema.prisma

RUN yarn install --frozen-lockfile

FROM node:21.7.3-alpine AS builder
RUN apk add --no-cache libc6-compat
FROM base as builder
WORKDIR /usr/src/app

COPY --from=deps /usr/src/app/node_modules ./node_modules
Expand All @@ -18,15 +20,14 @@ ARG YTF_GRAPHQL_SCHEMA_ENDPOINT

RUN yarn prisma generate && yarn graphql-codegen && yarn run tsc

FROM node:21.7.3-alpine
RUN apk add --no-cache libc6-compat
# Create app directory
FROM base
WORKDIR /usr/src/app

COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/prisma ./prisma
COPY --from=builder /usr/src/app/package.json ./package.json
COPY --from=builder /usr/src/app/yarn.lock ./yarn.lock
COPY --from=builder /usr/src/app/.yarnrc.yml ./.yarnrc.yml
COPY --from=builder /usr/src/app/build ./build
COPY /deployment/docker-entrypoint.sh ./docker-entrypoint.sh

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"node-cron": "3.0.3",
"path": "0.12.7",
"reflect-metadata": "0.2.2",
"type-fest": "^4",
"uuid": "10.0.0",
"vitest-mock-extended": "2.0.2",
"winston": "3.15.0"
Expand All @@ -61,5 +62,5 @@
"typescript": "5.6.2",
"vitest": "2.1.2"
},
"packageManager": "yarn@1.22.22"
"packageManager": "yarn@4.5.0+sha512.837566d24eec14ec0f5f1411adb544e892b3454255e61fdef8fd05f3429480102806bac7446bc9daff3896b01ae4b62d00096c7e989f1596f2af10b927532f39"
}
Loading

0 comments on commit c281abc

Please sign in to comment.