Files
page-builder/.gitea/workflows/ci.yml
jaybe 1c3ad4c647
CI / test (push) Failing after 6m4s
CI / pr_and_merge (push) Has been skipped
CI: Prisma Client 자동 생성 추가
2025-11-18 17:16:40 +09:00

109 lines
3.2 KiB
YAML

name: CI
on:
push:
branches:
- main
- feature/**
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install dependencies
run: |
npm ci
- name: Generate Prisma Client
run: |
npx prisma generate
- name: Run unit tests
run: |
npm test
- name: Install Playwright browsers
run: |
npx playwright install --with-deps
- name: Run Playwright E2E tests
run: |
npx playwright test
pr_and_merge:
needs: test
# feature/* 브랜치에 push 되었을 때만 실행한다.
if: ${{ startsWith(github.ref, 'refs/heads/feature/') }}
runs-on: ubuntu-latest
steps:
- name: Create or update PR and try auto-merge
env:
CI_BASE_URL: ${{ secrets.CI_BASE_URL }}
CI_TOKEN: ${{ secrets.CI_TOKEN }}
CI_OWNER: ${{ secrets.CI_OWNER }}
CI_REPO: ${{ secrets.CI_REPO }}
BRANCH_REF: ${{ github.ref }}
BRANCH_NAME: ${{ github.ref_name }}
run: |
set -e
if [ -z "$CI_BASE_URL" ] || [ -z "$CI_TOKEN" ] || [ -z "$CI_OWNER" ] || [ -z "$CI_REPO" ]; then
echo "CI_* 시크릿이 설정되지 않아 PR/자동 머지를 건너뜁니다." >&2
exit 0
fi
echo "현재 브랜치: $BRANCH_NAME ($BRANCH_REF)"
# 1) PR 생성 시도 (이미 존재하면 4xx를 허용)
create_pr_payload=$(jq -n \
--arg title "CI: $BRANCH_NAME" \
--arg head "$BRANCH_NAME" \
--arg base "main" \
'{title: $title, head: $head, base: $base}')
echo "PR 생성 시도..."
curl -sS -X POST \
-H "Content-Type: application/json" \
-H "Authorization: token $CI_TOKEN" \
"$CI_BASE_URL/api/v1/repos/$CI_OWNER/$CI_REPO/pulls" \
-d "$create_pr_payload" || true
# 2) 열린 PR 목록에서 해당 브랜치의 PR 번호를 찾는다.
echo "열린 PR 목록 조회..."
pr_list=$(curl -sS \
-H "Authorization: token $CI_TOKEN" \
"$CI_BASE_URL/api/v1/repos/$CI_OWNER/$CI_REPO/pulls?state=open")
pr_number=$(echo "$pr_list" | jq ".[] | select(.head.ref == \"$BRANCH_NAME\") | .number" | head -n 1)
if [ -z "$pr_number" ]; then
echo "브랜치 $BRANCH_NAME 에 대한 열린 PR을 찾지 못했습니다. 종료합니다."
exit 0
fi
echo "브랜치 $BRANCH_NAME 에 대한 PR #$pr_number 발견"
# 3) main 대상으로 자동 머지 시도
merge_payload=$(jq -n '{Do: "merge"}')
echo "PR #$pr_number 자동 머지 시도..."
curl -sS -X POST \
-H "Content-Type: application/json" \
-H "Authorization: token $CI_TOKEN" \
"$CI_BASE_URL/api/v1/repos/$CI_OWNER/$CI_REPO/pulls/$pr_number/merge" \
-d "$merge_payload" || true