diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 4f6c5d92..36f5e7ae 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,11 +3,11 @@ updates: - package-ecosystem: "npm" directories: - "/" - - "/spark-publish" schedule: interval: "daily" time: "09:00" timezone: "Europe/Berlin" + versioning-strategy: increase commit-message: prefix: "deps" prefix-development: "deps(dev)" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c837bf8..10eb50cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,6 @@ on: push: branches: [main] pull_request: - branches: [main] jobs: build-api: @@ -25,13 +24,14 @@ jobs: env: DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres GLIF_TOKEN: ${{ secrets.GLIF_TOKEN }} + NPM_CONFIG_WORKSPACE: spark-api steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 - run: npm ci - - run: npm run test:api + - run: npm test build-publish: runs-on: ubuntu-latest @@ -51,14 +51,25 @@ jobs: --health-retries 5 env: DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres + NPM_CONFIG_WORKSPACE: spark-publish + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: npm ci + - run: node bin/migrate.js + - run: npm test + + lint-all: + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 - run: npm ci - - run: npm run migrate - - run: npm run test:publish + - run: npm run lint docker-build: runs-on: ubuntu-latest @@ -94,7 +105,7 @@ jobs: deploy-api: if: github.ref == 'refs/heads/main' - needs: [build-api, build-publish, docker-build, docker-build] + needs: [build-api, build-publish, docker-build] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -123,7 +134,7 @@ jobs: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} deploy-publish: if: github.ref == 'refs/heads/main' - needs: [build-api, build-publish, docker-build, docker-build] + needs: [build-api, build-publish, docker-build] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.mocharc.cjs b/.mocharc.cjs deleted file mode 100644 index abd6d46f..00000000 --- a/.mocharc.cjs +++ /dev/null @@ -1,15 +0,0 @@ -const MODULES = [ - 'spark-api', - 'spark-publish' -] - -module.exports = { - spec: getSpec() -} - -// Workaround for https://github.com/mochajs/mocha/issues/4100 -function getSpec () { - const isTestFile = (/** @type {string} */arg) => arg.endsWith('.js') - if (process.argv.slice(2).some(isTestFile)) return [] - return MODULES.map(dir => `${dir}/test/**/*.js`) -} diff --git a/Dockerfile b/Dockerfile index 7d183596..23b8e624 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,13 @@ RUN apt-get update -qq && \ # to install all modules: "npm install --production=false". # Ref: https://docs.npmjs.com/cli/v9/commands/npm-install#description COPY --link package-lock.json package.json ./ -RUN npm ci + +# We cannot use a wildcard until `COPY --parents` is stabilised +# See https://docs.docker.com/reference/dockerfile/#copy---parents +COPY --link spark-api/package.json ./spark-api/ +COPY --link spark-publish/package.json ./spark-publish/ + +RUN npm ci --workspaces # Copy application code COPY --link . . @@ -44,6 +50,6 @@ ARG SERVICE # ARGs are not preserved at runtime, we need to store the value # as a default value of an ENV var -ENV SCRIPT="start:${SERVICE}" +ENV WORKSPACE="spark-${SERVICE}" -CMD npm run ${SCRIPT} +CMD npm start --workspace ${WORKSPACE} diff --git a/README.md b/README.md index 00e45fc8..7018f91e 100644 --- a/README.md +++ b/README.md @@ -89,13 +89,14 @@ docker run -d --name spark-db \ Start the API service: ```bash -npm run start:api +npm start --workspace spark-api ``` Run tests and linters: ```bash -npm run test:api +npm test --workspace spark-api +npm run lint --workspace spark-api ``` ## Deployment diff --git a/package-lock.json b/package-lock.json index c9bed8d1..8011a860 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,40 +1,18 @@ { - "name": "@filecoin-station/spark-api", + "name": "@filecoin-station/spark-api-monorepo", "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@filecoin-station/spark-api", - "version": "0.0.0", + "name": "@filecoin-station/spark-api-monorepo", "license": "MIT", - "dependencies": { - "@filecoin-station/spark-impact-evaluator": "^1.0.0", - "@glif/filecoin-address": "^3.0.5", - "@influxdata/influxdb-client": "^1.33.2", - "@ipld/car": "^5.3.0", - "@sentry/node": "^8.5.0", - "@ucanto/core": "^10.0.1", - "@ucanto/principal": "^9.0.1", - "@web3-storage/access": "^18.3.2", - "@web3-storage/w3up-client": "^13.1.1", - "compare-versions": "^6.1.0", - "ethers": "^6.12.1", - "http-assert": "^1.5.0", - "http-responders": "^2.0.2", - "multiformats": "^13.1.0", - "p-retry": "^6.2.0", - "p-timeout": "^6.1.2", - "pg": "^8.11.5", - "postgrator": "^7.2.0", - "raw-body": "^2.5.2" - }, + "workspaces": [ + "spark-api", + "spark-publish" + ], "devDependencies": { - "@flydotio/dockerfile": "^0.5.7", - "light-my-request": "^5.13.0", - "mocha": "^10.4.0", - "standard": "^17.1.0", - "varint": "^6.0.0" + "standard": "^17.1.0" } }, "node_modules/@adraffy/ens-normalize": { @@ -98,6 +76,10 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@filecoin-station/spark-api": { + "resolved": "spark-api", + "link": true + }, "node_modules/@filecoin-station/spark-impact-evaluator": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@filecoin-station/spark-impact-evaluator/-/spark-impact-evaluator-1.0.0.tgz", @@ -5397,6 +5379,10 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/spark-publish": { + "resolved": "spark-publish", + "link": true + }, "node_modules/split2": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", @@ -6003,6 +5989,53 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "spark-api": { + "name": "@filecoin-station/spark-api", + "version": "0.0.0", + "license": "MIT", + "dependencies": { + "@filecoin-station/spark-impact-evaluator": "^1.0.0", + "@glif/filecoin-address": "^3.0.5", + "@sentry/node": "^8.5.0", + "compare-versions": "^6.1.0", + "ethers": "^6.12.1", + "http-assert": "^1.5.0", + "http-responders": "^2.0.2", + "multiformats": "^13.1.0", + "pg": "^8.11.5", + "postgrator": "^7.2.0", + "raw-body": "^2.5.2" + }, + "devDependencies": { + "light-my-request": "^5.13.0", + "mocha": "^10.4.0", + "standard": "^17.1.0", + "varint": "^6.0.0" + } + }, + "spark-publish": { + "dependencies": { + "@filecoin-station/spark-impact-evaluator": "^1.0.0", + "@glif/filecoin-address": "^3.0.5", + "@influxdata/influxdb-client": "^1.33.2", + "@ipld/car": "^5.3.0", + "@sentry/node": "^8.4.0", + "@ucanto/core": "^10.0.1", + "@ucanto/principal": "^9.0.1", + "@web3-storage/access": "^18.3.2", + "@web3-storage/w3up-client": "^13.1.1", + "ethers": "^6.12.1", + "p-retry": "^6.2.0", + "p-timeout": "^6.1.2", + "pg": "^8.11.5" + }, + "devDependencies": { + "@flydotio/dockerfile": "^0.5.7", + "mocha": "^10.4.0", + "multiformats": "^13.1.0", + "standard": "^17.1.0" + } } } } diff --git a/package.json b/package.json index da356646..22d85974 100644 --- a/package.json +++ b/package.json @@ -1,46 +1,20 @@ { - "name": "@filecoin-station/spark-api", + "name": "@filecoin-station/spark-api-monorepo", "private": true, - "version": "0.0.0", "license": "MIT", "repository": "filecoin-station/spark-api", "type": "module", - "description": "API for SPARK", + "workspaces": [ + "spark-api", + "spark-publish" + ], "scripts": { "migrate": "node bin/migrate.js", - "start:api": "node spark-api/bin/spark.js", - "start:publish": "node spark-publish/bin/spark-publish.js", - "test:api": "mocha spark-api/test/**/*.js", - "test:publish": "mocha spark-publish/test/**/*.js", - "test": "standard && mocha" + "lint": "standard", + "test": "npm run lint && npm test --workspaces" }, "devDependencies": { - "@flydotio/dockerfile": "^0.5.7", - "light-my-request": "^5.13.0", - "mocha": "^10.4.0", - "standard": "^17.1.0", - "varint": "^6.0.0" - }, - "dependencies": { - "@filecoin-station/spark-impact-evaluator": "^1.0.0", - "@glif/filecoin-address": "^3.0.5", - "@influxdata/influxdb-client": "^1.33.2", - "@ipld/car": "^5.3.0", - "@sentry/node": "^8.5.0", - "@ucanto/core": "^10.0.1", - "@ucanto/principal": "^9.0.1", - "@web3-storage/access": "^18.3.2", - "@web3-storage/w3up-client": "^13.1.1", - "compare-versions": "^6.1.0", - "ethers": "^6.12.1", - "http-assert": "^1.5.0", - "http-responders": "^2.0.2", - "multiformats": "^13.1.0", - "p-retry": "^6.2.0", - "p-timeout": "^6.1.2", - "pg": "^8.11.5", - "postgrator": "^7.2.0", - "raw-body": "^2.5.2" + "standard": "^17.1.0" }, "standard": { "env": [ diff --git a/spark-api/package.json b/spark-api/package.json new file mode 100644 index 00000000..2dea8d6f --- /dev/null +++ b/spark-api/package.json @@ -0,0 +1,38 @@ +{ + "name": "@filecoin-station/spark-api", + "private": true, + "version": "0.0.0", + "license": "MIT", + "repository": "filecoin-station/spark-api", + "type": "module", + "description": "API for SPARK", + "scripts": { + "start": "node bin/spark.js", + "lint": "standard", + "test": "mocha" + }, + "devDependencies": { + "light-my-request": "^5.13.0", + "mocha": "^10.4.0", + "standard": "^17.1.0", + "varint": "^6.0.0" + }, + "dependencies": { + "@filecoin-station/spark-impact-evaluator": "^1.0.0", + "@glif/filecoin-address": "^3.0.5", + "@sentry/node": "^8.5.0", + "compare-versions": "^6.1.0", + "ethers": "^6.12.1", + "http-assert": "^1.5.0", + "http-responders": "^2.0.2", + "multiformats": "^13.1.0", + "pg": "^8.11.5", + "postgrator": "^7.2.0", + "raw-body": "^2.5.2" + }, + "standard": { + "env": [ + "mocha" + ] + } +} diff --git a/spark-publish/package.json b/spark-publish/package.json new file mode 100644 index 00000000..7a52297a --- /dev/null +++ b/spark-publish/package.json @@ -0,0 +1,35 @@ +{ + "type": "module", + "scripts": { + "start": "node bin/spark-publish.js", + "lint": "standard", + "test": "mocha" + }, + "dependencies": { + "@filecoin-station/spark-impact-evaluator": "^1.0.0", + "@glif/filecoin-address": "^3.0.5", + "@influxdata/influxdb-client": "^1.33.2", + "@ipld/car": "^5.3.0", + "@sentry/node": "^8.4.0", + "@ucanto/core": "^10.0.1", + "@ucanto/principal": "^9.0.1", + "@web3-storage/access": "^18.3.2", + "@web3-storage/w3up-client": "^13.1.1", + "ethers": "^6.12.1", + "p-retry": "^6.2.0", + "p-timeout": "^6.1.2", + "pg": "^8.11.5" + }, + "devDependencies": { + "@flydotio/dockerfile": "^0.5.7", + "mocha": "^10.4.0", + "multiformats": "^13.1.0", + "postgrator": "^7.2.0", + "standard": "^17.1.0" + }, + "standard": { + "env": [ + "mocha" + ] + } +}