Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflows that publish to JSR #19

Merged
merged 15 commits into from
Nov 26, 2024
89 changes: 89 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Publish
on:
push:
branches:
- main

jobs:
generate-matrix:
name: Generate Job Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/[email protected]
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- run: deno run -A www/tasks publish-matrix.ts
id: set-matrix

jsr:
if: needs.generate-matrix.outputs.matrix != ''
name: Publish ${{ matrix.name }}@${{matrix.version}} to JSR
runs-on: ubuntu-latest

permissions:
contents: read
id-token: write

needs: [generate-matrix]

strategy:
fail-fast: false
max-parallel: 6
matrix: ${{fromJSON(needs.generate-matrix.outputs.matrix)}}

steps:
- uses: actions/[email protected]
- uses: denoland/setup-deno@v2

- run: deno publish
working-directory: ${{ matrix.workspace }}
npm:
if: needs.generate-matrix.outputs.matrix != ''
name: Publish ${{ matrix.name }}@${{matrix.version}} to NPM
runs-on: ubuntu-latest

permissions:
contents: read
id-token: write

needs: [generate-matrix]

strategy:
fail-fast: false
max-parallel: 6
matrix: ${{fromJSON(needs.generate-matrix.outputs.matrix)}}

steps:
- uses: actions/[email protected]
- uses: denoland/setup-deno@v2
uses: actions/setup-node@v4
with:
node-version: 20.x
registry-url: https://registry.npmjs.com

- run: deno run -A www/tasks/build-npm.ts ${{matrix.workspace}}

- run: npm publish --access=public --tag=next
working-directory: ${{matrix.workspace}}/build/npm
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

tag:
if: needs.generate-matrix.outputs.matrix != ''
name: "Tag Release"
runs-on: ubuntu-latest
needs: [jsr, npm]

strategy:
fail-fast: false
matrix: ${{fromJSON(needs.generate-matrix.outputs.matrix)}}

steps:
- uses: actions/[email protected]
with:
token: ${{secrets.FRONTSIDEJACK_GITHUB_TOKEN}}
- run: git tag ${{ matrix.tagname }}
- run: git push origin --tags
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/deno.lock
/**/build/
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright 2024 The Frontside Software, Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ more than a few times are welcome.

1. Create a directory
2. Add a deno.json file with
`{ "name": "@effection-contrib/<you_package_name>", version: "0.1.0", exports: "./mod.ts" }`
`{ "name": "@effection-contrib/<you_package_name>", version: "0.1.0", "exports": "./mod.ts", "license": "MIT" }`
3. Add a README.md (the first sentence of the README will be used as the
description)
4. Add your source code and export it from `mod.ts`
5. Add doc strings to your source code - they will be used for documentation on
the site.

## To publish a new project

1. Member of [jsr.io/@effection-contrib](https://jsr.io/@effection-contrib) has
too add that project to the scope
2. It should be publish on next merge to main
6 changes: 5 additions & 1 deletion deno-deploy/deno-deploy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { type Context, createContext, type Operation } from "effection";
import {
type Context,
createContext,
type Operation,
} from "npm:[email protected]";

export interface DenoDeploy {
/**
Expand Down
3 changes: 2 additions & 1 deletion deno-deploy/deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@effection-contrib/deno-deploy",
"version": "0.1.0",
"exports": "./mod.ts"
"exports": "./mod.ts",
"license": "MIT"
}
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"revolution": "https://deno.land/x/[email protected]/mod.ts",
"revolution/jsx-runtime": "https://deno.land/x/[email protected]/jsx-runtime.ts",
"bdd": "jsr:@std/testing/bdd",
"expect": "jsr:@std/expect"
"expect": "jsr:@std/expect",
"effection": "npm:[email protected]"
},
"compilerOptions": {
"lib": [
Expand Down
7 changes: 0 additions & 7 deletions jsr.json

This file was deleted.

3 changes: 2 additions & 1 deletion task-buffer/deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@effection-contrib/task-buffer",
"version": "0.1.0",
"exports": "./mod.ts"
"exports": "./mod.ts",
"license": "MIT"
}
3 changes: 2 additions & 1 deletion tinyexec/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"exports": "./mod.ts",
"imports": {
"tinyexec": "npm:[email protected]"
}
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion tinyexec/tinyexec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type Stream,
stream,
useAbortSignal,
} from "effection";
} from "npm:effection@3.0.3";
import { type KillSignal, type Options, type Output, x as $x } from "tinyexec";

export interface TinyProcess extends Operation<Output> {
Expand Down
3 changes: 2 additions & 1 deletion websocket/deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@effection-contrib/websocket",
"version": "1.0.0",
"exports": "./mod.ts"
"exports": "./mod.ts",
"license": "MIT"
}
2 changes: 1 addition & 1 deletion websocket/websocket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type Subscription,
suspend,
useScope,
} from "effection";
} from "npm:effection@3.0.3";

import { useWebSocket, type WebSocketResource } from "./websocket.ts";

Expand Down
4 changes: 2 additions & 2 deletions websocket/websocket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSignal, once, race, resource, spawn } from "effection";
import type { Operation, Stream } from "effection";
import { createSignal, once, race, resource, spawn } from "npm:effection@3.0.3";
import type { Operation, Stream } from "npm:effection@3.0.3";
import { withResolvers } from "./with-resolvers.ts";

/**
Expand Down
2 changes: 1 addition & 1 deletion websocket/with-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type Operation,
type Result,
suspend,
} from "effection";
} from "npm:effection@3.0.3";

export interface WithResolvers<T> {
operation: Operation<T>;
Expand Down
3 changes: 2 additions & 1 deletion www/hooks/use-package.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ export type RenderableDocNode = DocNode & {
MDXDoc?: () => JSXElement;
};

const DenoJson = z.object({
export const DenoJson = z.object({
name: z.string(),
version: z.optional(z.string()),
exports: z.union([z.record(z.string()), z.string()]),
private: z.union([z.undefined(), z.literal(true)]),
license: z.string(),
});

export const DEFAULT_MODULE_KEY = ".";
Expand Down
56 changes: 56 additions & 0 deletions www/tasks/build-npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { build, emptyDir } from "jsr:@deno/dnt";
import { DenoJson } from "../hooks/use-package.tsx";

const outDir = "./build/npm";

await emptyDir(outDir);

let [workspace] = Deno.args;
if (!workspace) {
throw new Error("a version argument is required to build the npm package");
}

let mod = await import(`../../${workspace}/deno.json`, {
with: { type: "json" },
});
let deno = DenoJson.parse(mod.default);

let entryPoints = typeof deno.exports === "string"
? [deno.exports]
: Object.entries(deno.exports).map(([name, path]) => ({
kind: "export" as const,
name,
path,
}));

Deno.chdir(workspace);

await build({
entryPoints,
outDir,
shims: {
deno: false,
},
test: false,
typeCheck: false,
package: {
// package.json properties
name: deno.name,
version: deno.version!,
license: deno.license,
author: "[email protected]",
repository: {
type: "git",
url: "git+https://github.com/thefrontside/effection-contrib.git",
},
bugs: {
url: "https://github.com/thefrontside/effection-contrib/issues",
},
engines: {
node: ">= 16",
},
sideEffects: false,
},
});

await Deno.copyFile(`README.md`, `${outDir}/README.md`);
53 changes: 53 additions & 0 deletions www/tasks/publish-matrix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { call, each, main } from "effection";
import { usePackages } from "../hooks/use-packages.ts";
import { DenoJson } from "../hooks/use-package.tsx";
import { x } from "../../tinyexec/mod.ts";

await main(function* () {
let packages = yield* usePackages();

let include: Record<string, unknown>[] = [];

for (let pkgmeta of packages) {
let mod = yield* call(() =>
import(`${pkgmeta.path}/deno.json`, { with: { type: "json" } })
);
let pkg = DenoJson.parse(mod.default);

let tagname = `${pkg.name.split("/")[1]}-v${pkg.version}`;

let git = yield* x(`git`, [`tag`, `--list`, tagname]);

let output = [];

for (let line of yield* each(git.lines)) {
output.push(line);
yield* each.next();
}

// if output of `git tag --list ${{tagname}}` is empty, tag does not exists
// ergo we publish
if (output.join("").trim() === "") {
include.push({
workspace: pkgmeta.workspace,
tagname,
name: pkg.name,
version: pkg.version,
});
}
}

let outputValue = `matrix=${JSON.stringify({ include })}`;

if (Deno.env.has("GITHUB_OUTPUT")) {
const githubOutput = Deno.env.get("GITHUB_OUTPUT") as string;
yield* call(() =>
Deno.writeTextFile(githubOutput, outputValue, {
append: true,
})
);
} else {
// for local dev
console.log(outputValue);
}
});