-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (121 loc) · 4.06 KB
/
release.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: "Release"
on:
workflow_dispatch:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build-and-test:
if: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }}
name: Tests
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.TOKEN }}
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'corretto'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Test with Gradle
run: ./gradlew test
generate-jar:
if: ${{ github.event_name == 'push' }}
needs: build-and-test
name: Generate Jar
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.TOKEN }}
- name: Read Application Config
run: |
echo "APP_NAME=$(yq eval '.info.app.name' ./src/main/resources/application.yaml)" >> $GITHUB_ENV
echo "APP_VERSION=$(yq eval '.info.app.version' ./src/main/resources/application.yaml)" >> $GITHUB_ENV
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.TOKEN }}
- name: Create tag
uses: actions/github-script@v6
with:
github-token: ${{ secrets.TOKEN }}
script: |
github.rest.git.createRef({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
ref: "refs/tags/${{ env.APP_VERSION }}",
})
- uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '21'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build PROD with Gradle
run: ./gradlew clean build -x test -Pvaadin.productionMode
- name: Upload package
uses: actions/upload-artifact@v3
with:
name: artifact
path: |
build/libs/quiz-${{ env.APP_VERSION }}.jar
src/main/resources/application.yaml
deploy:
if: ${{ github.event_name == 'push' }}
needs: generate-jar
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.TOKEN }}
- name: Download package
uses: actions/download-artifact@v3
with:
name: artifact
- name: Read Application Config
run: |
echo "APP_VERSION=$(yq eval '.info.app.version' ./src/main/resources/application.yaml)" >> $GITHUB_ENV
- name: Copy jar file to project root dir
run: cp ./build/libs/quiz-${{ env.APP_VERSION }}.jar ./quiz-${{ env.APP_VERSION }}.jar
- name: Deploy file via ssh password
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
source: "quiz-${{ env.APP_VERSION }}.jar"
target: www/quiz
- name: run app
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: kill -9 $(pgrep -f 'quiz') & screen -d -m -S quiz java -jar ./www/quiz/quiz-${{ env.APP_VERSION }}.jar --server.port=${{ secrets.APP_PORT }}
remove-artifact:
if: ${{ github.event_name == 'push' }}
needs: deploy
name: Remove local artifact
runs-on: ubuntu-latest
steps:
- name: Remove local artifact
uses: geekyeggo/delete-artifact@v2
with:
name: artifact