From d6df3f21ea993e76fd0241cc3443eec10726ceee Mon Sep 17 00:00:00 2001 From: robinjoon Date: Sun, 21 Jan 2024 08:47:17 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat=20:=20=EB=B9=8C=EB=93=9C=EC=A0=84=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=ED=8C=8C=EC=9D=BC=20import=20=EB=B0=8F=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=EC=97=90=20=EB=B0=B0=ED=8F=AC=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...n_build_fail.yml => test_build_deploy.yml} | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) rename .github/workflows/{close_pr_when_build_fail.yml => test_build_deploy.yml} (56%) diff --git a/.github/workflows/close_pr_when_build_fail.yml b/.github/workflows/test_build_deploy.yml similarity index 56% rename from .github/workflows/close_pr_when_build_fail.yml rename to .github/workflows/test_build_deploy.yml index 09a85461..3fe7f0ff 100644 --- a/.github/workflows/close_pr_when_build_fail.yml +++ b/.github/workflows/test_build_deploy.yml @@ -1,4 +1,4 @@ -name: Close PR when Build Fail +name: Test And Build And Deploy on: pull_request: types: [ opened ] @@ -23,12 +23,30 @@ jobs: settings-path: ${{ github.workspace }} # location for the settings.xml file - name: Grant execute permission for gradlew run: chmod +x gradlew + - name: Import secret files + run: | + echo -e "${{ secrets.APPLICATION_COMMON}}" >> ./src/main/resources/application-common.yml + echo -e "${{ secrets.APPLICATION_PRODUCT}}" >> ./src/main/resources/application-product.yml + echo -e "${{ secrets.APPLICATION_LOCAL}}" >> ./src/main/resources/application-local.yml + echo -e "${{ secrets.APPLICATION_INFO_LOGGING}}" >> ./src/main/resources/application-info-logging.yml + echo -e "${{ secrets.APPLICATION_DEBUG_LOGGING}}" >> ./src/main/resources/application-debug-logging.yml - name: Build with Gradle continue-on-error: true id: build_and_test run: ./gradlew clean build --stacktrace - + - name: Deploy file + continue-on-error: true + uses: wlixcc/SFTP-Deploy-Action@v1.2.4 + id: deploy_file + if: ${{ steps.build_and_test.outcome == 'success'}} + with: + username: ${{ secrets.SSH_USERNAME }} + server: ${{ secrets.SSH_HOST }} + local_path: './build/libs/*' + remote_path: ${{ secrets.SSH_REMOTE_PATH }} + sftp_only: true + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} - name: If build fail continue-on-error: true # 이전 step이 실패한 경우에만 이 step을 실행시키는 syntax @@ -86,4 +104,36 @@ jobs: "description": "빌드가 성공했습니다! 아싸!", "url": "https://github.com/Cafegory/Cafegory_Backend_REST_API/pull/${{github.event.number}}" } + ]}' + - name: Send Deploy Fail Message to Discord + continue-on-error: true + if: ${{ steps.deploy_file.outcome == 'failure'}} + run: | + curl --location ${{secrets.DISCORD_WEBHOOK_URL}} \ + --header 'Content-Type: application/json' \ + --data '{ + "avatar_url": "https://cdn-icons-png.flaticon.com/512/25/25231.png", + "embeds": [ + { + "title": "${{ github.event.pull_request.title }}", + "type": "rich", + "description": "배포가 실패했습니다.", + "url": "https://github.com/Cafegory/Cafegory_Backend_REST_API/pull/${{github.event.number}}" + } + ]}' + - name: Send Deploy Success Message to Discord + continue-on-error: true + if: ${{ steps.deploy_file.outcome == 'success'}} + run: | + curl --location ${{secrets.DISCORD_WEBHOOK_URL}} \ + --header 'Content-Type: application/json' \ + --data '{ + "avatar_url": "https://cdn-icons-png.flaticon.com/512/25/25231.png", + "embeds": [ + { + "title": "${{ github.event.pull_request.title }}", + "type": "rich", + "description": "배포가 성공했습니다!!! 아싸!!!", + "url": "https://github.com/Cafegory/Cafegory_Backend_REST_API/pull/${{github.event.number}}" + } ]}' \ No newline at end of file From 3aaa5adfdde4260bfd054de2043e4699b3c4ee62 Mon Sep 17 00:00:00 2001 From: robinjoon Date: Sun, 21 Jan 2024 08:56:48 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix=20:=20=EB=B0=B0=ED=8F=AC=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=20=ED=8A=B8=EB=A6=AC=EA=B1=B0=20?= =?UTF-8?q?=EC=A1=B0=EA=B1=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test_build_deploy.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test_build_deploy.yml b/.github/workflows/test_build_deploy.yml index 3fe7f0ff..1a59a3e0 100644 --- a/.github/workflows/test_build_deploy.yml +++ b/.github/workflows/test_build_deploy.yml @@ -1,7 +1,6 @@ name: Test And Build And Deploy on: - pull_request: - types: [ opened ] + push: branches: [ 'main' ] jobs: From 7e16c368f07bf4751b9c5eb5a73d41e3f11e2efb Mon Sep 17 00:00:00 2001 From: robinjoon Date: Sun, 21 Jan 2024 09:01:02 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix=20:=20pr=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=88=98=ED=96=89=ED=95=98=EB=8A=94=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A6=BD=ED=8A=B8=20=ED=8A=B8=EB=A6=AC=EA=B1=B0=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 재오픈, 수정, 새 커밋 추가시 트리거되도록 추가 --- .github/workflows/run_test_when_pr_update.yml | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .github/workflows/run_test_when_pr_update.yml diff --git a/.github/workflows/run_test_when_pr_update.yml b/.github/workflows/run_test_when_pr_update.yml new file mode 100644 index 00000000..4361bc27 --- /dev/null +++ b/.github/workflows/run_test_when_pr_update.yml @@ -0,0 +1,95 @@ +name: Test And Build And Deploy +on: + pull_request: + types: [ opened, reopened, edited, synchronize ] + branches: [ 'main' ] + +jobs: + build_and_test: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + pull-requests: write + issues: write + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Import secret files + run: | + echo -e "${{ secrets.APPLICATION_COMMON}}" >> ./src/main/resources/application-common.yml + echo -e "${{ secrets.APPLICATION_PRODUCT}}" >> ./src/main/resources/application-product.yml + echo -e "${{ secrets.APPLICATION_LOCAL}}" >> ./src/main/resources/application-local.yml + echo -e "${{ secrets.APPLICATION_INFO_LOGGING}}" >> ./src/main/resources/application-info-logging.yml + echo -e "${{ secrets.APPLICATION_DEBUG_LOGGING}}" >> ./src/main/resources/application-debug-logging.yml + - name: Build with Gradle + continue-on-error: true + id: build_and_test + run: + ./gradlew clean build --stacktrace + - name: If build fail + continue-on-error: true + # 이전 step이 실패한 경우에만 이 step을 실행시키는 syntax + if: ${{ steps.build_and_test.outcome == 'failure'}} + id: close_pr + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const pull_number = ${{ github.event.pull_request.number }} + const updated_title = `[BUILD FAIL] ${{ github.event.pull_request.title }}` + await github.rest.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pull_number, + body: '빌드에 실패했습니다.', + event: 'REQUEST_CHANGES' + }) + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pull_number, + title: updated_title, + state: 'closed' + }) + - name: Send Build Fail Message to Discord + continue-on-error: true + if: ${{ steps.build_and_test.outcome == 'failure'}} + run: | + curl --location ${{secrets.DISCORD_WEBHOOK_URL}} \ + --header 'Content-Type: application/json' \ + --data '{ + "avatar_url": "https://cdn-icons-png.flaticon.com/512/25/25231.png", + "embeds": [ + { + "title": "${{ github.event.pull_request.title }}", + "type": "rich", + "description": "빌드가 실패했습니다.", + "url": "https://github.com/Cafegory/Cafegory_Backend_REST_API/pull/${{github.event.number}}" + } + ]}' + + - name: Send Build Success Message to Discord + continue-on-error: true + if: ${{ steps.build_and_test.outcome == 'success'}} + run: | + curl --location ${{secrets.DISCORD_WEBHOOK_URL}} \ + --header 'Content-Type: application/json' \ + --data '{ + "avatar_url": "https://cdn-icons-png.flaticon.com/512/25/25231.png", + "embeds": [ + { + "title": "${{ github.event.pull_request.title }}", + "type": "rich", + "description": "빌드가 성공했습니다! 아싸!", + "url": "https://github.com/Cafegory/Cafegory_Backend_REST_API/pull/${{github.event.number}}" + } + ]}' \ No newline at end of file From ca87a358e4c62db086382735a9fa9adf8ef6381b Mon Sep 17 00:00:00 2001 From: robinjoon Date: Sun, 21 Jan 2024 09:06:22 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix=20:=20=EB=B0=B0=ED=8F=AC=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=EC=97=90=EC=84=9C=20=EB=B9=8C?= =?UTF-8?q?=EB=93=9C=20=EA=B2=B0=EA=B3=BC=20=EB=A9=94=EC=84=B8=EC=A7=80=20?= =?UTF-8?q?=EC=A0=84=EC=86=A1=20=EA=B8=B0=EB=8A=A5=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EB=B0=8F=20=EB=B0=B0=ED=8F=AC=20=EB=A9=94=EC=84=B8=EC=A7=80=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test_build_deploy.yml | 64 ++----------------------- 1 file changed, 3 insertions(+), 61 deletions(-) diff --git a/.github/workflows/test_build_deploy.yml b/.github/workflows/test_build_deploy.yml index 1a59a3e0..a20059dd 100644 --- a/.github/workflows/test_build_deploy.yml +++ b/.github/workflows/test_build_deploy.yml @@ -46,64 +46,6 @@ jobs: remote_path: ${{ secrets.SSH_REMOTE_PATH }} sftp_only: true ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} - - name: If build fail - continue-on-error: true - # 이전 step이 실패한 경우에만 이 step을 실행시키는 syntax - if: ${{ steps.build_and_test.outcome == 'failure'}} - id: close_pr - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const pull_number = ${{ github.event.pull_request.number }} - const updated_title = `[BUILD FAIL] ${{ github.event.pull_request.title }}` - await github.rest.pulls.createReview({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: pull_number, - body: '빌드에 실패했습니다.', - event: 'REQUEST_CHANGES' - }) - await github.rest.pulls.update({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: pull_number, - title: updated_title, - state: 'closed' - }) - - name: Send Build Fail Message to Discord - continue-on-error: true - if: ${{ steps.build_and_test.outcome == 'failure'}} - run: | - curl --location ${{secrets.DISCORD_WEBHOOK_URL}} \ - --header 'Content-Type: application/json' \ - --data '{ - "avatar_url": "https://cdn-icons-png.flaticon.com/512/25/25231.png", - "embeds": [ - { - "title": "${{ github.event.pull_request.title }}", - "type": "rich", - "description": "빌드가 실패했습니다.", - "url": "https://github.com/Cafegory/Cafegory_Backend_REST_API/pull/${{github.event.number}}" - } - ]}' - - - name: Send Build Success Message to Discord - continue-on-error: true - if: ${{ steps.build_and_test.outcome == 'success'}} - run: | - curl --location ${{secrets.DISCORD_WEBHOOK_URL}} \ - --header 'Content-Type: application/json' \ - --data '{ - "avatar_url": "https://cdn-icons-png.flaticon.com/512/25/25231.png", - "embeds": [ - { - "title": "${{ github.event.pull_request.title }}", - "type": "rich", - "description": "빌드가 성공했습니다! 아싸!", - "url": "https://github.com/Cafegory/Cafegory_Backend_REST_API/pull/${{github.event.number}}" - } - ]}' - name: Send Deploy Fail Message to Discord continue-on-error: true if: ${{ steps.deploy_file.outcome == 'failure'}} @@ -117,7 +59,7 @@ jobs: "title": "${{ github.event.pull_request.title }}", "type": "rich", "description": "배포가 실패했습니다.", - "url": "https://github.com/Cafegory/Cafegory_Backend_REST_API/pull/${{github.event.number}}" + "url": "https://github.com/Cafegory/Cafegory_Backend_REST_API" } ]}' - name: Send Deploy Success Message to Discord @@ -133,6 +75,6 @@ jobs: "title": "${{ github.event.pull_request.title }}", "type": "rich", "description": "배포가 성공했습니다!!! 아싸!!!", - "url": "https://github.com/Cafegory/Cafegory_Backend_REST_API/pull/${{github.event.number}}" + "url": "http://${{ secrets.SSH_HOST }}/" } - ]}' \ No newline at end of file + ]}'제 \ No newline at end of file