From 38815141082d35231e667eb2178e7bd27c36a07f Mon Sep 17 00:00:00 2001 From: marinesnow34 Date: Fri, 3 Nov 2023 20:55:21 +0900 Subject: [PATCH] =?UTF-8?q?Config:=20workflow=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - main_merge는 추후 작성 예정 --- .github/workflows/main_merge.yml | 1 + .github/workflows/main_pr.yml | 77 +++++++++++++++++++++++++++++++ .github/workflows/test_merge.yml | 79 ++++++++++++++++++++++++++++++++ .github/workflows/test_pr.yml | 69 ++++++++++++++++++++++++++++ 4 files changed, 226 insertions(+) create mode 100644 .github/workflows/main_merge.yml create mode 100644 .github/workflows/main_pr.yml create mode 100644 .github/workflows/test_merge.yml create mode 100644 .github/workflows/test_pr.yml diff --git a/.github/workflows/main_merge.yml b/.github/workflows/main_merge.yml new file mode 100644 index 0000000..15f0c9c --- /dev/null +++ b/.github/workflows/main_merge.yml @@ -0,0 +1 @@ +#추후에 메인서버 배포시에는 작성 예정 \ No newline at end of file diff --git a/.github/workflows/main_pr.yml b/.github/workflows/main_pr.yml new file mode 100644 index 0000000..1c3ebac --- /dev/null +++ b/.github/workflows/main_pr.yml @@ -0,0 +1,77 @@ +ame: Main Server Pull-request + +on: + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Check branch + run: | + echo "Head branch is: ${{ github.head_ref }}" + echo "Base branch is: ${{ github.base_ref }}" + if [[ "${{ github.head_ref }}" != "test" ]]; then + echo "test 브랜치가 아님" + exit 1 + fi + - name: Checkout source code. # Repo checkout + uses: actions/checkout@v3 + + - name: Set application.properties from secrets + run: | + echo "${{ secrets.MAIN_APPLICATION_PROPERTIES }}" > src/main/resources/application.properties + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'corretto' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew clean build + + after: + runs-on: ubuntu-latest + needs: build + if: always() + permissions: + contents: read + pull-requests: write + steps: + - name: Comment on failure and close PR + if: needs.build.result == 'failure' + uses: actions/github-script@v6 + with: + github-token: ${{ github.token }} + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '빌드 실패' + }); + + github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + state: 'closed' + }); + + - name: Auto approve pull request + if: needs.build.result == 'success' + uses: actions/github-script@v6 + with: + github-token: ${{ github.token }} + script: | + github.rest.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + event: 'APPROVE' + }); diff --git a/.github/workflows/test_merge.yml b/.github/workflows/test_merge.yml new file mode 100644 index 0000000..f0901f5 --- /dev/null +++ b/.github/workflows/test_merge.yml @@ -0,0 +1,79 @@ +name: Test Server Merge +on: + push: + branches: [ "test" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout source code. # Repo checkout + uses: actions/checkout@v3 + + - name: Set application.properties from secrets + run: | + echo "${{ secrets.TEST_APPLICATION_PROPERTIES }}" > src/main/resources/application.properties + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'corretto' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew clean build + + - name: file copy + uses: actions/upload-artifact@v3 + with: + name: build + path: build + deploy: + needs: build + runs-on: ubuntu-latest + steps: + - name: file download + uses: actions/download-artifact@v3 + with: + name: build + path: build + - name: Upload to Cloudflare + env: + AWS_ACCESS_KEY_ID: ${{ secrets.CF_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.CF_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: us-east-1 + BUCKET_NAME: ${{ secrets.CF_BUCKET_NAME }} + ENDPOINT_URL: ${{ secrets.CF_ENDPOINT_URL }} + run: | + aws s3 sync build/libs/*SNAPSHOT.jar s3://$BUCKET_NAME/java/test_main.jar \ + --endpoint-url $ENDPOINT_URL --delete --exact-timestamps + + - name: SSH and deploy + uses: appleboy/ssh-action@v1.0.0 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.SSH_KEY }} + port: ${{ secrets.PORT }} + timeout: 40s # 30초 기본 + script: | + aws s3 sync s3://readyvery-dev-server/java/test_main.jar ./docker/java/test/test_main.jar \ + --endpoint-url https://29c6e4b55b1ddb8d2b6e69df21141caa.r2.cloudflarestorage.com \ + --delete --exact-timestamps + + docker-compose build java-test + docker-compose up -d java-test + + - name: Discordbot alert # 디스코드 알림 + uses: sarisia/actions-status-discord@v1.13.0 + with: + webhook: ${{ secrets.DISCORD_WEBHOOK }} + content: ${{ (github.actor == 'marinesnow34' && '<@392607023495118862>') || + (github.actor == '1223v' && '<@368775981667844098>') || + (github.actor == 'imi21123' && '<@999337351799128115>') || + (github.actor == 'marina-yhm' && '<@946431150614794240>') || + (github.actor == 'hhhhyelim' && '<@1076887091427946496>') }} + if: always() diff --git a/.github/workflows/test_pr.yml b/.github/workflows/test_pr.yml new file mode 100644 index 0000000..5e9216b --- /dev/null +++ b/.github/workflows/test_pr.yml @@ -0,0 +1,69 @@ +name: Test Server Pull-request # Workflow 이름 + +on: + pull_request: + branches: [ "test" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout source code. # Repo checkout + uses: actions/checkout@v3 + + - name: Set application.properties from secrets + run: | + echo "${{ secrets.TEST_APPLICATION_PROPERTIES }}" > src/main/resources/application.properties + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'corretto' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew clean build + + after: + runs-on: ubuntu-latest + needs: build + if: always() + permissions: + contents: read + pull-requests: write + steps: + - name: Comment on failure and close PR + if: needs.build.result == 'failure' + uses: actions/github-script@v6 + with: + github-token: ${{ github.token }} + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '빌드 실패' + }); + + github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + state: 'closed' + }); + + - name: Auto approve pull request + if: needs.build.result == 'success' + uses: actions/github-script@v6 + with: + github-token: ${{ github.token }} + script: | + github.rest.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + event: 'APPROVE' + });