diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml index 179600c..ba5c72b 100644 --- a/.github/workflows/deno.yml +++ b/.github/workflows/deno.yml @@ -3,9 +3,12 @@ on: push: branches: - master + pull_request: + branches: + - master jobs: build: - name: ${{ matrix.kind }} ${{ matrix.os }} + name: Deno ${{ matrix.os }} runs-on: ${{ matrix.os }} if: "!contains(github.event.head_commit.message, '[skip ci]')" strategy: @@ -16,24 +19,24 @@ jobs: DENO_BUILD_MODE: release V8_BINARY: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v7 - name: Setup Deno - uses: denolib/setup-deno@master + uses: denoland/setup-deno@v2 with: - deno-version: 1.x + deno-version: 2.x - name: Tests run: deno test --allow-run --allow-net release: name: Release - runs-on: ubuntu-18.04 - if: "!contains(github.event.head_commit.message, '[skip ci]')" + runs-on: ubuntu-latest + if: "github.event_name == 'push' && !contains(github.event.head_commit.message, '[skip ci]')" steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v7 - name: Setup Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v6 with: - node-version: 12.17.0 + node-version: 20 - name: Setup package.json run: echo '{"name":"@denorg/dpx","version":"0.0.0","publishConfig":{"access":"public"},"scripts":{"semantic-release":"semantic-release"},"repository":{"type":"git","url":"https://github.com/denorg/dpx.git"},"author":"Denorg ","license":"MIT","bugs":{"url":"https://github.com/denorg/dpx/issues"},"homepage":"https://denorg.github.io/dpx/","devDependencies":{"semantic-release":"^17.0.4","semantic-release-gitmoji":"^1.3.3"}}' > package.json - name: Install dependencies diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 334fbd7..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Test CI -on: - push: - branches-ignore: - - "master" - pull_request: - branches-ignore: - - "master" -jobs: - build: - name: ${{ matrix.kind }} ${{ matrix.os }} - runs-on: ${{ matrix.os }} - if: "!contains(github.event.head_commit.message, '[skip ci]')" - strategy: - matrix: - os: [macOS-latest, ubuntu-latest, windows-latest] - env: - GH_ACTIONS: true - DENO_BUILD_MODE: release - V8_BINARY: true - steps: - - uses: actions/checkout@v2 - - name: Setup Deno - uses: denolib/setup-deno@master - with: - deno-version: 1.x - - name: Run tests - run: deno test --allow-run --allow-net diff --git a/mod.ts b/mod.ts index c143ed8..a6fbc95 100644 --- a/mod.ts +++ b/mod.ts @@ -1,8 +1,8 @@ -import { getRegistryUrl } from "./src/utils.ts" +import { getRegistryUrl } from "./src/utils.ts"; /** Get the file URL to run */ export async function getEntryFile(packageName: string, registry?: string) { - let repo_url = getRegistryUrl(packageName, registry) + let repo_url = getRegistryUrl(packageName, registry); const potentialFiles = ["cli.ts", "mod.ts"]; let fileUrl = ""; for await (const file of potentialFiles) { @@ -31,13 +31,13 @@ export async function dpx( packageName: string, flags: string[], args: string[], - registry?: string + registry?: string, ) { const filePath = await getEntryFile(packageName, registry); - return Deno.run({ - cmd: ["deno", "run", ...flags, filePath, ...args], + return new Deno.Command("deno", { + args: ["run", ...flags, filePath, ...args], stdout: "inherit", stderr: "inherit", stdin: "inherit", - }).status(); + }).spawn().status; } diff --git a/mod_test.ts b/mod_test.ts index 3d899ac..de335b9 100644 --- a/mod_test.ts +++ b/mod_test.ts @@ -1,14 +1,14 @@ import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; -import { getEntryFile } from "./mod.ts"; +import { dpx, getEntryFile } from "./mod.ts"; Deno.test( "get entry file - cli.ts", async (): Promise => { assertEquals( await getEntryFile("online"), - "https://deno.land/x/online/cli.ts" + "https://deno.land/x/online/cli.ts", ); - } + }, ); Deno.test( @@ -16,7 +16,30 @@ Deno.test( async (): Promise => { assertEquals( await getEntryFile("recursive_readdir"), - "https://deno.land/x/recursive_readdir/mod.ts" + "https://deno.land/x/recursive_readdir/mod.ts", ); - } + }, ); + +Deno.test("dpx runs a CLI from a custom registry", async () => { + const server = Deno.serve({ port: 0 }, (request) => { + const { pathname } = new URL(request.url); + if (pathname === "/package/cli.ts") { + return new Response('console.log("dpx test CLI");'); + } + return new Response("Not found", { status: 404 }); + }); + const { port } = server.addr as Deno.NetAddr; + + try { + const status = await dpx( + "package", + [`--allow-net=127.0.0.1:${port}`], + [], + `http://127.0.0.1:${port}`, + ); + assertEquals(status.success, true); + } finally { + await server.shutdown(); + } +});