Skip to content

Commit

Permalink
chore: migrate to deno workspaces (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter authored Nov 20, 2024
1 parent 6f419fc commit c7d59df
Show file tree
Hide file tree
Showing 104 changed files with 4,108 additions and 4,780 deletions.
7 changes: 4 additions & 3 deletions .github/deno_tag.ts → .github/deno_bump.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// deno-lint-ignore-file no-console
// Imports
import { fromFileUrl, resolve } from "@std/path"
import * as JSONC from "@std/jsonc"
Expand All @@ -16,9 +17,9 @@ const path = resolve(fromFileUrl(import.meta.resolve("../")), `${name}`, "deno.j
console.log(`patching: ${path}`)

// Patch config version
const config = JSONC.parse(await Deno.readTextFile(path)) as record<string>
const raw = await Deno.readTextFile(path)
const config = JSONC.parse(raw) as record<string>
const { version: previous } = config
config.version = version
console.log(`version: ${previous}${version}`)
await Deno.writeTextFile(path, `${JSON.stringify(config, null, 2)}\n`)
assert(semver.greaterThan(semver.parse(version), semver.parse(previous)), "expected new version to be greater than previous one")
await Deno.writeTextFile(path, raw.replace(`"version": "${previous}"`, `"version": "${version}"`))
147 changes: 0 additions & 147 deletions .github/deno_config.ts

This file was deleted.

14 changes: 2 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ jobs:
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Run deno task coverage
- name: Run deno task make:coverage
run: |
deno task coverage
deno run --allow-read --allow-write=coverage --allow-net jsr:@libs/bundle/ts/cli/coverage --root=coverage --summary
deno task make:coverage
mv coverage _site
- uses: actions/upload-pages-artifact@v3
- id: pages
Expand All @@ -101,15 +100,6 @@ jobs:
run: |
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
- name: Run deno task make:config
run: |
deno task make:config
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m 'chore: update `deno.jsonc`'
git pull --rebase
git push
fi
- name: Run deno task make:readme
run: |
deno task make:readme
Expand Down
38 changes: 4 additions & 34 deletions .github/workflows/ci_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
- run: deno lint
- run: deno fmt --check
- run: |
if [ "$(jq -r '.mirror' deno.jsonc)" != "true"]; then
deno doc --lint mod.ts
fi
- name: Run deno publish --dry-run
run: |
SLOW_TYPES="$(jq -r 'if .types == "slow" then "--allow-slow-types" else "" end' deno.jsonc)"
deno publish --dry-run --quiet --allow-dirty $SLOW_TYPES
- run: deno task lint --check

codeql:
name: Code quality
Expand Down Expand Up @@ -118,11 +109,8 @@ jobs:
outputs:
releasable: ${{ steps.releasable.outputs.releasable }}
has_build: ${{ steps.package.outputs.has_build }}
has_bench: ${{ steps.package.outputs.has_bench }}
has_npm: ${{ steps.package.outputs.has_npm }}
has_x: ${{ steps.package.outputs.has_x }}
slow_types: ${{ steps.package.outputs.slow_types }}
versioning: ${{ steps.package.outputs.versioning }}
tag: ${{ steps.tag.outputs.tag }}
version: ${{ steps.tag.outputs.semver }}
steps:
Expand All @@ -141,11 +129,8 @@ jobs:
id: package
run: |
echo "has_build=$(jq -r 'if .tasks.build then "run" else empty end' deno.jsonc)" >> "$GITHUB_OUTPUT"
echo "has_bench=$(jq -r 'if .tasks.bench then "run" else empty end' deno.jsonc)" >> "$GITHUB_OUTPUT"
echo "has_npm=$(jq -r 'if .npm then "run" else empty end' deno.jsonc)" >> "$GITHUB_OUTPUT"
echo "has_x=$(jq -r 'if .["deno.land/x"] then "run" else empty end' deno.jsonc)" >> "$GITHUB_OUTPUT"
echo "slow_types=$(jq -r 'if .types == "slow" then "--allow-slow-types" else "" end' deno.jsonc)" >> "$GITHUB_OUTPUT"
echo "versioning=$(jq -r 'if .versioning == "date" then "date" else "semver" end' deno.jsonc)" >> "$GITHUB_OUTPUT"
# Build
- run: deno task build
if: ${{ steps.package.outputs.has_build }}
Expand All @@ -154,7 +139,6 @@ jobs:
- run: deno task test:others
# Bench
- run: deno task bench
if: ${{ steps.package.outputs.has_bench }}
# Tag
- name: Run git tag --list '${{ inputs.package }}-*'
id: releasable
Expand All @@ -171,26 +155,13 @@ jobs:
run: |
CURRENT_SEMVER="$(jq -r .version deno.jsonc)"
CURRENT_TAG="$(git tag --list '${{ inputs.package }}-*' | tail -1)"
if [ "${{ steps.package.outputs.versioning }}" == "date" ]; then
TAG="${{ inputs.package }}-$(date '+%Y.%m.%d')"
SEMVER="$(date '+%Y.%-m.%-d')"
if [ "$CURRENT_SEMVER" == "$SEMVER" ]; then
echo -e "\033[33mversion $SEMVER is already published, skipping\033[0m"
TAG=""
SEMVER=""
fi
else
TAG="${{ steps.tag-next.outputs.tag }}"
SEMVER="${{ steps.tag-next.outputs.semver }}"
fi
echo "versioning: ${{ steps.package.outputs.versioning }}"
echo "┌──────────────┬──────────────────────┬──────────────────────┐"
printf "│ %-12s │ %-20s │ %-20s │\n" "" "CURRENT" "NEXT"
printf "│ %-12s │ %-20s │ %-20s │\n" "TAG" "$CURRENT_TAG" "$TAG"
printf "│ %-12s │ %-20s │ %-20s │\n" "SEMVER" "$CURRENT_SEMVER" "$SEMVER"
echo "├──────────────┴──────────────────────┴──────────────────────┤"
printf "│ %-12s │ %-43s │\n" "VERSIONING" "${{ steps.package.outputs.versioning }}"
echo "└────────────────────────────────────────────────────────────┘"
echo "└──────────────┴──────────────────────┴──────────────────────┘"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "semver=$SEMVER" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -231,11 +202,11 @@ jobs:
git push
fi
# Tag
- name: Run deno task tag
- name: Run deno task make:bump
if: ${{ needs.test.outputs.tag }}
run: |
pushd "$(git rev-parse --show-toplevel)"
deno task tag --version '${{ needs.test.outputs.version }}' ${{ inputs.package }}
deno task make:bump --version '${{ needs.test.outputs.version }}' ${{ inputs.package }}
popd
deno fmt deno.jsonc
git add deno.jsonc
Expand All @@ -250,7 +221,6 @@ jobs:
git pull --rebase
git push origin '${{ needs.test.outputs.tag }}'
# Publish
- run: deno publish ${{ needs.test.outputs.slow_types }}
- name: Run npm publish
if: ${{ needs.test.outputs.has_npm }}
run: deno run --allow-all jsr:@libs/bundle/ts/cli/publish deno.jsonc --loglevel debug --npm.registry 'https://registry.npmjs.org' --npm.token '${{ secrets.NPM_TOKEN }}' --npm.scope '@lowlighter' --npm.access public
Expand Down
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ The following tasks are available from `@libs` scope:
- `playground?:string`: URL to playground
- `npm?:boolean`: Is this package published on npm?
- `["deno.land/x"]?:boolean`: Is this package published on deno.land/x?
- `types?:"slow"`: Use `--allow-slow-types` when publishing _(do not use except is absolutely needed)_
- `test:permissions?:Deno.TestDefinition["permissions"]`: Permissions required for tests _(these should be minimal, note that `--allow-run=deno,node,bun,npx` permissions is always appended as they're required for cross-runtime testing)_
- `make:config-upgrade`<sub>👨‍💻</sub>: Same as `make:config` but also upgrade dependencies of `*/deno.jsonc` with the ones from `deno.jsonc`
- _This action is to be performed by a maintainer, each package should be separately commited to ensure that each package are correctly rebuild in the CI_
Expand Down
4 changes: 2 additions & 2 deletions api/bundle/css/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env DENO_DIR=/tmp deno run
import { bundle } from "jsr:@libs/bundle/css"
import { STATUS_CODE, STATUS_TEXT } from "jsr:@std/http/status"
import { bundle } from "@libs/bundle/css"
import { STATUS_CODE, STATUS_TEXT } from "@std/http/status"

/** Bundle CSS */
export default async function (request: Request) {
Expand Down
4 changes: 2 additions & 2 deletions api/bundle/css/compatibility.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env DENO_DIR=/tmp deno run
import { compatibility } from "jsr:@libs/bundle/css"
import { STATUS_CODE, STATUS_TEXT } from "jsr:@std/http/status"
import { compatibility } from "@libs/bundle/css"
import { STATUS_CODE, STATUS_TEXT } from "@std/http/status"

/** CSS compatibility report */
export default async function (request: Request) {
Expand Down
4 changes: 2 additions & 2 deletions api/bundle/ts/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env DENO_DIR=/tmp deno run
import { bundle } from "jsr:@libs/bundle/ts"
import { STATUS_CODE, STATUS_TEXT } from "jsr:@std/http/status"
import { bundle } from "@libs/bundle/ts"
import { STATUS_CODE, STATUS_TEXT } from "@std/http/status"

/** Bundle TypeScript */
export default async function (request: Request) {
Expand Down
4 changes: 2 additions & 2 deletions api/crypto/totp/get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env DENO_DIR=/tmp deno run
import { totp } from "jsr:@libs/crypto/totp"
import { STATUS_CODE, STATUS_TEXT } from "jsr:@std/http/status"
import { totp } from "@libs/crypto/totp"
import { STATUS_CODE, STATUS_TEXT } from "@std/http/status"

/** Get OTP */
export default async function (request: Request) {
Expand Down
6 changes: 3 additions & 3 deletions api/crypto/totp/qrcode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env DENO_DIR=/tmp deno run
import { qrcode } from "jsr:@libs/qrcode"
import { otpauth } from "jsr:@libs/crypto/totp"
import { STATUS_CODE, STATUS_TEXT } from "jsr:@std/http/status"
import { qrcode } from "@libs/qrcode"
import { otpauth } from "@libs/crypto/totp"
import { STATUS_CODE, STATUS_TEXT } from "@std/http/status"

/** Generate QR Code for OTP secret */
export default function (request: Request) {
Expand Down
4 changes: 2 additions & 2 deletions api/crypto/totp/secret.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env DENO_DIR=/tmp deno run
import { otpsecret } from "jsr:@libs/crypto/totp"
import { STATUS_CODE, STATUS_TEXT } from "jsr:@std/http/status"
import { otpsecret } from "@libs/crypto/totp"
import { STATUS_CODE, STATUS_TEXT } from "@std/http/status"

/** Generate OTP secret */
export default function (request: Request) {
Expand Down
4 changes: 2 additions & 2 deletions api/crypto/totp/verify.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env DENO_DIR=/tmp deno run
import { verify } from "jsr:@libs/crypto/totp"
import { STATUS_CODE, STATUS_TEXT } from "jsr:@std/http/status"
import { verify } from "@libs/crypto/totp"
import { STATUS_CODE, STATUS_TEXT } from "@std/http/status"

/** Get OTP */
export default async function (request: Request) {
Expand Down
2 changes: 1 addition & 1 deletion api/deno/run.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env DENO_DIR=/tmp deno run
import { STATUS_CODE, STATUS_TEXT } from "jsr:@std/http/status"
import { STATUS_CODE, STATUS_TEXT } from "@std/http/status"

/** Maximum runtime execution */
const TIMEOUT = 5 * 1000
Expand Down
4 changes: 2 additions & 2 deletions api/diff/diff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env DENO_DIR=/tmp deno run
import { diff } from "jsr:@libs/diff/diff"
import { STATUS_CODE, STATUS_TEXT } from "jsr:@std/http/status"
import { diff } from "@libs/diff/diff"
import { STATUS_CODE, STATUS_TEXT } from "@std/http/status"

/** Diff */
export default async function (request: Request) {
Expand Down
4 changes: 2 additions & 2 deletions api/qrcode/get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env DENO_DIR=/tmp deno run
import { qrcode } from "jsr:@libs/qrcode"
import { STATUS_CODE, STATUS_TEXT } from "jsr:@std/http/status"
import { qrcode } from "@libs/qrcode"
import { STATUS_CODE, STATUS_TEXT } from "@std/http/status"

/** Generate QR code */
export default function (request: Request) {
Expand Down
Loading

0 comments on commit c7d59df

Please sign in to comment.