From 24f9b1b95c6ede65eb74a38be7d9504bc96948dd Mon Sep 17 00:00:00 2001 From: Thibault Seisel Date: Fri, 14 Jun 2024 20:49:38 +0200 Subject: [PATCH 1/5] feat(docker): cache npm cache in Dockerfile --- src/docker/files/Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/docker/files/Dockerfile b/src/docker/files/Dockerfile index 5476976..6cdde6f 100644 --- a/src/docker/files/Dockerfile +++ b/src/docker/files/Dockerfile @@ -8,7 +8,8 @@ ENTRYPOINT [ "dumb-init", "--" ] FROM base as development # Install Node.js development dependencies COPY package*.json ./ -RUN npm clean-install --ignore-scripts --prefer-offline --no-audit +RUN --mount=type=cache,id=npm,target=/root/.npm \ + npm clean-install --ignore-scripts --prefer-offline --no-audit # Run application in development mode CMD [ "npx", "nest", "start", "--watch", "--debug", "0.0.0.0:9229" ] @@ -21,7 +22,8 @@ FROM base as production # Install Node.js production dependencies ENV NODE_ENV=production COPY package*.json ./ -RUN npm clean-install --ignore-scripts --prefer-offline --no-audit +RUN --mount=type=cache,id=npm,target=/root/.npm \ + npm clean-install --ignore-scripts --prefer-offline --no-audit # Run application in production mode COPY --from=builder /usr/src/app/dist ./dist CMD [ "node", "--enable-source-maps", "dist/main.js" ] From 4a2572ebcc9f7ffd338bdbd18f9d575bf18f7a0e Mon Sep 17 00:00:00 2001 From: Thibault Seisel Date: Fri, 14 Jun 2024 21:13:44 +0200 Subject: [PATCH 2/5] feat(docker): remove deprecated docker compose version --- src/docker/files/docker-compose.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/docker/files/docker-compose.yml b/src/docker/files/docker-compose.yml index 4cae74c..c2c2ad3 100644 --- a/src/docker/files/docker-compose.yml +++ b/src/docker/files/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3" - services: api: build: From dec97d0fb89a5ef502c9cbc7b85c02d01327a37b Mon Sep 17 00:00:00 2001 From: Thibault Seisel Date: Fri, 14 Jun 2024 21:49:31 +0200 Subject: [PATCH 3/5] ci: automatically publish package to npm on Github Release --- .github/workflows/publishing.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/publishing.yml diff --git a/.github/workflows/publishing.yml b/.github/workflows/publishing.yml new file mode 100644 index 0000000..207d535 --- /dev/null +++ b/.github/workflows/publishing.yml @@ -0,0 +1,30 @@ +name: Publish package to npm + +on: + release: + types: [published] + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.x" + node-version-file: package.json + cache: npm + cache-dependency-path: package-lock.json + registry-url: "https://registry.npmjs.org" + + - name: Install dependencies + run: npm clean-install --prefer-offline --ignore-scripts + + - name: Publish to npm + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} From 52f0e150c704a3c3113170640657000f978c7109 Mon Sep 17 00:00:00 2001 From: Thibault Seisel Date: Fri, 14 Jun 2024 21:57:35 +0200 Subject: [PATCH 4/5] ci: run schematics as part of a pull request --- .github/workflows/pull-request.yml | 60 +++++++++++++++++++++++----- .github/workflows/run-schematics.yml | 29 -------------- 2 files changed, 49 insertions(+), 40 deletions(-) delete mode 100644 .github/workflows/run-schematics.yml diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index b917bf6..ae0b864 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -5,20 +5,58 @@ on: branches: [develop] jobs: - test: + unit-tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.x" + node-version-file: package.json + cache: npm + cache-dependency-path: package-lock.json + + - name: Install Node.js dependencies + run: npm ci --prefer-offline --ignore-scripts + + - name: Check code formatting + run: npx prettier --check . + + - name: Compile TypeScript + run: npm run build + + - name: Run unit-tests + run: npm test + + run-schematics: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 with: + node-version: "20.x" node-version-file: package.json cache: npm cache-dependency-path: package-lock.json - - run: npm ci --prefer-offline --ignore-scripts - name: Install Node.js dependencies - - run: npx prettier --check . - name: Check code formatting - - run: npm run build - name: Compile TypeScript - - run: npm test - name: Run unit-tests + + - name: Install NestJS CLI globally + run: npm install --global @nestjs/cli@^10 + + - name: Install schematics globally + run: | + npm ci --prefer-offline --ignore-scripts + npm run build + npm install --global . + + - name: Test generating a new NestJS application + run: > + nest new test-app --dry-run + --package-manager npm + --collection @tseisel/nestjs-schematics + timeout-minutes: 1 diff --git a/.github/workflows/run-schematics.yml b/.github/workflows/run-schematics.yml deleted file mode 100644 index 3709ad3..0000000 --- a/.github/workflows/run-schematics.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Test NestJS schematics -on: - push: - branches: - - develop - -jobs: - render: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version-file: package.json - cache: npm - cache-dependency-path: package-lock.json - - run: npm install --global @nestjs/cli@^10 - name: Install NestJS CLI globally - - run: | - npm clean-install --no-audit --ignore-scripts --prefer-offline - npm run build - npm install --global . - name: Install schematics globally - - run: > - nest new test-app --dry-run - --package-manager npm - --collection @tseisel/nestjs-schematics - name: Test generating a new NestJS application - timeout-minutes: 1 From 0ada2f9ddd574cb3c11494d1136c074a7723bb72 Mon Sep 17 00:00:00 2001 From: Thibault Seisel Date: Fri, 14 Jun 2024 22:10:09 +0200 Subject: [PATCH 5/5] ci: run pull request checks when targeting main --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index ae0b864..d66bbcf 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -2,7 +2,7 @@ name: Check pull request on: pull_request: - branches: [develop] + branches: [main] jobs: unit-tests: