Skip to content

Commit

Permalink
Added Hono client
Browse files Browse the repository at this point in the history
  • Loading branch information
leo committed May 6, 2024
1 parent 3070e54 commit fb750a7
Show file tree
Hide file tree
Showing 20 changed files with 665 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/actions/bump-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Publish Experimental Packages
description: Bumps the version of an npm package and publishes it with an experimental tag.

on:
workflow_call: []

inputs:
package_dir:
description: Directory of the Package to Publish
required: true
default: './'

outputs:
VERSION_TAG:
description: Generated Experimental Version Tag for This Package
value: ${{ steps.version-tag.outputs.VERSION_TAG }}

runs:
using: composite
steps:
- name: Construct Experimental Version Tag
id: version-tag
shell: bash
run: |
BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | sed -r 's/([a-z0-9])([A-Z])/\1-\L\2/g' | sed 's/_/-/g' | sed 's/\//-/g')
echo "VERSION_TAG=$(echo $BRANCH_NAME)-experimental" >> $GITHUB_ENV
echo "VERSION_TAG=$(echo $VERSION_TAG)" >> $GITHUB_OUTPUT
- name: Bump ${{ inputs.package_dir }}
shell: bash
run: |
cd ${{ inputs.package_dir }}
PACKAGE_NAME=$(cat package.json | grep "name" | cut -d':' -f 2 | cut -d'"' -f 2)
echo "PACKAGE_NAME=${PACKAGE_NAME}" >> $GITHUB_ENV
# Matches any version that ends with "-author-ron-123-experimental.<number>". e.g. 1.0.0-leo-ron-123-experimental.0
REGEX="\-$VERSION_TAG.[0-9]\{1,\}$"
# Get all versions
ALL_VERSIONS=$(npm view $PACKAGE_NAME versions --json | jq -r '.[]')
# Check if the experimental version already exists
if ! echo "$ALL_VERSIONS" | grep -q "$REGEX"; then
# If not, create it
npm version prerelease --preid=$VERSION_TAG --no-git-tag-version
else
# Otherwise up it
LATEST_VERSION=$(echo "$ALL_VERSIONS" | grep "$REGEX" | tail -1)
npm version $(npx semver $LATEST_VERSION -i prerelease --preid="$VERSION_TAG") --no-git-tag-version
fi
- name: Publish to npm
shell: bash
run: cd ${{ inputs.package_dir }} && npm publish --tag="$VERSION_TAG"
21 changes: 21 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'

# Open a new pull request every week, if there are updates available.
schedule:
interval: 'weekly'
timezone: 'Europe/Berlin'

labels:
- 'enhancement'

# Create one PR for all production dependencies, and one for all
# development dependencies. The latter is easier/faster to merge because it
# usually only affects local development.
groups:
production:
dependency-type: 'production'
development:
dependency-type: 'development'
51 changes: 51 additions & 0 deletions .github/workflows/publish-experimental.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Publish Experimental Packages

on:
pull_request:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
permissions:
# Required for `actions/checkout@v3`
contents: read
# Required for `thollander/actions-comment-pull-request@v2`
pull-requests: write

steps:
- name: Code Checkout
uses: actions/[email protected]

# Needed only for bumping package version and publishing npm packages.
- name: Set up Node.js
uses: actions/[email protected]
- run: echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_READ_AND_WRITE }}' > ~/.npmrc

- name: Set up Bun
uses: oven-sh/setup-bun@v1

- name: Install Dependencies
run: bun install --frozen-lockfile

- name: Build Package
run: bun run build

- name: Bump `hono-ronin`
id: bump-ronin
uses: ./.github/actions/bump-version

- name: Comment on PR
uses: thollander/actions-comment-pull-request@v2
with:
comment_tag: packages_announcement
message: |
Released an experimental package:
```bash
bun add hono-ronin@${{ env.VERSION_TAG }}
```
This package will be removed after the pull request has been merged.
71 changes: 71 additions & 0 deletions .github/workflows/publish-manually.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Manually Publish npm Packages

on:
workflow_dispatch:
inputs:
version_type:
description: Choose a version type to bump the package version by.
required: true
default: 'patch'
type: choice
options:
- major
- minor
- patch
- prerelease

jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Generate GitHub App Token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.ORG_GH_RONIN_APP_ID }}
private_key: ${{ secrets.ORG_GH_RONIN_APP_PRIVATE_KEY }}

- name: Code Checkout
uses: actions/[email protected]
with:
token: ${{ steps.generate_token.outputs.token }}

# Needed only for bumping package version and publishing npm packages.
- name: Set up Node.js
uses: actions/[email protected]
- run: echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_READ_AND_WRITE }}' > ~/.npmrc

- name: Set up Bun
uses: oven-sh/setup-bun@v1

- name: Install Dependencies
run: bun install --frozen-lockfile

- name: Build Package
run: bun run build

- name: Set Git Config
run: |
# See where these config values come from at https://stackoverflow.com/a/74071223
git config --global user.name "ronin-app[bot]"
git config --global user.email 135042755+ronin-app[bot]@users.noreply.github.com
- name: Bump `hono-ronin`
run: |
npm version ${{ inputs.version_type }} --git-tag-version=false
echo "NEW_VERSION=$(npm pkg get version --workspaces=false | tr -d \")" >> $GITHUB_ENV
- name: Push New Version
run: |
git fetch
git checkout ${GITHUB_HEAD_REF}
git pull origin ${GITHUB_HEAD_REF}
git commit -a -m '${{ env.NEW_VERSION }}' --no-verify
git tag -a ${{ env.NEW_VERSION }} -m '${{ env.NEW_VERSION }}'
git push origin ${GITHUB_HEAD_REF}
# Push tag
git push origin ${{ env.NEW_VERSION }}
- name: Publish npm Package
run: npm publish
28 changes: 28 additions & 0 deletions .github/workflows/remove-experimental.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Remove Experimental Packages

on:
pull_request:
branches:
- main
types: [closed]

jobs:
deploy:
runs-on: ubuntu-latest
name: Remove Experimental Packages
steps:
- name: Code Checkout
uses: actions/[email protected]

- name: Set up Node.js
uses: actions/[email protected]
- run: echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_READ_AND_WRITE }}' > ~/.npmrc

# This converts the branch name into dash-case, so it can be used as a
# valid dist-tag.
- name: Extract Branch Name
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | sed -r 's/([a-z0-9])([A-Z])/\1-\L\2/g' | sed 's/_/-/g' | sed 's/\//-/g')" >> $GITHUB_ENV

- name: Remove Experimental Packages
run: npm dist-tag rm hono-ronin $BRANCH_NAME-experimental
23 changes: 23 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Dependabot Auto-Merge
on: pull_request

permissions:
contents: write
pull-requests: write

jobs:
dependabot:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1
with:
github-token: '${{ github.token }}'

- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ github.token }}
73 changes: 73 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Validate

on:
pull_request:
branches:
- main

jobs:
lint:
name: Linting
runs-on: ubuntu-latest
steps:
- name: Code Checkout
uses: actions/checkout@v4

- name: Set up Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.6

# Cache the local `node_modules` directory.
- name: Restore npm cache
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('patches/**') }}-${{ hashFiles('bun.lockb') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('patches/**') }}-
${{ runner.os }}-build-${{ hashFiles('patches/**') }}-
${{ runner.os }}-${{ hashFiles('patches/**') }}-
- name: Install Dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile

- name: Code Linting
run: bun run lint

test:
name: Testing
runs-on: ubuntu-latest
steps:
- name: Code Checkout
uses: actions/checkout@v4

- name: Set up Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.6

# Cache the local `node_modules` directory.
- name: Restore npm cache
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('patches/**') }}-${{ hashFiles('bun.lockb') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('patches/**') }}-
${{ runner.os }}-build-${{ hashFiles('patches/**') }}-
${{ runner.os }}-${{ hashFiles('patches/**') }}-
- name: Install Dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile

- name: Testing
run: bun run test
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Build output
dist

# Dependencies
node_modules
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bunx lint-staged
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["biomejs.biome", "oven.bun-vscode", "redhat.vscode-yaml"]
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"editor.rulers": [80, 120],

"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true,

"javascript.updateImportsOnFileMove.enabled": "always",
"javascript.preferences.importModuleSpecifier": "non-relative",

"typescript.updateImportsOnFileMove.enabled": "always",
"typescript.preferences.importModuleSpecifier": "non-relative"
}
21 changes: 21 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.1/schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUnusedImports": "warn",
"noUnusedVariables": "warn"
}
}
}
}
Binary file added bun.lockb
Binary file not shown.
7 changes: 7 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[install]
exact = true

[test]
coverage = true
coverageThreshold = 1.0
preload = ['./tests/preload.ts']
Loading

0 comments on commit fb750a7

Please sign in to comment.