Skip to content

Commit

Permalink
feat: バックエンドをHonoへ移行し、新たにruntimeを生成 (#70)
Browse files Browse the repository at this point in the history
Co-authored-by: rai <[email protected]>
  • Loading branch information
sou1118 and r4ai authored Oct 14, 2024
1 parent 4a4976c commit 4562bf6
Show file tree
Hide file tree
Showing 32 changed files with 1,226 additions and 849 deletions.
78 changes: 18 additions & 60 deletions .github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Backend CI

on:
push:
branches:
Expand All @@ -22,6 +23,7 @@ jobs:
filters: |
backend:
- 'backend/**'
- .tool-versions
workflows:
- '.github/workflows/backend-ci.yml'
Expand All @@ -35,14 +37,12 @@ jobs:
working-directory: ./backend
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Cache dependencies
uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
- name: Install Rust toolchain
run: rustup toolchain install stable
- name: Install rustfmt
run: rustup component add rustfmt
- name: Install tools
uses: jdx/mise-action@f8dfbcc150159126838e44b882bf34bd98fd90f3 # v2.1.0
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Check formatting
run: cargo fmt --all -- --check
run: bun run format

lint:
name: Lint
Expand All @@ -54,14 +54,12 @@ jobs:
working-directory: ./backend
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Cache dependencies
uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
- name: Install Rust toolchain
run: rustup toolchain install stable
- name: Install clippy
run: rustup component add clippy
- name: Install tools
uses: jdx/mise-action@f8dfbcc150159126838e44b882bf34bd98fd90f3 # v2.1.0
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Check linting
run: cargo clippy -- -D warnings
run: bun run lint

build:
name: Build
Expand All @@ -73,48 +71,12 @@ jobs:
working-directory: ./backend
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Cache dependencies
uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
- name: Install Rust toolchain
run: rustup toolchain install stable
- name: Build
run: cargo build

test:
name: Test
runs-on: ubuntu-24.04
needs: changes
if: needs.changes.outputs.backend == 'true' || needs.changes.outputs.workflows == 'true'
defaults:
run:
working-directory: ./backend
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Cache dependencies
uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
- name: Install Rust toolchain
run: rustup toolchain install stable
- name: Test
run: cargo test

machete:
name: Machete
runs-on: ubuntu-24.04
needs: changes
if: needs.changes.outputs.backend == 'true' || needs.changes.outputs.workflows == 'true'
defaults:
run:
working-directory: ./backend
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Cache dependencies
uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
- name: Install Rust toolchain
run: rustup toolchain install stable
- name: Install machete
run: cargo install cargo-machete
- name: Run machete
run: cargo machete
- name: Install tools
uses: jdx/mise-action@f8dfbcc150159126838e44b882bf34bd98fd90f3 # v2.1.0
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Check build
run: bun run build

generate:
name: Generate OpenAPI Schema
Expand All @@ -126,10 +88,6 @@ jobs:
working-directory: ./backend
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Cache dependencies
uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
- name: Install Rust toolchain
run: rustup toolchain install stable
- name: Install tools
uses: jdx/mise-action@f8dfbcc150159126838e44b882bf34bd98fd90f3 # v2.1.0
- name: Install dependencies
Expand Down
117 changes: 117 additions & 0 deletions .github/workflows/runtime-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Runtime CI
on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
changes:
name: Changes
runs-on: ubuntu-24.04
outputs:
runtime: ${{ steps.changes.outputs.runtime }}
workflows: ${{ steps.changes.outputs.workflows }}
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Check runtime files changed
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: changes
with:
filters: |
runtime:
- 'runtime/**'
workflows:
- '.github/workflows/runtime-ci.yml'
format:
name: Format
runs-on: ubuntu-24.04
needs: changes
if: needs.changes.outputs.runtime == 'true' || needs.changes.outputs.workflows == 'true'
defaults:
run:
working-directory: ./runtime
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Cache dependencies
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
- name: Install Rust toolchain
run: rustup toolchain install stable
- name: Install rustfmt
run: rustup component add rustfmt
- name: Check formatting
run: cargo fmt --all -- --check

lint:
name: Lint
runs-on: ubuntu-24.04
needs: changes
if: needs.changes.outputs.runtime == 'true' || needs.changes.outputs.workflows == 'true'
defaults:
run:
working-directory: ./runtime
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Cache dependencies
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
- name: Install Rust toolchain
run: rustup toolchain install stable
- name: Install clippy
run: rustup component add clippy
- name: Check linting
run: cargo clippy -- -D warnings

build:
name: Build
runs-on: ubuntu-24.04
needs: changes
if: needs.changes.outputs.runtime == 'true' || needs.changes.outputs.workflows == 'true'
defaults:
run:
working-directory: ./runtime
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Cache dependencies
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
- name: Install Rust toolchain
run: rustup toolchain install stable
- name: Build
run: cargo build

test:
name: Test
runs-on: ubuntu-24.04
needs: changes
if: needs.changes.outputs.runtime == 'true' || needs.changes.outputs.workflows == 'true'
defaults:
run:
working-directory: ./runtime
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Cache dependencies
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
- name: Install Rust toolchain
run: rustup toolchain install stable
- name: Test
run: cargo test

machete:
name: Machete
runs-on: ubuntu-24.04
needs: changes
if: needs.changes.outputs.runtime == 'true' || needs.changes.outputs.workflows == 'true'
defaults:
run:
working-directory: ./runtime
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Cache dependencies
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
- name: Install Rust toolchain
run: rustup toolchain install stable
- name: Install machete
run: cargo install cargo-machete
- name: Run machete
run: cargo machete
36 changes: 24 additions & 12 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
### rust ###
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# dev
.yarn/
!.yarn/releases
.vscode/*
!.vscode/launch.json
!.vscode/*.code-snippets
.idea/workspace.xml
.idea/usage.statistics.xml
.idea/shelf

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# deps
node_modules/

# These are backup files generated by rustfmt
**/*.rs.bk
# env
.env
.env.production

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# logs
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

# misc
.DS_Store
14 changes: 0 additions & 14 deletions backend/Cargo.toml

This file was deleted.

36 changes: 3 additions & 33 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,8 @@
# Program Grading System Backend

## Development

### Pre-requisites

- [Rust](https://www.rust-lang.org)
- [Node.js](https://nodejs.org)
- [Bun](https://bun.sh/)

### Commands

#### 開発サーバーの起動

```sh
bun run dev
```

#### OpenAPIのスキーマと型定義の生成

```sh
bun run generate
npm install
npm run dev
```

> [!important]
> バックエンドのコードを変更した場合は、必ずOpenAPIのスキーマと型定義を生成し、変更を反映させてください。
#### ビルドの実行

```sh
bun run build
```

#### テストの実行

```sh
bun run test
open http://localhost:3000
```
17 changes: 17 additions & 0 deletions backend/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { build } from "esbuild"

const b = () =>
build({
banner: {
js: "#!/usr/bin/env node",
},
bundle: true,
entryPoints: ["./src/index.ts"],
format: "cjs",
// For debug
minify: false,
outfile: "bin",
platform: "node",
})

Promise.all([b()])
23 changes: 23 additions & 0 deletions backend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @ts-check
import js from "@eslint/js"
import gitignore from "eslint-config-flat-gitignore"
import prettier from "eslint-config-prettier"
import jsxA11y from "eslint-plugin-jsx-a11y"
import perfectionist from "eslint-plugin-perfectionist"
import globals from "globals"
import tseslint from "typescript-eslint"

export default tseslint.config(
gitignore(),
{
languageOptions: {
globals: globals.browser,
},
},
js.configs.recommended,
...tseslint.configs.strict,
...tseslint.configs.stylistic,
perfectionist.configs["recommended-natural"],
jsxA11y.flatConfigs.recommended,
prettier,
)
Loading

0 comments on commit 4562bf6

Please sign in to comment.