Merge pull request #147 from ShanePark/#flyway #146
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: Dutypark CI/CD | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
submodules: recursive | |
token: ${{ secrets.PAT_TOKEN }} | |
- name: Copy secret files | |
run: | | |
cp dutypark_secret/application-op.yml src/main/resources/ | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 | |
with: | |
arguments: build | |
- name: Upload artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: dutypark-ci | |
path: build/libs/*.jar | |
deploy: | |
needs: build | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: dutypark-ci | |
- name: Setup SSH | |
uses: webfactory/ssh-agent@v0.5.4 | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Add remote server to known hosts | |
run: | | |
mkdir -p ~/.ssh | |
ssh-keyscan ${{ secrets.SSH_IP }} >> ~/.ssh/known_hosts | |
- name: SCP transfer | |
run: scp *.jar ${{ secrets.SSH_USER }}@${{ secrets.SSH_IP }}:/shane | |
- name: Execute remote commands | |
run: | | |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_IP }} "sudo fuser -k 443/tcp || true" | |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_IP }} "sudo nohup java -jar /shane/*.jar --spring.profiles.active=op > /shane/nohup.log 2>&1 &" |