Merge pull request #46 from kyum-q/feat/cd #4
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and deploy | |
on: | |
push: | |
branches: | |
- develop | |
- main | |
- hackathon | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
build-directory: ./backend | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: temurin | |
- name: Build with Gradle Wrapper | |
run: ./gradlew bootJar | |
working-directory: ${{ env.build-directory }} | |
- name: Archive JAR file | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-jar | |
path: backend/build/libs/*.jar | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download JAR artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-jar | |
- name: Copy JAR to remote server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.REMOTE_HOST }} | |
username: ${{ secrets.REMOTE_USER }} | |
key: ${{ secrets.REMOTE_SSH_KEY }} | |
target: ${{ secrets.WORK_DIRECTORY }} | |
source: '*.jar' | |
- name: Execute Server Init Script | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.REMOTE_HOST }} | |
username: ${{ secrets.REMOTE_USER }} | |
key: ${{ secrets.REMOTE_SSH_KEY }} | |
target: ${{ secrets.WORK_DIRECTORY }} | |
script_stop: true | |
script: chmod +x ./deploy.sh && sh ./deploy.sh |