Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Resolve # 25] 자동 배포 스크립트 작성 #26

Merged
merged 4 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Close PR when Build Fail
name: Test And Build And Deploy
on:
pull_request:
types: [ opened ]
types: [ opened, reopened, edited, synchronize ]
branches: [ 'main' ]

jobs:
Expand All @@ -23,12 +23,18 @@ 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: If build fail
continue-on-error: true
# 이전 step이 실패한 경우에만 이 step을 실행시키는 syntax
Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/test_build_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Test And Build And Deploy
on:
push:
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: Deploy file
continue-on-error: true
uses: wlixcc/[email protected]
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: 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"
}
]}'
- 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": "http://${{ secrets.SSH_HOST }}/"
}
]}'제