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 committed Apr 2, 2023
2 parents b41f9b9 + f397e57 commit 7e301a6
Show file tree
Hide file tree
Showing 20 changed files with 607 additions and 2 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/codeql-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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: 6.23.6
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}}

77 changes: 77 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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
run: deno coverage coverage --output=cov_profile.lcov --lcov

- uses: codecov/codecov-action@v3
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-04-02)


### Features

* add middleware factory for referrer policy header ([35f4f86](https://github.com/httpland/referrer-policy-middleware/commit/35f4f86ef75229d0c30451b8858f40047a9e276d))
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

HTTP referrer policy middleware.

Compliant with
[Referrer Policy](https://w3c.github.io/webappsec-referrer-policy/#grammardef-extension-token).
Compliant with [Referrer Policy](https://www.w3.org/TR/referrer-policy/).

## Middleware

Expand Down
7 changes: 7 additions & 0 deletions _dev_deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export {
assert,
assertEquals,
} from "https://deno.land/std@0.181.0/testing/asserts.ts";
export { describe, it } from "https://deno.land/std@0.181.0/testing/bdd.ts";
export { equalsResponse } from "https://deno.land/x/http_utils@1.0.0/response.ts";
export { Header } from "./constants.ts";
6 changes: 6 additions & 0 deletions _test_import_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"imports": {
"https://deno.land/x/referrer_policy_middleware@$VERSION/": "./",
"https://deno.land/std/": "https://deno.land/std@0.181.0/"
}
}
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);
}
58 changes: 58 additions & 0 deletions _tools/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { BuildOptions } from "https://deno.land/x/dnt@0.33.1/mod.ts";

export const makeOptions = (version: string): BuildOptions => ({
test: false,
shims: {},
compilerOptions: {
lib: ["dom", "esnext", "dom.iterable"],
},
typeCheck: true,
entryPoints: ["./mod.ts"],
outDir: "./npm",
package: {
name: "@httpland/referrer-policy-middleware",
version,
description: "HTTP referrer policy middleware",
keywords: [
"http",
"middleware",
"header",
"policy",
"referrer-policy",
"referrer",
"security",
"fetch-api",
],
license: "MIT",
homepage: "https://github.com/httpland/referrer-policy-middleware",
repository: {
type: "git",
url: "git+https://github.com/httpland/referrer-policy-middleware.git",
},
bugs: {
url: "https://github.com/httpland/referrer-policy-middleware/issues",
},
sideEffects: false,
type: "module",
publishConfig: {
access: "public",
},
},
packageManager: "pnpm",
mappings: {
"https://deno.land/x/http_middleware@1.0.0/mod.ts": {
name: "@httpland/http-middleware",
version: "1.0.0",
},
"https://deno.land/x/isx@1.1.1/is_string.ts": {
name: "@miyauci/isx",
version: "1.1.1",
subPath: "is_string",
},
"https://deno.land/x/http_utils@1.0.0/message.ts": {
name: "@httpland/http-utils",
version: "1.0.0",
subPath: "message.js",
},
},
});
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.0/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));
}

0 comments on commit 7e301a6

Please sign in to comment.