From 658c752d2a69c052fe11be661e2b4c0e810fd84e Mon Sep 17 00:00:00 2001 From: Jason Yu Date: Mon, 14 Oct 2024 23:53:10 +0100 Subject: [PATCH] ci: run npm build in ci --- .github/workflows/npm-build.yaml | 46 ++++++++++++++++++++++++++++++++ .github/workflows/publish.yaml | 8 +++--- deno.json | 3 ++- scripts/build-npm-integration.ts | 10 +++++++ scripts/build-npm.ts | 16 ++++++----- 5 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/npm-build.yaml create mode 100644 scripts/build-npm-integration.ts diff --git a/.github/workflows/npm-build.yaml b/.github/workflows/npm-build.yaml new file mode 100644 index 0000000..20b8b19 --- /dev/null +++ b/.github/workflows/npm-build.yaml @@ -0,0 +1,46 @@ +name: "Node: Build + Integration" + +on: + push: + branches: + - main + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - uses: denoland/setup-deno@v2 + with: + deno-version: v2.x # Run with latest stable Deno. + + - name: Start Pebble and pebble-challtestsrv + run: deno task pebble:start --detach + + - name: Wait for Pebble to be ready + run: | + echo "⏳ Waiting for Pebble... 🪨" + + # Loop until the port 14000 is open + until nc -zv localhost 14000 2>/dev/null; do + sleep 1 + done + + echo "✅ Pebble is running!" + - name: Wait for pebble-challtestsrv to be ready + run: | + echo "⏳ Waiting for pebble-challtestsrv... 🪨" + + until nc -zv localhost 8055 2>/dev/null; do + sleep 1 + done + + echo "✅ pebble-challtestsrv is running!" + + - run: deno task build:npm:integration + + - name: Stop Pebble + run: deno task pebble:stop diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index c35571d..bcb73bc 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -1,8 +1,10 @@ name: Publish on: - push: - branches: - - main + workflow_run: + workflows: ["CI", "E2E", "Integration", "Node: Build + Integration"] + branches: [main] + types: + - completed jobs: publish-jsr: diff --git a/deno.json b/deno.json index 84d406a..3dfbea2 100644 --- a/deno.json +++ b/deno.json @@ -13,7 +13,8 @@ "test:integration": "deno test --unsafely-ignore-certificate-errors=localhost -A integration", "pebble:start": "docker compose -f integration/docker-compose.yaml up", "pebble:stop": "docker compose -f integration/docker-compose.yaml down", - "build:npm": "deno run -A scripts/build-npm.ts" + "build:npm": "deno run -A scripts/build-npm.ts", + "build:npm:integration": "deno run -A scripts/build-npm-integration.ts" }, "compilerOptions": { "strict": true, diff --git a/scripts/build-npm-integration.ts b/scripts/build-npm-integration.ts new file mode 100644 index 0000000..207c550 --- /dev/null +++ b/scripts/build-npm-integration.ts @@ -0,0 +1,10 @@ +import { build, type BuildOptions } from "jsr:@deno/dnt"; +import { dntConfig } from "./build-npm.ts"; + +const config: BuildOptions = { + ...dntConfig, + testPattern: "integration/**/*.test.ts", + test: true, +}; + +await build(config); diff --git a/scripts/build-npm.ts b/scripts/build-npm.ts index cf0b398..ced1949 100644 --- a/scripts/build-npm.ts +++ b/scripts/build-npm.ts @@ -1,4 +1,4 @@ -import { build, emptyDir } from "jsr:@deno/dnt"; +import { build, type BuildOptions, emptyDir } from "jsr:@deno/dnt"; import { join } from "jsr:@std/path"; import DENO_JSON from "../deno.json" with { type: "json" }; @@ -14,19 +14,16 @@ const OUT_DIR = join( "./dist-npm", ); -await emptyDir(OUT_DIR); - const GITHUB_REPO = "https://github.com/fishballapp/acme"; -await build({ - testPattern: "integration/**/*.test.ts", +export const dntConfig: BuildOptions = { entryPoints: Object.entries(DENO_JSON.exports).map(([name, path]) => ({ kind: "export", name, path: join(PROJECT_ROOT, path), })), outDir: OUT_DIR, - test: true, + test: false, shims: { deno: "dev", undici: "dev", @@ -67,4 +64,9 @@ await build({ ); } }, -}); +}; + +if (import.meta.main) { + await emptyDir(OUT_DIR); + await build(dntConfig); +}