Skip to content

Commit b1ca87e

Browse files
authored
add github actions (#23)
add github actions workflow * format * test * build (not push yet, not deploy yet) add script * create workload identity
1 parent a16bda7 commit b1ca87e

37 files changed

+1774
-2914
lines changed

.github/workflows/build.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}-build
9+
cancel-in-progress: true
10+
11+
jobs:
12+
frontend:
13+
runs-on: ubuntu-22.04
14+
timeout-minutes: 10
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Use mise
18+
run: |
19+
curl https://mise.run | sh
20+
echo "$HOME/.local/share/mise/bin" >> $GITHUB_PATH
21+
echo "$HOME/.local/share/mise/shims" >> $GITHUB_PATH
22+
23+
- name: Install pnpm
24+
uses: pnpm/action-setup@v4
25+
with:
26+
version: 9
27+
28+
- name: Set up Node
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: '22.x'
32+
cache: 'pnpm'
33+
cache-dependency-path: ./frontend/web/pnpm-lock.yaml
34+
35+
- name: Install dependencies
36+
run: mise exec -- pnpm install
37+
working-directory: ./frontend/web
38+
39+
- name: Run build
40+
run: |
41+
set -eo pipefail
42+
mise run fe:build
43+
working-directory: ./frontend/web
44+
45+
backend:
46+
runs-on: ubuntu-22.04
47+
timeout-minutes: 10
48+
steps:
49+
- uses: actions/checkout@v4
50+
- name: Use mise
51+
run: |
52+
curl https://mise.run | sh
53+
echo "$HOME/.local/share/mise/bin" >> $GITHUB_PATH
54+
echo "$HOME/.local/share/mise/shims" >> $GITHUB_PATH
55+
56+
- name: Install uv
57+
uses: astral-sh/setup-uv@v4
58+
with:
59+
enable-cache: true
60+
cache-dependency-glob: ./backend/genai/uv.lock
61+
62+
- name: Set up Python
63+
uses: actions/setup-python@v5
64+
with:
65+
python-version: '3.13'
66+
67+
- name: Install dependencies
68+
run: mise exec -- uv sync --frozen
69+
working-directory: ./backend/genai
70+
71+
- name: Run build
72+
run: |
73+
set -eo pipefail
74+
mise run be:build
75+
working-directory: ./backend/genai

.github/workflows/format.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Format
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}-format
9+
cancel-in-progress: true
10+
11+
jobs:
12+
frontend:
13+
runs-on: ubuntu-22.04
14+
timeout-minutes: 10
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Use mise
18+
run: |
19+
curl https://mise.run | sh
20+
echo "$HOME/.local/share/mise/bin" >> $GITHUB_PATH
21+
echo "$HOME/.local/share/mise/shims" >> $GITHUB_PATH
22+
23+
- name: Install pnpm
24+
uses: pnpm/action-setup@v4
25+
with:
26+
version: 9
27+
28+
- name: Set up Node
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: '22.x'
32+
cache: 'pnpm'
33+
cache-dependency-path: ./frontend/web/pnpm-lock.yaml
34+
35+
- name: Install dependencies
36+
run: mise exec -- pnpm install
37+
working-directory: ./frontend/web
38+
39+
- name: Run format
40+
run: |
41+
mise run fe:format
42+
git diff --exit-code
43+
working-directory: ./frontend/web
44+
45+
- name: Show formatting diff on failure
46+
if: failure()
47+
run: git diff
48+
working-directory: ./frontend/web
49+
50+
backend:
51+
runs-on: ubuntu-22.04
52+
timeout-minutes: 10
53+
steps:
54+
- uses: actions/checkout@v4
55+
- name: Use mise
56+
run: |
57+
curl https://mise.run | sh
58+
echo "$HOME/.local/share/mise/bin" >> $GITHUB_PATH
59+
echo "$HOME/.local/share/mise/shims" >> $GITHUB_PATH
60+
61+
- name: Install uv
62+
uses: astral-sh/setup-uv@v4
63+
with:
64+
enable-cache: true
65+
cache-dependency-glob: ./backend/genai/uv.lock
66+
67+
- name: Set up Python
68+
uses: actions/setup-python@v5
69+
with:
70+
python-version: '3.13'
71+
72+
- name: Install dependencies
73+
run: mise exec -- uv sync --frozen
74+
working-directory: ./backend/genai
75+
76+
- name: Run format
77+
run: |
78+
mise run be:format
79+
git diff --exit-code
80+
working-directory: ./backend/genai
81+
82+
- name: Show formatting diff on failure
83+
if: failure()
84+
run: git diff
85+
working-directory: ./backend/genai

.github/workflows/lint.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/test.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}-test
9+
cancel-in-progress: true
10+
11+
jobs:
12+
frontend:
13+
runs-on: ubuntu-22.04
14+
timeout-minutes: 10
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Use mise
18+
run: |
19+
curl https://mise.run | sh
20+
echo "$HOME/.local/share/mise/bin" >> $GITHUB_PATH
21+
echo "$HOME/.local/share/mise/shims" >> $GITHUB_PATH
22+
23+
- name: Install pnpm
24+
uses: pnpm/action-setup@v4
25+
with:
26+
version: 9
27+
28+
- name: Set up Node
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: '22.x'
32+
cache: 'pnpm'
33+
cache-dependency-path: ./frontend/web/pnpm-lock.yaml
34+
35+
- name: Install dependencies
36+
run: mise exec -- pnpm install
37+
working-directory: ./frontend/web
38+
39+
- name: Run test
40+
run: |
41+
set -eo pipefail
42+
mise run fe:test
43+
working-directory: ./frontend/web
44+
45+
backend:
46+
runs-on: ubuntu-22.04
47+
permissions:
48+
contents: 'read'
49+
id-token: 'write'
50+
timeout-minutes: 10
51+
steps:
52+
- uses: actions/checkout@v4
53+
- name: Use mise
54+
run: |
55+
curl https://mise.run | sh
56+
echo "$HOME/.local/share/mise/bin" >> $GITHUB_PATH
57+
echo "$HOME/.local/share/mise/shims" >> $GITHUB_PATH
58+
59+
- uses: 'google-github-actions/auth@v2'
60+
with:
61+
# use permissions above
62+
project_id: 'advena-dev'
63+
workload_identity_provider: 'projects/38358387786/locations/global/workloadIdentityPools/github/providers/my-repo'
64+
65+
- name: Install uv
66+
uses: astral-sh/setup-uv@v4
67+
with:
68+
enable-cache: true
69+
cache-dependency-glob: ./backend/genai/uv.lock
70+
71+
- name: Set up Python
72+
uses: actions/setup-python@v5
73+
with:
74+
python-version: '3.13'
75+
76+
- name: Install dependencies
77+
run: mise exec -- uv sync --frozen
78+
working-directory: ./backend/genai
79+
80+
- name: Run test
81+
run: |
82+
set -eo pipefail
83+
mise run be:test
84+
working-directory: ./backend/genai
85+
env:
86+
CI: 'true'

backend/genai/Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS builder
66
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
77
WORKDIR /app
8+
9+
# Install build dependencies
10+
RUN apt-get update && apt-get install -y build-essential
11+
# Using uv to install dependencies
812
RUN --mount=type=cache,target=/root/.cache/uv \
913
--mount=type=bind,source=uv.lock,target=uv.lock \
1014
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
@@ -23,7 +27,10 @@ WORKDIR /app
2327

2428
# Install dotenvx
2529
RUN apt-get update && apt-get install -y curl
26-
RUN curl -sfS https://dotenvx.sh > install.sh && chmod +x install.sh && ./install.sh --directory=. && rm install.sh
30+
RUN curl -sfS https://dotenvx.sh > install.sh \
31+
&& chmod +x install.sh \
32+
&& ./install.sh --directory=. \
33+
&& rm install.sh
2734

2835
# Copy the application from the builder
2936
COPY --from=builder --chown=app:app /app /app

backend/genai/src/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
# memo: I9784621310328 の I のあとが 13桁 であれば ISBN 、20桁であれば JP-eコード とみなせる?
2222

23+
2324
def thumbnail(isbn_or_jpecode: str) -> str:
2425
"""書影画像を取得するための URL を生成する
2526
例: https://ndlsearch.ndl.go.jp/thumbnail/9784422311074.jpg

backend/genai/src/feed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def parse_rss(url: str):
2020
# link = entry.get("link")
2121
# description = entry.get("description")
2222
# published = entry.get("published")
23-
23+
2424
print(entry)
2525
print(type(entry))
2626
# {'title': 'はじめての\u3000シールえほん\u3000ぺたぺた\u3000ミッフィー / ディック・ブルーナ イラストほか', 'title_detail': {'type': 'text/plain', 'language': None, 'base': 'https://ndlsearch.ndl.go.jp/rss/ndls/bib.xml?cs=bib&display=panel&from=0&size=10&sort=published:desc&f-ht=ndl&f-ht=library&f-repository=R100000137&f-doc_style=digital&f-doc_style=paper&f-mt=dtbook&f-mt=dbook', 'value': 'はじめての\u3000シールえほん\u3000ぺたぺた\u3000ミッフィー / ディック・ブルーナ イラストほか'}, 'links': [{'rel': 'alternate', 'type': 'text/html', 'href': 'https://ndlsearch.ndl.go.jp/books/R100000137-I9784065386859'}], 'link': 'https://ndlsearch.ndl.go.jp/books/R100000137-I9784065386859', 'summary': 'ディック・ブルーナ イラスト; 講談社 編集. はじめての\u3000シールえほん\u3000ぺたぺた\u3000ミッフィー. 講談社. ISBN:9784065386859', 'summary_detail': {'type': 'text/html', 'language': None, 'base': 'https://ndlsearch.ndl.go.jp/rss/ndls/bib.xml?cs=bib&display=panel&from=0&size=10&sort=published:desc&f-ht=ndl&f-ht=library&f-repository=R100000137&f-doc_style=digital&f-doc_style=paper&f-mt=dtbook&f-mt=dbook', 'value': 'ディック・ブルーナ イラスト; 講談社 編集. はじめての\u3000シールえほん\u3000ぺたぺた\u3000ミッフィー. 講談社. ISBN:9784065386859'}, 'id': 'https://ndlsearch.ndl.go.jp/books/R100000137-I9784065386859', 'guidislink': False, 'tags': [{'term': '図書', 'scheme': None, 'label': None}], 'published': 'Sat, 21 Dec 2024 18:46:00 +0900', 'published_parsed': time.struct_time(tm_year=2024, tm_mon=12, tm_mday=21, tm_hour=9, tm_min=46, tm_sec=0, tm_wday=5, tm_yday=356, tm_isdst=0)}

backend/genai/src/main.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616

1717
from src.logger import logger
1818

19-
weave.init(project_name=os.getenv("WEAVE_PROJECT_NAME", ""))
20-
L.initialize(project_api_key=os.getenv("LMNR_PROJECT_API_KEY"))
21-
22-
19+
if os.getenv("CI") == "true":
20+
# CI 環境では weave と Laminar を初期化しない
21+
pass
22+
else:
23+
weave.init(project_name=os.getenv("WEAVE_PROJECT_NAME", ""))
24+
L.initialize(project_api_key=os.getenv("LMNR_PROJECT_API_KEY"))
25+
26+
# agents
2327
# see: https://docs.livekit.io/agents/integrations/google/#gemini-llm
2428
llm = livekit_google.LLM(
2529
model="gemini-2.0-flash-exp",

backend/genai/src/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime
2+
23
from pydantic import BaseModel
34

45

backend/genai/tests/conftest.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
import os
22

3-
# テスト実行時は wandb を無効にする
4-
os.environ["WANDB_MODE"] = "disabled"
3+
import pytest
4+
5+
from src.logger import logger
6+
7+
8+
def pytest_configure(config):
9+
# pytest開始時に一度だけ呼び出されるフック
10+
logger.info("Pytest is starting up...")
11+
12+
13+
@pytest.fixture(scope="session", autouse=True)
14+
def disable_wandb_and_weave():
15+
os.environ["WANDB_DISABLED"] = "true"
16+
os.environ["WANDB_SILENT"] = "true"
17+
os.environ["WANDB_MODE"] = "offline"
18+
logger.info("Wandb is disabled")
19+
20+
import weave
21+
22+
logger.info("Weave is imported")

frontend/web/.env

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#/-------------------[DOTENV_PUBLIC_KEY]--------------------/
2+
#/ public-key encryption for .env files /
3+
#/ [how it works](https://dotenvx.com/encryption) /
4+
#/----------------------------------------------------------/
5+
DOTENV_PUBLIC_KEY="02a33b6ab1419fbdce5ad6180a93970b61a1d26b5728554d35186700826d141f32"
6+
7+
# .env
8+
TEST="encrypted:BBxrOwjcIzO7p0ysNaUGZbAWKuyaDSWcQhz9teqOZKiLori+aHi4741eB81O/qOWW24wRPbTAgluP2Pgeoo9FsETvDsB0+nbvJMewGgE1NnPVBpSom/sPO9gTQDyAytamzjig21G"
9+
# Generate a random secret: https://generate-secret.vercel.app/32 or `openssl rand -base64 32`
10+
AUTH_SECRET="encrypted:BDJgQJbwZBGGIrsj17zrQnK4LtwzUYGGrd6gFQlRI6QU3rXB6r/QZuC6J6Xg4Mrnx4sQf9xZLsHz4uVnHpMbVPuurYxwiK+DEiqSO+pua6usKdezLcKQ2quiYkp14knbC5z117F2+ARhILc7UAtv7uPLfEduT9eIzjdxkAb7Mk4ZnX9D8who75HjtXr+"
11+
# Google Vertex AI
12+
# see: https://sdk.vercel.ai/providers/ai-sdk-providers/google-vertex
13+
GOOGLE_VERTEX_PROJECT="advena-dev"
14+
GOOGLE_VERTEX_LOCATION="us-central1"
15+
POSTGRES_URL="postgresql://postgres:your_password@localhost:5432/your_database"

0 commit comments

Comments
 (0)