Skip to content

Commit

Permalink
Merge pull request #485 from AikidoSec/ci-cache-node-modules
Browse files Browse the repository at this point in the history
Cache dependencies in CI workflows
  • Loading branch information
hansott authored Dec 20, 2024
2 parents 8871c7d + 2414713 commit 4160341
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push: {}
workflow_call: {}
jobs:
build:
benchmark:
runs-on: ubuntu-latest
services:
mongodb:
Expand All @@ -28,9 +28,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Install K6
uses: grafana/setup-k6-action@v1
- name: Install wrk
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18.x"
registry-url: "https://registry.npmjs.org"
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/end-to-end-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push: {}
workflow_call: {}
jobs:
build:
test:
runs-on: ubuntu-latest
services:
mongodb:
Expand Down Expand Up @@ -52,9 +52,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Add local.aikido.io to /etc/hosts
run: |
sudo echo "127.0.0.1 local.aikido.io" | sudo tee -a /etc/hosts
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/lint-code.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
name: Lint code
on: push
jobs:
build:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- run: make install-lib-only
- run: make build
- run: make lint
6 changes: 4 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push: {}
workflow_call: {}
jobs:
build:
test:
runs-on: ubuntu-latest
services:
s3:
Expand Down Expand Up @@ -68,9 +68,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Add local.aikido.io to /etc/hosts
run: |
sudo echo "127.0.0.1 local.aikido.io" | sudo tee -a /etc/hosts
Expand Down
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,19 @@ fastify-clickhouse:
hono-prisma:
cd sample-apps/hono-prisma && AIKIDO_DEBUG=true AIKIDO_BLOCK=true node app.js

NPM_INSTALL_CMD := $(if $(CI),ci,install)

.PHONY: install-lib-only
install-lib-only:
mkdir -p build
node scripts/copyPackageJSON.js
touch build/index.js
cd build && npm link
npm install
cd library && npm install
npm $(NPM_INSTALL_CMD)
cd library && npm $(NPM_INSTALL_CMD)

.PHONY: install
install: install-lib-only
cd end2end && npm install
cd end2end && npm $(NPM_INSTALL_CMD)
node scripts/install.js

.PHONY: build
Expand Down
11 changes: 9 additions & 2 deletions scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ const { exec } = require("child_process");
const { promisify } = require("util");
const execAsync = promisify(exec);

function getInstallCmd() {
if (process.env.CI) {
return "npm ci";
}
return "npm install";
}

async function main() {
const sampleAppsDir = join(__dirname, "../sample-apps");
const sampleApps = await readdir(sampleAppsDir);
Expand Down Expand Up @@ -42,7 +49,7 @@ async function installSampleAppDeps(sampleApp) {
console.log(`Installing dependencies for ${sampleApp}`);

try {
await execAsync(`npm install`, {
await execAsync(getInstallCmd(), {
cwd: join(__dirname, "../sample-apps", sampleApp),
});
console.log(`Dependencies installed for ${sampleApp}`);
Expand All @@ -57,7 +64,7 @@ async function installBenchmarkDeps(benchmark) {
console.log(`Installing dependencies for ${benchmark}`);

try {
await execAsync(`npm install`, {
await execAsync(getInstallCmd(), {
cwd: join(__dirname, "../benchmarks", benchmark),
});
console.log(`Dependencies installed for ${benchmark}`);
Expand Down

0 comments on commit 4160341

Please sign in to comment.