-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (124 loc) · 4.67 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
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
127
128
129
130
131
132
133
name: Java CI with Maven, Auto-Versioning, and Release
#
on:
push:
branches: [ "master" ]
permissions:
contents: write
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # To ensure tags are fetched as well
token: ${{ secrets.GITHUB_TOKEN }} # Użyj GITHUB_TOKEN do checkout
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven and Auto-Versioning
run: mvn -B build-helper:parse-version versions:set versions:commit package --file pom.xml
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: minecraft-plugin
path: target/*.jar
- name: Extract version and artifact name
id: extract_info
run: |
JAR_NAME=$(ls target/*.jar)
ARTIFACT_NAME=$(basename $JAR_NAME)
VERSION=$(echo $ARTIFACT_NAME | grep -oP '(?<=-)\d+\.\d+\.\d+(?=-SNAPSHOT)')
echo "::set-output name=version::v$VERSION"
echo "::set-output name=artifact_name::$ARTIFACT_NAME"
- name: Create and Push Tag
run: |
git config user.name "GitHub Actions"
git config user.email "github-actions@users.noreply.github.com"
git tag ${{ steps.extract_info.outputs.version }}
git push https://x-access-token:${{ secrets.BE_ACCESS_TOKEN }}@github.com/${{ github.repository }} ${{ steps.extract_info.outputs.version }}
- name: Create Release
uses: softprops/action-gh-release@v1
with:
name: ${{ steps.extract_info.outputs.artifact_name }}
tag_name: ${{ steps.extract_info.outputs.version }}
files: target/*.jar
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
backup-plugins:
needs: build-and-release
runs-on: ubuntu-latest
steps:
- name: Setup SSH Keys
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
env:
SERVER_IP: ${{ secrets.SERVER_IP }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Test SSH Connection
run: |
echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh -o BatchMode=yes -o ConnectTimeout=5 $SERVER_USER@$SERVER_IP "echo SSH connection successful"
env:
SERVER_IP: ${{ secrets.SERVER_IP }}
SERVER_USER: ${{ secrets.SERVER_USER }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Backup Current Plugins
run: |
DATE=$(date +%Y%m%d-%H%M%S)
BACKUP_FILE="minecraft-plugins-backup-$DATE.tgz"
ssh $SERVER_USER@$SERVER_IP "tar czvf $PLUGINS_BACKUP_PATH/$BACKUP_FILE -C $SERVER_PATH ."
env:
SERVER_IP: ${{ secrets.SERVER_IP }}
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_PATH: ${{ secrets.SERVER_PATH }}
PLUGINS_BACKUP_PATH: ${{ secrets.PLUGINS_BACKUP_PATH }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
deploy-to-server:
needs: [build-and-release, backup-plugins]
runs-on: ubuntu-latest
steps:
- name: Setup SSH directory and accept server host key
run: |
mkdir -p ~/.ssh
ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
env:
SERVER_IP: ${{ secrets.SERVER_IP }}
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: minecraft-plugin
- name: List downloaded files
run: |
ls -R
# Lub, aby znaleźć wszystkie pliki JAR w bieżącym katalogu roboczym i jego podkatalogach:
find . -name "*.jar"
- name: Remove Previous Plugin Versions from Server
env:
SERVER_IP: ${{ secrets.SERVER_IP }}
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_PATH: ${{ secrets.SERVER_PATH }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
run: |
echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh $SERVER_USER@$SERVER_IP "rm -f $SERVER_PATH/BetterElo-*.jar"
- name: Deploy JAR to Server
env:
SERVER_IP: ${{ secrets.SERVER_IP }}
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_PATH: ${{ secrets.SERVER_PATH }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
run: |
echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
scp ./BetterElo-*.jar $SERVER_USER@$SERVER_IP:$SERVER_PATH
if: ${{ always() }}