Skip to content

Commit

Permalink
Merge pull request #1 from httpland/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
TomokiMiyauci authored Mar 16, 2023
2 parents 3b68aba + 8555936 commit d6fa794
Show file tree
Hide file tree
Showing 12 changed files with 379 additions and 8 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/codeql-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "CodeQL"

on:
push:
branches: [ main ]

pull_request:
branches: [ main ]

schedule:
- cron: '18 15 * * 2'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'typescript' ]

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
57 changes: 57 additions & 0 deletions .github/workflows/release-npm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: release-npm

on:
release:
types: [published]

jobs:
release:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]
deno: [v1.x]
node: [16.x]

steps:
- name: Checkout
uses: actions/checkout@v3

- uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno }}

- name: Cache node_modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v2.0.1
with:
version: 7.16.0
run_install: |
- recursive: true
args: [--frozen-lockfile, --prefer-offline, --ignore-scripts]
- name: Get tag version
if: startsWith(github.ref, 'refs/tags/')
id: get_tag_version
run: echo ::set-output name=TAG_VERSION::${GITHUB_REF/refs\/tags\//}

- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
registry-url: 'https://registry.npmjs.org'

- name: build
run: deno run -A ./_tools/build_npm.ts ${{steps.get_tag_version.outputs.TAG_VERSION}}

- name: publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: deno run -A ./_tools/publish_npm.ts ${{steps.get_tag_version.outputs.TAG_VERSION}}

79 changes: 79 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: release

on:
push:
branches:
- beta
- main

jobs:
lint:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]
deno: [v1.x]

steps:
- name: Checkout
uses: actions/checkout@v3

- uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno }}

- name: Lint
run: |
deno fmt --check
deno lint
test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]
deno: [v1.x]

steps:
- name: Checkout
uses: actions/checkout@v3

- uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno }}

- name: Test
run: deno task test --coverage=coverage

- name: Generate coverage
if: ${{ matrix.deno == 'v1.x' }}
run: deno task coverage coverage --output=cov_profile.lcov --lcov

- uses: codecov/codecov-action@v3
if: ${{ matrix.deno == 'v1.x' }}
with:
files: cov_profile.lcov

release:
needs: [lint, test]
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]

steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.GH_TOKEN }}

- uses: cycjimmy/semantic-release-action@v3
with:
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
43 changes: 43 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: test

on: push
jobs:
lint:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, ubuntu-22.04, macos-latest, windows-latest]
deno: [v1.x]

steps:
- name: Checkout
uses: actions/checkout@v3

- uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno }}

- name: Lint
run: |
deno fmt --check
deno lint
test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, ubuntu-22.04, macos-latest, windows-latest]
deno: [v1.x]

steps:
- name: Checkout
uses: actions/checkout@v3

- uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno }}

- name: Test
run: deno task test
25 changes: 25 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"branches": [
"main",
{
"name": "beta",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/github",
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md"
],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
],
"tagFormat": "${version}"
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 1.0.0-beta.1 (2023-02-13)


### Features

* **types:** add middleware interface ([936af7b](https://github.com/httpland/http-middleware/commit/936af7bdf9229243e3256ac0397f39e1071110c1))
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ Define standard HTTP middleware specifications. This is intended to increase the
interoperability of the HTTP library's own middleware.

It consists only of the web standards stack and is compatible with many
Browsers.
browsers.

## Terms

<dl>
<dt>Upstream</dt>
<dd>Refers to HTTP requests forwarded from the client to the server.</dd>

<dt>Downstream</dt>
<dd>Refers to the HTTP response forwarded from the server to the client.</dd>
</dl>

## Interface

Expand All @@ -28,17 +38,25 @@ interface Handler {

`Middleware` has the following features:

- Compatible with `Handler`.
- Compliant with [Fetch API](https://fetch.spec.whatwg.org/).
- Compliant with `Handler`.

`Handler` is a powerful interface for handling HTTP requests. The `Middleware`
is purely an extension and compatibility with `Handler`.

- It can access to the `Request`.
- It can access the next handler.
- It can call the next handler.
- It can choose not to call the next handler.
- It can access the next handler's return value (`Response`).
- It can return `Response`.
- It is a pure function.

`Middleware` is a pure function that returns a value. Implementations are
expected to have no side effects.
- It is self-contained.
- It can handle upstream.
- It can handle downstream.
- It can handle next handler.

## Implementation

See [chain-handler](https://github.com/httpland/chain-handler) for a concrete
implementation that can handle middleware

## License

Expand Down
23 changes: 23 additions & 0 deletions _tools/build_npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { build, emptyDir } from "https://deno.land/x/dnt@0.33.1/mod.ts";
import { join } from "https://deno.land/std@0.177.0/path/mod.ts";
import { makeOptions } from "./meta.ts";

async function buildPkg(version: string): Promise<void> {
await emptyDir("./npm");
const pkg = makeOptions(version);
await Deno.copyFile("LICENSE", join(pkg.outDir, "LICENSE"));
Deno.copyFile(
join(".", "README.md"),
join(pkg.outDir, "README.md"),
);
await build(pkg);
}

if (import.meta.main) {
const version = Deno.args[0];
if (!version) {
console.error("argument is required");
Deno.exit(1);
}
await buildPkg(version);
}
38 changes: 38 additions & 0 deletions _tools/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { BuildOptions } from "https://deno.land/x/dnt@0.33.1/mod.ts";

export const makeOptions = (version: string): BuildOptions => ({
test: false,
shims: {},
compilerOptions: { lib: ["esnext", "dom"] },
typeCheck: true,
entryPoints: ["./mod.ts"],
outDir: "./npm",
package: {
name: "@httpland/http-middleware",
version,
description: "HTTP middleware specification",
keywords: [
"http",
"middleware",
"http-middleware",
"handler",
"http-handler",
"next",
"request",
"response",
],
license: "MIT",
homepage: "https://github.com/httpland/http-middleware",
repository: {
type: "git",
url: "git+https://github.com/httpland/http-middleware.git",
},
bugs: {
url: "https://github.com/httpland/http-middleware/issues",
},
sideEffects: false,
type: "module",
publishConfig: { access: "public" },
},
packageManager: "pnpm",
});
26 changes: 26 additions & 0 deletions _tools/publish_npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { prerelease, valid } from "https://deno.land/x/semver@v1.4.1/mod.ts";
import { makeOptions } from "./meta.ts";

if (import.meta.main) {
const version = Deno.args[0];
if (!version) {
console.error("arg of version is required");
Deno.exit(1);
}
if (!valid(version)) {
console.error("The argument of version is invalid");
Deno.exit(1);
}

const isPrerelease = prerelease(version);
const tag = isPrerelease?.[0] ?? "latest";

const pkg = makeOptions(version);
const result = await Deno.run({
cmd: ["npm", "publish", pkg.outDir, "--tag", String(tag)],
stdout: "piped",
})
.output();

console.log(new TextDecoder().decode(result));
}
Loading

0 comments on commit d6fa794

Please sign in to comment.