-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (76 loc) · 2.61 KB
/
maven.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
name: Java CI with Maven and Auto Tagging
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
CI:
permissions:
contents: write
runs-on: ubuntu-latest
env:
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
AZURE_STORAGE_CONTAINER_NAME: ${{ secrets.AZURE_STORAGE_CONTAINER_NAME }}
AZURE_STORAGE_URL: ${{ secrets.AZURE_STORAGE_URL }}
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Create application.properties
run: |
echo "azure.storage.url=${AZURE_STORAGE_URL}" > src/main/resources/application.properties
echo "azure.storage.container.name=${AZURE_STORAGE_CONTAINER_NAME}" >> src/main/resources/application.properties
echo "azure.storage.connection.string=${AZURE_STORAGE_CONNECTION_STRING}" >> src/main/resources/application.properties
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Run tests
run: mvn -B test
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v5.6
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: patch
initial_version: '1.0.0' # Sets the initial version if no tags exist
release_branches: main # Ensures tags are only pushed on the main branch
- name: Upload Artifact
id: upload-artifact
uses: actions/upload-artifact@v4
with:
name: application
path: target/*.jar
CD:
needs: [CI]
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: application
path: target/
- name: Deploy to Azure VM
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.AZURE_VM_HOST }}
username: ${{ secrets.AZURE_VM_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.AZURE_VM_PORT }}
source: "target/*.jar"
target: "/home/educai/java-app"
- name: Move Java App to Docker Container
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.AZURE_VM_HOST }}
username: ${{ secrets.AZURE_VM_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.AZURE_VM_PORT }}
script: |
chmod +x /home/educai/script-backend.sh
sh /home/educai/script-backend.sh