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..6066861 --- /dev/null +++ b/.github/workflows/ci-feat.yaml @@ -0,0 +1,41 @@ +name: feature 브랜치 전용 빌드 및 lint 테스트 + +on: + pull_request: + types: [opened, reopened, synchronize] + branches: + - dev + +jobs: + ci-feat: + runs-on: ubuntu-latest + outputs: + lint_results: ${{ steps.lint.outputs.lint_results }} + + 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: yarn install + + - name: Run Lint + id: lint + run: | + output=$(yarn run lint) + echo "lint_results=$output" >> $GITHUB_OUTPUT + + - name: Build project + run: yarn run build # Vite로 프로젝트를 빌드 + + add_comment: + needs: ci-feat + uses: ./.github/workflows/preview-comment.yaml + with: + content: ${{ needs.ci-feat.outputs.lint_results }} + 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}}