Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Server Configuration
PORT=3000
NODE_ENV=development
Comment thread
Darrin-Lin marked this conversation as resolved.
APP_ENV=test
FIRESTORE_EMULATOR=true

# Firebase Configuration
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_PRIVATE_KEY_ID=your-private-key-id
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nyour-private-key-here\n-----END PRIVATE KEY-----"
FIREBASE_CLIENT_EMAIL=your-service-account-email@your-project-id.iam.gserviceaccount.com
FIREBASE_CLIENT_ID=your-client-id
FIREBASE_AUTH_URI=https://accounts.google.com/o/oauth2/auth
FIREBASE_TOKEN_URI=https://oauth2.googleapis.com/token
FIREBASE_AUTH_PROVIDER_X509_CERT_URL=https://www.googleapis.com/oauth2/v1/certs
FIREBASE_CLIENT_X509_CERT_URL=https://www.googleapis.com/robot/v1/metadata/x509/your-service-account-email%40your-project-id.iam.gserviceaccount.com

# Firebase Credentials Path
FIREBASE_CREDENTIALS_PATH="credentials/firebase-credentials.json"

# CORS Origins (comma-separated)
CORS_ORIGINS=http://localhost:3000,http://localhost:5173

# test environment variables
FIREBASE_PROJECT_ID=your-project-id
FIRESTORE_EMULATOR_HOST=localhost:8081 # you also need to modify "firebase.json"
44 changes: 22 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,41 @@ jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
version: latest
go-version: '1.21'

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
- name: Cache Go modules
uses: actions/cache@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Type check
run: pnpm typecheck

- name: Lint
run: pnpm lint
- name: Download dependencies
run: go mod download

- name: Format check
run: pnpm format:check
run: |
go fmt ./...
if [ -n "$(git status --porcelain)" ]; then
echo "Code is not formatted. Please run 'go fmt ./...'"
exit 1
fi

- name: Vet check
run: go vet ./...

- name: Build
run: pnpm build
run: go build -o bin/main src/main.go

# TODO: 暫時停用測試,因為需要 Firebase 環境變數配置
# 在正式部署前需要設置 GitHub Secrets 或使用 Firebase 模擬器
# - name: Run tests
# run: pnpm test:run
# run: go test ./...
48 changes: 16 additions & 32 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,37 @@ jobs:
test-with-env:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
version: latest
go-version: '1.21'

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
- name: Cache Go modules
uses: actions/cache@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Download dependencies
run: go mod download

# 設置測試用的環境變數
- name: Create test environment file
run: |
echo "PORT=3000" > .env
echo "NODE_ENV=test" >> .env
echo "FIREBASE_PROJECT_ID=test-project" >> .env
echo "FIREBASE_PRIVATE_KEY_ID=test-key-id" >> .env
echo 'FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\ntest-key\n-----END PRIVATE KEY-----"' >> .env
echo "FIREBASE_CLIENT_EMAIL=test@test.iam.gserviceaccount.com" >> .env
echo "FIREBASE_CLIENT_ID=test-client-id" >> .env
echo "FIREBASE_AUTH_URI=https://accounts.google.com/o/oauth2/auth" >> .env
echo "FIREBASE_TOKEN_URI=https://oauth2.googleapis.com/token" >> .env
echo "FIREBASE_AUTH_PROVIDER_X509_CERT_URL=https://www.googleapis.com/oauth2/v1/certs" >> .env
echo "FIREBASE_CLIENT_X509_CERT_URL=https://www.googleapis.com/robot/v1/metadata/x509/test%40test.iam.gserviceaccount.com" >> .env
echo "CORS_ORIGINS=http://localhost:3000" >> .env

- name: Run tests
run: pnpm test:run

- name: Run tests with coverage
run: pnpm test:coverage
run: go test ./...

# 上傳覆蓋率報告(可選)
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: success()
with:
fail_ci_if_error: false
# TODO: Add coverage reporting for Go
# - name: Run tests with coverage
# run: go test -coverprofile=coverage.out ./...
# run: go tool cover -html=coverage.out -o coverage.html
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@ dist
# Vite logs files
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

credentials/
bin/
8 changes: 7 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
pnpm lint-staged
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# Go code quality checks
go fmt ./...
go vet ./...
go mod tidy
2 changes: 1 addition & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
"*.go": ["go fmt"],
"*.{json,md,yml,yaml}": ["prettier --write"]
}
Loading