-
Notifications
You must be signed in to change notification settings - Fork 1
87 lines (79 loc) · 3.02 KB
/
gradle.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: Java CI with Gradle
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- uses: actions/checkout@v3
- run: touch ./src/main/resources/application-prod.yml
- run: echo "${{ secrets.APPLICATION_PROD }}" > ./src/main/resources/application-prod.yml
- run: cat ./src/main/resources/application-prod.yml
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew clean build --exclude-task test
# - name: Build with Gradle
# uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
# with:
# arguments: build
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: cicd
path: build/libs/*.jar
- name: Upload property file
uses: actions/upload-artifact@v2
with:
name: property
path: ./src/main/resources/application-prod.yml
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: cicd
- name: Download property
uses: actions/download-artifact@v2
with:
name: property
- name: Publish to GitHub Packages Gradle
env:
PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
HOST: ${{ secrets.SERVER_IP }}
USERNAME: ${{ secrets.SSH_USER }}
PORT: ${{ secrets.SERVER_PORT }}
# scp -i private_key.pem -P $PORT -o StrictHostKeyChecking=no -r target/*.jar $USERNAME@$HOST:/home/$USERNAME/
#nohup java -jar /home/$USERNAME/*.jar > /dev/null 2>&1 & disown
run: |
echo "$PRIVATE_KEY" > private_key.pem
chmod 600 private_key.pem
scp -i private_key.pem -P $PORT -o StrictHostKeyChecking=no -r application-prod.yml $USERNAME@$HOST:/home/appuser
scp -i private_key.pem -P $PORT -o StrictHostKeyChecking=no -r *.jar $USERNAME@$HOST:/home/appuser/jars/
ssh -i private_key.pem -p $PORT -o StrictHostKeyChecking=no $USERNAME@$HOST 'bash -s' <<- EOF
pgrep java | xargs kill -9 || true
nohup java -jar /home/appuser/jars/*SNAPSHOT.jar > application.log 2>&1 &
exit
EOF
rm -f private_key.pem