Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FE] ci 워크플로우 구축 #40

Merged
merged 4 commits into from
Jul 23, 2024
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
69 changes: 69 additions & 0 deletions .github/workflows/frontend-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Frontend CI Test

on:
pull_request:
branches: ["develop"]

permissions:
checks: write
pull-requests: write

jobs:
detect-changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
backend:
- 'backend/**'
frontend:
- 'frontend/**'
list-files: "csv"

fe-test:
needs: detect-changes
if: ${{ needs.detect-changes.outputs.frontend == 'true' }}
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./frontend

steps:
- name: 모모 레파지토리의 코드를 가져와요 :)
uses: actions/checkout@v4

- name: 노드 버젼을 설정해요 :)
uses: actions/setup-node@v4
with:
node-version: "lts/*"
Comment on lines +44 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

노드 버전 설정 관련돼서 설정하는 방법이 https://github.com/actions/setup-node 여기 명시돼있네요!


- name: 이전 의존성을 저장해둔게 있나~? 확인해요 :)
id: cache
uses: actions/cache@v4
with:
path: "frontend/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
${{ runner.os }}
- name: package-lock.json을 활용해서 의존성을 깨끗하게 설치해요 :)
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci

- name: RTL을 실행해요 :)
run: npm run test -- --passWithNoTests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아무런 테스트를 진행하지 않는 경우에도, CI 파이프라인이 통과될 수 있도록 하기 위한 설정이군요!

설정 고생하셨습니다 빙봉~ 🔮

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞습니다!

PR을 날린 시점에서 아래 사진처럼 테스트가 존재하지 않아서 CI 파이프라인이 실패하였었는데, 이러한 현상을 방지하기 위해 --passWithNoTests 옵션을 추가했습니다.
image

--passWithNoTests: 테스트 파일이 없더라도 테스트를 통과시키도록 하는 옵션
이 옵션을 사용하면, 테스트를 실행할 때 실제로 테스트 파일이 하나도 없더라도 Jest가 에러를 발생시키지 않고 성공 코드로 종료됩니다.


- name: 테스트 결과를 PR에 코멘트로 등록해요 :)
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: frontend/test-results/results.xml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR 본문에 테스트 결과 표시를 위해서는, jest-junit 의존성을 추가하고 테스트 완료 시, xml 파일 생성 후 테스트 결과를 작성하도록 해야 함!
(기록용 코멘트 입니다 ㅎㅎ)

22 changes: 22 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"fork-ts-checker-webpack-plugin": "9.0.2",
"html-webpack-plugin": "5.6.0",
"jest-environment-jsdom": "29.7.0",
"jest-junit": "^16.0.0",
"msw": "2.3.1",
"postcss": "8.4.39",
"postcss-styled-syntax": "0.6.4",
Expand Down
Loading