diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a8bedb..2005bdf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,36 +1,56 @@ -name: Node.js CI +name: Node.js CI + Auto Approve on: - # "on" 키워드는 이 워크플로우를 언제 어떻게 실행할지 정의 push: - branches: [ "main" ] - # main 브랜치에 새 커밋이 푸시(push)될 때 자동으로 워크플로우 실행 + branches: ["main"] pull_request: - branches: [ "main" ] - # main 브랜치 대상의 풀 리퀘스트(PR)가 생성, 업데이트, 병합 준비 등 상태가 변경될 때 실행 + branches: ["main"] + pull_request_target: # 🔥 자동 승인을 위한 추가 이벤트 + types: [opened, reopened, synchronize] workflow_dispatch: - # 수동 실행(Dispatch)을 허용 - # GitHub Actions 페이지에서 "Run workflow" 버튼을 눌러 직접 트리거 가능 + +permissions: + actions: write + pull-requests: read + contents: read # 코드 체크아웃을 위해 추가 jobs: - build-and-test: + # ---------------------------------- + # 1. 자동 승인 작업 (신규 기여자용) + # ---------------------------------- + auto-approve: + if: github.event_name == 'pull_request_target' # PR 대상 이벤트에서만 실행 runs-on: ubuntu-latest + steps: + - name: Approve First-Time Contributors + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + PR_NUMBER=${{ github.event.pull_request.number }} + RUN_IDS=$(gh api "/repos/${{ github.repository }}/actions/runs?event=pull_request&pull_request=$PR_NUMBER" --jq '.workflow_runs[] | select(.status == "waiting") | .id') + for RUN_ID in $RUN_IDS; do + echo "Approving Run ID: $RUN_ID" + gh api -X POST "/repos/${{ github.repository }}/actions/runs/$RUN_ID/approve" + done + # ---------------------------------- + # 2. 기존 빌드/테스트 작업 (모든 PR에 적용) + # ---------------------------------- + build-and-test: + needs: auto-approve # 자동 승인 후 실행 + runs-on: ubuntu-latest steps: - - name: Check out repository code - uses: actions/checkout@v3 - # 현재 리포지토리의 코드를 가져옴 (소스 접근 및 빌드/테스트 위해 필요) + - name: Checkout code + uses: actions/checkout@v4 # v3 → v4로 업그레이드 - name: Use Node.js 22.x - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 # v3 → v4로 업그레이드 with: node-version: 22 - # Node.js 22 버전 환경에서 스크립트 실행 + cache: "npm" # 🔥 npm 캐싱 추가 (빌드 속도 향상) - name: Install dependencies - run: npm install - # package.json에 명시된 의존성(라이브러리 등)을 설치 + run: npm ci # npm install → npm ci로 변경 (정확한 버전 보장) - name: Run tests run: npm test - # Jest 등으로 작성된 테스트 스크립트를 실행 \ No newline at end of file diff --git a/problem01/problem01.js b/problem01/problem01.js index 4bee421..9e31b27 100644 --- a/problem01/problem01.js +++ b/problem01/problem01.js @@ -8,15 +8,14 @@ /* problem01.js */ function grade(score) { let result; - if (score > 100 || score < 0) { - result = "C"; // 🚨 + result = "Invalid"; } else if (score >= 90) { - result = "B"; // 🚨 + result = "A"; } else if (score >= 80) { - result = "A"; // 🚨 + result = "B"; } else { - result = "B"; // 🚨 + result = "C"; } return result; diff --git a/problem02/problem02.js b/problem02/problem02.js index ff7014b..eb4c838 100644 --- a/problem02/problem02.js +++ b/problem02/problem02.js @@ -11,12 +11,16 @@ function checkNumber(num) { switch (true) { case typeof num !== "number" || isNaN(num): // 🚨 result = "숫자가 아닙니다."; - case num > 0: // 🚨 + break; + case num > 0: result = "양수입니다."; - case num < 0: // 🚨 + break; + case num < 0: result = "음수입니다."; - case num === 0: // 🚨 + break; + case num === 0: result = "0입니다."; + break; default: // 🚨 result = "알 수 없는 오류입니다."; } diff --git a/problem03/problem03.js b/problem03/problem03.js index 1b59f8c..6989502 100644 --- a/problem03/problem03.js +++ b/problem03/problem03.js @@ -7,10 +7,10 @@ */ /* problem03.js */ function sumExcludingMultiplesOfThreeAndFive(n) { - let sum = 1; // 🚨 + let sum = 0; for (let i = 1; i <= n; i++) { - if (i % 3 !== 0 && i % 5 !== 0) continue; // 🚨 - sum -= i; // 🚨 + if (i % 3 == 0 || i % 5 == 0) continue; + sum += i; // 🚨 } return sum; } diff --git a/problem04/problem04.js b/problem04/problem04.js index 0c25c97..d60af85 100644 --- a/problem04/problem04.js +++ b/problem04/problem04.js @@ -6,13 +6,12 @@ * - 현재 코드는 잘못된 로직으로 인해 테스트가 실패합니다. */ function sumUpToTen(n) { - let sum = 1; // 🚨 + let sum = 0; // 🚨 let i = 1; while (i <= n) { if (i > 10) break; // 🚨 - sum -= i; // 🚨 - i++; + sum += i++; // 🚨 } return sum; diff --git a/problem05/problem05.js b/problem05/problem05.js index c74abb6..6dd93fc 100644 --- a/problem05/problem05.js +++ b/problem05/problem05.js @@ -6,11 +6,11 @@ * - 모든 조건을 확인한 후 최후에 `return`을 사용하세요. */ function sumOfSmallProducts(n) { - let sum = 1; // 🚨 + let sum = 0; // 🚨 for (let i = 1; i <= n; i++) { for (let j = 1; j <= n; j++) { - if (i * j > 10) continue; // 🚨 - sum -= i * j; // 🚨 + if (i * j > 10) continue; + sum += i * j; } } return sum;