From ebe83c5c899f23e222d16f3edbf30cd055a464d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B1=84=EC=A7=80=EC=9B=90?= Date: Tue, 25 Mar 2025 16:38:19 +0900 Subject: [PATCH 1/3] =?UTF-8?q?lint=20=EC=B6=9C=EB=A0=A5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-feat.yaml | 94 ----------------------- .github/workflows/ci-feat.yaml | 39 ++++++++++ .github/workflows/delete-feat-bucket.yaml | 40 ---------- .github/workflows/preview-comment.yaml | 4 +- 4 files changed, 41 insertions(+), 136 deletions(-) delete mode 100644 .github/workflows/cd-feat.yaml create mode 100644 .github/workflows/ci-feat.yaml delete mode 100644 .github/workflows/delete-feat-bucket.yaml diff --git a/.github/workflows/cd-feat.yaml b/.github/workflows/cd-feat.yaml deleted file mode 100644 index a258593..0000000 --- a/.github/workflows/cd-feat.yaml +++ /dev/null @@ -1,94 +0,0 @@ -name: feature 브랜치 전용 S3 버킷 상태 관리 - -on: - pull_request: - types: [opened, reopened, synchronize] - branches: - - dev - -jobs: - cd-feat: - runs-on: ubuntu-latest - outputs: - bucket-name: ${{ steps.generate-bucket-name.outputs.bucket-name }} - - steps: - - name: Checkout the code - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: "18" # 프로젝트에서 사용하는 Node.js 버전에 맞게 설정 - - - name: Install dependencies - run: yarn install - - - name: Build project - run: yarn run build # Vite로 프로젝트를 빌드 - - - name: Set up AWS CLI - uses: aws-actions/configure-aws-credentials@v3 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ap-northeast-2 - - - name: Determine S3 bucket name with branch name - id: generate-bucket-name - env: - FEATURE_BRANCH: ${{ github.head_ref }} - run: | - # feat/ 이후의 문자열만 추출, empty string일 경우 exit - BUCKET_NAME=$(echo "${{ github.head_ref }}" | - sed -e 's/feat\///' | # feat/ 접두사 제거 - tr '[:upper:]' '[:lower:]' | # 대문자를 소문자로 변환 - sed -e 's/[^a-z0-9-]/-/g' | # 허용되지 않는 문자를 대시로 대체 - sed -e 's/^-*//; s/-*$//' | # 시작과 끝의 대시 제거 - cut -c1-50) # 최대 길이 제한 - - echo "bucket-name=zipline-fe-$BUCKET_NAME" >> $GITHUB_OUTPUT - - - name: Manage S3 Buckets - env: - S3_BUCKET: ${{ steps.generate-bucket-name.outputs.bucket-name }} - - run: | - if [[ "${{ github.event.action }}" == "opened" || "${{ github.event.action }}" == "reopened" || "${{ github.event.action }}" == "synchronize" ]]; then - echo "Set S3 bucket config: $S3_BUCKET" - if ! aws s3api head-bucket --bucket $S3_BUCKET 2>/dev/null; then - aws s3api create-bucket --bucket $S3_BUCKET --region ap-northeast-2 --create-bucket-configuration LocationConstraint=ap-northeast-2 - - aws s3api delete-public-access-block --bucket $S3_BUCKET - - aws s3api put-bucket-policy --bucket $S3_BUCKET --policy '{ - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Principal": "*", - "Action": "s3:GetObject", - "Resource": "arn:aws:s3:::'$S3_BUCKET'/*" - } - ] - }' - - aws s3 website s3://$S3_BUCKET --index-document index.html --error-document index.html - fi - - aws s3 sync ./dist s3://$S3_BUCKET/ --delete - - elif [[ "${{ github.event.action }}" = "closed" && "${{ github.event.pull_request.merged }}" = "true" ]]; then - echo "Deleting S3 bucket: $S3_BUCKET" - aws s3 rm s3://$S3_BUCKET --recursive - aws s3 rb s3://$S3_BUCKET --force - else - echo "No action needed" - fi - - add_comment: - needs: cd-feat - uses: ./.github/workflows/preview-comment.yaml - with: - bucket_name: ${{ needs.cd-feat.outputs.bucket-name }} - pr_number: ${{ github.event.pull_request.number }} diff --git a/.github/workflows/ci-feat.yaml b/.github/workflows/ci-feat.yaml new file mode 100644 index 0000000..28e2638 --- /dev/null +++ b/.github/workflows/ci-feat.yaml @@ -0,0 +1,39 @@ +name: feature 브랜치 전용 빌드 및 lint 테스트 + +on: + pull_request: + types: [opened, reopened, synchronize] + branches: + - dev + +jobs: + ci-feat: + runs-on: ubuntu-latest + + steps: + - name: Checkout the code + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "20" # 프로젝트에서 사용하는 Node.js 버전에 맞게 설정 + + - name: Install dependencies + run: npm install + + - name: Run Lint + id: lint + run: | + npm run lint > lint-results.txt + cat lint-results.txt + + - name: Build project + run: npm run build # Vite로 프로젝트를 빌드 + + add_comment: + needs: ci-feat + uses: ./.github/workflows/preview-comment.yaml + with: + content: ${{ needs.cd-feat.outputs.bucket-name }} + pr_number: ${{ github.event.pull_request.number }} diff --git a/.github/workflows/delete-feat-bucket.yaml b/.github/workflows/delete-feat-bucket.yaml deleted file mode 100644 index 0d0c22e..0000000 --- a/.github/workflows/delete-feat-bucket.yaml +++ /dev/null @@ -1,40 +0,0 @@ -name: 작업 완료된 feature 브랜치의 S3 버킷 삭제 - -on: - pull_request: - types: [closed] - branches: - - dev - -jobs: - cd-feat: - runs-on: ubuntu-latest - - steps: - - name: Set up AWS CLI - uses: aws-actions/configure-aws-credentials@v3 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ap-northeast-2 - - - name: Get branch name for bucket deletion - id: extract-bucket-name - env: - FEATURE_BRANCH: ${{ github.event.pull_request.head.ref }} - run: | - # feat/ 이후의 문자열만 추출 - BUCKET_NAME=$(echo $FEATURE_BRANCH | sed 's|^feat/||') - echo "Bucket name determined: $BUCKET_NAME" # For debugging - echo "bucket=$BUCKET_NAME" >> $GITHUB_ENV - - - name: Delete S3 bucket - env: - S3_BUCKET: zipline-fe-${{ env.bucket }} - run: | - if [ "${{ github.event.action }}" = "closed" ] && [ "${{ github.event.pull_request.merged }}" = "true" ]; then - echo "Deleting S3 bucket: $S3_BUCKET" - aws s3 rb s3://$S3_BUCKET --force - else - echo "No action needed" - fi diff --git a/.github/workflows/preview-comment.yaml b/.github/workflows/preview-comment.yaml index 3879879..fd230cf 100644 --- a/.github/workflows/preview-comment.yaml +++ b/.github/workflows/preview-comment.yaml @@ -3,7 +3,7 @@ name: PR에 Feature 브랜치 주소 코멘트 추가 on: workflow_call: inputs: - bucket_name: + content: required: true type: string pr_number: @@ -20,5 +20,5 @@ jobs: - name: comment PR uses: thollander/actions-comment-pull-request@v3 with: - message: "🍐 배포 주소: ${{ inputs.bucket_name }}.s3-website.ap-northeast-2.amazonaws.com/" + message: ${{inputs.content}} pr-number: ${{ inputs.pr_number}} From 2e84406c13a628cdb28b3487f59f2580bff36d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B1=84=EC=A7=80=EC=9B=90?= Date: Tue, 25 Mar 2025 16:38:51 +0900 Subject: [PATCH 2/3] npm -> yarn --- .github/workflows/ci-feat.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-feat.yaml b/.github/workflows/ci-feat.yaml index 28e2638..d5dfc21 100644 --- a/.github/workflows/ci-feat.yaml +++ b/.github/workflows/ci-feat.yaml @@ -20,16 +20,16 @@ jobs: node-version: "20" # 프로젝트에서 사용하는 Node.js 버전에 맞게 설정 - name: Install dependencies - run: npm install + run: yarn install - name: Run Lint id: lint run: | - npm run lint > lint-results.txt + yarn run lint > lint-results.txt cat lint-results.txt - name: Build project - run: npm run build # Vite로 프로젝트를 빌드 + run: yarn run build # Vite로 프로젝트를 빌드 add_comment: needs: ci-feat From 228109e5a595f8b0a258c934587fd04a28effff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B1=84=EC=A7=80=EC=9B=90?= Date: Tue, 25 Mar 2025 16:47:45 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=95=88=EB=84=98?= =?UTF-8?q?=EA=B2=A8=EC=A3=BC=EB=8D=98=20=EB=B6=80=EB=B6=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-feat.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-feat.yaml b/.github/workflows/ci-feat.yaml index d5dfc21..6066861 100644 --- a/.github/workflows/ci-feat.yaml +++ b/.github/workflows/ci-feat.yaml @@ -9,6 +9,8 @@ on: jobs: ci-feat: runs-on: ubuntu-latest + outputs: + lint_results: ${{ steps.lint.outputs.lint_results }} steps: - name: Checkout the code @@ -25,8 +27,8 @@ jobs: - name: Run Lint id: lint run: | - yarn run lint > lint-results.txt - cat lint-results.txt + output=$(yarn run lint) + echo "lint_results=$output" >> $GITHUB_OUTPUT - name: Build project run: yarn run build # Vite로 프로젝트를 빌드 @@ -35,5 +37,5 @@ jobs: needs: ci-feat uses: ./.github/workflows/preview-comment.yaml with: - content: ${{ needs.cd-feat.outputs.bucket-name }} + content: ${{ needs.ci-feat.outputs.lint_results }} pr_number: ${{ github.event.pull_request.number }}