From 59b14af9e9abad254b0c756584e79feb42d46040 Mon Sep 17 00:00:00 2001 From: Maxwell Brown Date: Fri, 6 Sep 2024 08:27:28 -0400 Subject: [PATCH 1/2] add release workflows --- .changeset/five-countries-explain.md | 5 +++ .github/workflows/check.yml | 50 +++++++++++++++++++++ .github/workflows/release.yml | 33 ++++++++++++++ examples/http-server/src/Accounts/Policy.ts | 3 +- examples/http-server/src/Groups.ts | 2 +- examples/http-server/src/Groups/Policy.ts | 3 +- examples/http-server/src/Uuid.ts | 3 +- package.json | 3 +- packages/create-effect-app/src/bin.ts | 1 - packages/create-effect-app/vitest.config.ts | 6 +++ setupTests.ts | 3 ++ vitest.shared.ts | 35 +++++++++++++++ vitest.workspace.ts | 28 ++++++++++++ 13 files changed, 168 insertions(+), 7 deletions(-) create mode 100644 .changeset/five-countries-explain.md create mode 100644 .github/workflows/check.yml create mode 100644 .github/workflows/release.yml create mode 100644 packages/create-effect-app/vitest.config.ts create mode 100644 setupTests.ts create mode 100644 vitest.shared.ts create mode 100644 vitest.workspace.ts diff --git a/.changeset/five-countries-explain.md b/.changeset/five-countries-explain.md new file mode 100644 index 0000000..4f5e3b0 --- /dev/null +++ b/.changeset/five-countries-explain.md @@ -0,0 +1,5 @@ +--- +"create-effect-app": patch +--- + +Initial release diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..15006b3 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,50 @@ +name: Check + +on: + workflow_dispatch: + pull_request: + branches: [main] + push: + branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: {} + +jobs: + types: + name: Types + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + uses: ./.github/actions/setup + - run: pnpm check + - run: pnpm dtslint + + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + uses: ./.github/actions/setup + - run: pnpm lint + + test: + name: Test + runs-on: ubuntu-latest + timeout-minutes: 10 + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + uses: ./.github/actions/setup + - run: pnpm vitest + env: + NODE_OPTIONS: --max_old_space_size=8192 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..83e229c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,33 @@ +name: Release + +on: + push: + branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + +permissions: {} + +jobs: + release: + if: github.repository_owner == 'Effect-Ts' + name: Release + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: write + id-token: write + pull-requests: write + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + uses: ./.github/actions/setup + - name: Create Release Pull Request or Publish + uses: changesets/action@v1 + with: + version: pnpm changeset-version + publish: pnpm changeset-publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/examples/http-server/src/Accounts/Policy.ts b/examples/http-server/src/Accounts/Policy.ts index 22ef83f..7108a7e 100644 --- a/examples/http-server/src/Accounts/Policy.ts +++ b/examples/http-server/src/Accounts/Policy.ts @@ -1,7 +1,8 @@ import { Effect, Layer } from "effect" -import type { policy } from "../Domain/Policy.js" +import { policy } from "../Domain/Policy.js" import type { UserId } from "../Domain/User.js" +// eslint-disable-next-line require-yield const make = Effect.gen(function*() { const canUpdate = (toUpdate: UserId) => policy("User", "update", (actor) => Effect.succeed(actor.id === toUpdate)) diff --git a/examples/http-server/src/Groups.ts b/examples/http-server/src/Groups.ts index cb353e1..d232ed3 100644 --- a/examples/http-server/src/Groups.ts +++ b/examples/http-server/src/Groups.ts @@ -1,5 +1,5 @@ import { SqlClient } from "@effect/sql" -import { Cause, Effect, Layer, Option, pipe } from "effect" +import { Effect, Layer, Option, pipe } from "effect" import type { AccountId } from "./Domain/Account.js" import type { GroupId } from "./Domain/Group.js" import { Group, GroupNotFound } from "./Domain/Group.js" diff --git a/examples/http-server/src/Groups/Policy.ts b/examples/http-server/src/Groups/Policy.ts index 6edbedb..f4501c9 100644 --- a/examples/http-server/src/Groups/Policy.ts +++ b/examples/http-server/src/Groups/Policy.ts @@ -1,7 +1,8 @@ import { Effect, Layer } from "effect" import type { Group } from "../Domain/Group.js" -import type { policy } from "../Domain/Policy.js" +import { policy } from "../Domain/Policy.js" +// eslint-disable-next-line require-yield const make = Effect.gen(function*() { const canCreate = (_group: typeof Group.jsonCreate.Type) => policy("Group", "create", (_actor) => Effect.succeed(true)) diff --git a/examples/http-server/src/Uuid.ts b/examples/http-server/src/Uuid.ts index bf5ecfe..96689ad 100644 --- a/examples/http-server/src/Uuid.ts +++ b/examples/http-server/src/Uuid.ts @@ -1,6 +1,7 @@ import { Context, Effect, Layer } from "effect" import * as Api from "uuid" +// eslint-disable-next-line require-yield const make = Effect.gen(function*() { const generate = Effect.sync(() => Api.v7()) return { generate } as const @@ -10,7 +11,7 @@ export class Uuid extends Context.Tag("Uuid")< Uuid, Effect.Effect.Success >() { - static Live = Layer.effect(Uuid, make) + static Live = Layer.succeed(Uuid, make) static Test = Layer.succeed(Uuid, { generate: Effect.succeed("test-uuid") }) diff --git a/package.json b/package.json index a1ee5b6..87ef5f0 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,7 @@ "type": "module", "packageManager": "pnpm@9.9.0", "workspaces": [ - "packages/*", - "examples/*" + "packages/*" ], "scripts": { "build": "pnpm --recursive --parallel run build", diff --git a/packages/create-effect-app/src/bin.ts b/packages/create-effect-app/src/bin.ts index d5f0c89..94f923c 100644 --- a/packages/create-effect-app/src/bin.ts +++ b/packages/create-effect-app/src/bin.ts @@ -7,7 +7,6 @@ import * as NodeHttpClient from "@effect/platform-node/NodeHttpClient" import * as NodeRuntime from "@effect/platform-node/NodeRuntime" import * as Ansi from "@effect/printer-ansi/Ansi" import * as AnsiDoc from "@effect/printer-ansi/AnsiDoc" -import * as Console from "effect/Console" import * as Effect from "effect/Effect" import * as Layer from "effect/Layer" import * as Logger from "effect/Logger" diff --git a/packages/create-effect-app/vitest.config.ts b/packages/create-effect-app/vitest.config.ts new file mode 100644 index 0000000..0411095 --- /dev/null +++ b/packages/create-effect-app/vitest.config.ts @@ -0,0 +1,6 @@ +import { mergeConfig, type UserConfigExport } from "vitest/config" +import shared from "../../vitest.shared.js" + +const config: UserConfigExport = {} + +export default mergeConfig(shared, config) diff --git a/setupTests.ts b/setupTests.ts new file mode 100644 index 0000000..62c5d03 --- /dev/null +++ b/setupTests.ts @@ -0,0 +1,3 @@ +import * as it from "@effect/vitest" + +it.addEqualityTesters() diff --git a/vitest.shared.ts b/vitest.shared.ts new file mode 100644 index 0000000..861c0a4 --- /dev/null +++ b/vitest.shared.ts @@ -0,0 +1,35 @@ +import * as path from "node:path" +import type { UserConfig } from "vitest/config" + +const alias = (name: string) => { + const target = process.env.TEST_DIST !== undefined ? "dist/dist/esm" : "src" + return ({ + [`${name}/test`]: path.join(__dirname, "packages", name, "test"), + [`${name}`]: path.join(__dirname, "packages", name, target) + }) +} + +// This is a workaround, see https://github.com/vitest-dev/vitest/issues/4744 +const config: UserConfig = { + esbuild: { + target: "es2020" + }, + optimizeDeps: { + exclude: ["bun:sqlite"] + }, + test: { + setupFiles: [path.join(__dirname, "setupTests.ts")], + fakeTimers: { + toFake: undefined + }, + sequence: { + concurrent: true + }, + include: ["test/**/*.test.ts"], + alias: { + ...alias("create-effect-app") + } + } +} + +export default config diff --git a/vitest.workspace.ts b/vitest.workspace.ts new file mode 100644 index 0000000..a6a87fe --- /dev/null +++ b/vitest.workspace.ts @@ -0,0 +1,28 @@ +import * as path from "node:path" +import { defineWorkspace, type UserWorkspaceConfig } from "vitest/config" + +// Remaining issues: +// - Random failures (browser): https://github.com/vitest-dev/vitest/issues/4497 +// - Alias resolution (browser, has workaround): https://github.com/vitest-dev/vitest/issues/4744 +// - Workspace optimization: https://github.com/vitest-dev/vitest/issues/4746 + +// TODO: Once https://github.com/vitest-dev/vitest/issues/4497 and https://github.com/vitest-dev/vitest/issues/4746 +// are resolved, we can create specialized workspace groups in separate workspace files to better control test groups +// with different dependencies (e.g. playwright browser) in CI. + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const project = ( + config: UserWorkspaceConfig["test"] & { name: `${string}|${string}` }, + root = config.root ?? path.join(__dirname, `packages/${config.name.split("|").at(0)}`) +) => ({ + extends: "vitest.shared.ts", + test: { root, ...config } +}) + +export default defineWorkspace([ + // Add specialized configuration for some packages. + // project({ name: "effect|browser", environment: "happy-dom" }), + // project({ name: "schema|browser", environment: "happy-dom" }), + // Add the default configuration for all packages. + "packages/*" +]) From 377cac2e0153f78ec5a36f98c3fc9e3a654c492a Mon Sep 17 00:00:00 2001 From: Maxwell Brown Date: Fri, 6 Sep 2024 08:29:00 -0400 Subject: [PATCH 2/2] remove dtslint --- .github/workflows/check.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 15006b3..5fd189e 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -23,7 +23,6 @@ jobs: - name: Install dependencies uses: ./.github/actions/setup - run: pnpm check - - run: pnpm dtslint lint: name: Lint