diff --git a/.github/workflows/check_errors.yml b/.github/workflows/check_err.yml similarity index 66% rename from .github/workflows/check_errors.yml rename to .github/workflows/check_err.yml index 71506379..b4f63942 100644 --- a/.github/workflows/check_errors.yml +++ b/.github/workflows/check_err.yml @@ -1,15 +1,12 @@ name: Check Errors on: - pull_request: - branches: [ "develop", "main" ] workflow_call: jobs: err_check: name: Check Errors - # runs-on: self-hosted - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Checkout @@ -17,10 +14,10 @@ jobs: with: fetch-depth: 1 - - name: Set Node.js 16.x - uses: actions/setup-node@v3 + - name: Set Node.js 18.18 + uses: actions/setup-node@v4 with: - node-version: 18.18 + node-version: 18.18 - name: Setup yarn run: npm install -g yarn @@ -35,4 +32,4 @@ jobs: run: yarn lint - name: Check tsc-project - run: yarn tsc-project + run: yarn tsc-project \ No newline at end of file diff --git a/.github/workflows/cr.yml b/.github/workflows/cr.yml index 743d5991..c142222f 100644 --- a/.github/workflows/cr.yml +++ b/.github/workflows/cr.yml @@ -15,7 +15,7 @@ permissions: jobs: code_review: - runs-on: ubuntu-latest + runs-on: self-hosted steps: - uses: anc95/ChatGPT-CodeReview@main env: diff --git a/.github/workflows/front.yml b/.github/workflows/front.yml index 290ed0b6..4b6a9934 100644 --- a/.github/workflows/front.yml +++ b/.github/workflows/front.yml @@ -1,23 +1,21 @@ -name: CI/CD nextjs +name: Build Nextjs on: - push: - branches: [ "develop", "main" ] - -env: - ECR_URL: ${{ secrets.ECR_REPO_DEV_FRONT }} - ROLE_ARN: ${{ secrets.OIDC_ROLE }} - AWS_REGION: ${{ secrets.AWS_REGION }} - WEBHOOK_URL: ${{ secrets.WEBHOOK }} + workflow_call: + secrets: + ECR_REPO_DEV_FRONT: + OIDC_ROLE: + AWS_REGION: + WEBHOOK: + AWS_DEPLOY_APP_NAME: + AWS_DEPLOY_GROUP: + AWS_DEPLOY_CONFIG: permissions: id-token: write contents: read -jobs: - call_err_check: - name: Call workflow Error Check - uses: ./.github/workflows/check_errors.yml +jobs: build: name: To push ECR runs-on: self-hosted @@ -31,11 +29,11 @@ jobs: run: docker build -t catcher-web . - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v4 with: - aws-region: ${{ env.AWS_REGION }} + aws-region: ${{ secrets.AWS_REGION }} role-session-name: GitHubActions - role-to-assume: ${{ env.ROLE_ARN }} + role-to-assume: ${{ secrets.OIDC_ROLE }} - name: Login to Amazon ECR id: login-ecr @@ -45,7 +43,7 @@ jobs: run: | # ECR Front 레포의 기존 이미지 조회 aws ecr describe-images \ - --repository-name ${{ secrets.AWS_FRONT_ECR_NAME }} \ + --repository-name ${{ secrets.ECR_REPO_DEV_FRONT }} \ --region ${{ secrets.AWS_REGION }} \ --output yaml | grep imageDigest | awk -F ' ' '{print $2}' > ./delete_list.txt @@ -53,15 +51,15 @@ jobs: for front_image in `cat ./delete_list.txt` do aws ecr batch-delete-image \ - --repository-name ${{ secrets.AWS_FRONT_ECR_NAME }} \ + --repository-name ${{ secrets.ECR_REPO_DEV_FRONT }} \ --image-ids imageDigest=$front_image \ --output yaml > /dev/null done - name: Publish Image to ECR(CATCHER-WEB) run: | - docker tag catcher-web:latest ${{ env.ECR_URL }}:${{ github.sha }} - docker push ${{ env.ECR_URL }}:${{ github.sha }} + docker tag catcher-web:latest ${{ secrets.ECR_REPO_DEV_FRONT }}:${{ github.sha }} + docker push ${{ secrets.ECR_REPO_DEV_FRONT }}:${{ github.sha }} - name: Deploy to Frontend Instance from ECR Image run: | @@ -79,4 +77,4 @@ jobs: else MESSAGE="❌ ${{ job.status }} 프론트 배포 실패 : catcher-web - by ${{ github.actor }}" fi - curl -X POST -H "Content-Type: application/json" --data "{\"text\":\"${MESSAGE}\"}" ${{ env.WEBHOOK_URL }} \ No newline at end of file + curl -X POST -H "Content-Type: application/json" --data "{\"text\":\"${MESSAGE}\"}" ${{ secrets.WEBHOOK }} \ No newline at end of file diff --git a/.github/workflows/on_pr.yml b/.github/workflows/on_pr.yml new file mode 100644 index 00000000..e6eb4cf3 --- /dev/null +++ b/.github/workflows/on_pr.yml @@ -0,0 +1,46 @@ +name: ON PR/Merge - Check Errors | Build + +on: + pull_request: + branches: [ "develop", "main" ] + types: [ "opened", "closed" ] + push: + branches: [ "develop", "main" ] + +jobs: + merged: + if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true }} + name: Build Nextjs + uses: ./.github/workflows/front.yml + secrets: + ECR_REPO_DEV_FRONT: ${{ secrets.ECR_REPO_DEV_FRONT }} + OIDC_ROLE: ${{ secrets.OIDC_ROLE }} + AWS_REGION: ${{ secrets.AWS_REGION }} + WEBHOOK: ${{ secrets.WEBHOOK }} + AWS_DEPLOY_APP_NAME: ${{ secrets.AWS_DEPLOY_APP_NAME }} + AWS_DEPLOY_GROUP: ${{ secrets.AWS_DEPLOY_GROUP }} + AWS_DEPLOY_CONFIG: ${{ secrets.AWS_DEPLOY_CONFIG }} + + pr: + if: ${{ github.event.pull_request.merged == false && github.event != 'push'}} + name: Error Check + uses: ./.github/workflows/check_err.yml + + pushed-1: + if: ${{ github.event.pull_request.merged == false && github.event == 'push'}} + name: Error Check + uses: ./.github/workflows/check_err.yml + + pushed-2: + if: ${{ github.event.pull_request.merged == false && github.event == 'push'}} + name: Build Nextjs + uses: ./.github/workflows/front.yml + secrets: + ECR_REPO_DEV_FRONT: ${{ secrets.ECR_REPO_DEV_FRONT }} + OIDC_ROLE: ${{ secrets.OIDC_ROLE }} + AWS_REGION: ${{ secrets.AWS_REGION }} + WEBHOOK: ${{ secrets.WEBHOOK }} + AWS_DEPLOY_APP_NAME: ${{ secrets.AWS_DEPLOY_APP_NAME }} + AWS_DEPLOY_GROUP: ${{ secrets.AWS_DEPLOY_GROUP }} + AWS_DEPLOY_CONFIG: ${{ secrets.AWS_DEPLOY_CONFIG }} + needs: pushed-1 \ No newline at end of file