-
-
Notifications
You must be signed in to change notification settings - Fork 247
182 lines (136 loc) · 5.83 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: Setup Ubuntu with Composer and PHP 8
on:
push:
tags:
- '*'
jobs:
setup-ubuntu:
runs-on: ubuntu-20.04
steps:
- name: Check for GitHub API key
if: ${{ github.event_name == 'push' }}
env:
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
run: |
if [ -z "${GITHUB_TOKEN}" ]; then
echo "GitHub API key not found. Exiting..."
exit 0
else
echo "GitHub API key found."
fi
- name: Updating Dependencies + zip
run: |
cd ~
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
HASH=`curl -sS https://composer.github.io/installer.sig`
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
sudo update-alternatives --set php /usr/bin/php8.0
cd /tmp
mkdir linkstack
cd linkstack
TAG_VERSION="${GITHUB_REF##*/}"
version=${TAG_VERSION#"v"}
echo "$version" > version.json
git clone https://github.com/LinkStackOrg/LinkStack/
mkdir linkstack
mv LinkStack linkstack/linkstack
cd linkstack
curl -o README.md https://gist.githubusercontent.com/JulianPrieber/7a3f18a404c524d59c147a8d4f1ad33c/raw/3008f0893da2effaee56b99ee8b956fa533d9b07/README.md
cd linkstack
cp "../../version.json" "version.json"
composer update --no-scripts
php artisan migrate
php artisan db:seed
php artisan db:seed --class="PageSeeder"
php artisan db:seed --class="ButtonSeeder"
rm -r ".git"
rm -r ".github"
rm README.md
cd ../../
rsync -av linkstack/linkstack update
cd update
mv linkstack/database/database.sqlite database.sqlite
curl -o "HOW TO UPDATE.md" https://gist.githubusercontent.com/JulianPrieber/afc782666cf8c8f7a1a9cb9928498af5/raw/dbbbefb3c88ecd7703efbc866209629d9d130659/HOW%2520TO%2520UPDATE.md
rm linkstack/INSTALLING
cd ..
rsync -av linkstack/linkstack/ "$version"
rm "$version/.env"
rm "$version/INSTALLING"
rm "$version/database/database.sqlite"
cp version.json "$version/version.json"
echo "v$version" > "$version/vbeta.json"
touch /tmp/linkstack/linkstack/linkstack/storage/app/ISINSTALLED
cd /tmp/linkstack
cd "$version"
zip -r "$version.zip" *
mv "$version.zip" ../
cd ..
cd linkstack
zip -r "linkstack.zip" *
mv linkstack.zip ../
cd ..
cd update
zip -r "update.zip" *
mv update.zip ../
cd ..
- name: Create GitHub Release
if: ${{ github.event_name == 'push' }}
env:
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
run: |
if [ -z "${GITHUB_TOKEN}" ]; then
echo "GitHub API key not found. Exiting..."
exit 1
else
echo "GitHub API key found."
cd /tmp/linkstack
# Get the repository name in the format 'OWNER/REPO'
REPO_NAME="LinkStackOrg/LinkStack"
# Upload 'update.zip'
gh release upload "${GITHUB_REF##*/}" "update.zip" --clobber -R "$REPO_NAME"
# Upload 'linkstack.zip'
gh release upload "${GITHUB_REF##*/}" "linkstack.zip" --clobber -R "$REPO_NAME"
# Mark the release as the latest
gh release edit "${GITHUB_REF##*/}" --title="${GITHUB_REF##*/}" -R "$REPO_NAME"
fi
- name: Update version.json
if: ${{ github.event_name == 'push' }}
env:
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
run: |
if [ -z "${GITHUB_TOKEN}" ]; then
echo "GitHub API key not found. Exiting..."
exit 1
else
# GitHub credentials
username="JulianPrieber"
token="${{ secrets.MY_GITHUB_TOKEN }}"
# The repository and file path
repo="LinkStackOrg/LinkStack"
file_path="version.json"
# Fetch the latest commit's SHA for the file
sha=$(curl -u "$username:$token" -s "https://api.github.com/repos/$repo/contents/$file_path" | grep -oP '(?<="sha": ")[^"]+')
# Get version from version.json
cd /tmp/linkstack
TAG_VERSION="${GITHUB_REF##*/}"
version=${TAG_VERSION#"v"}
# JSON payload with the new content
payload="{\"message\": \"Update version.json to $version\", \"content\": \"$(echo -ne "$version\n" | base64 -w 0)\", \"sha\": \"$sha\"}"
# API endpoint to create a new commit
url="https://api.github.com/repos/$repo/contents/$file_path"
# Make the API request to update the file
curl -X PUT -u "$username:$token" -d "$payload" "$url"
fi
- name: Upload to Update Server
if: ${{ github.event_name == 'push' }}
run: |
cd /tmp/linkstack
ls
TAG_VERSION="${GITHUB_REF##*/}"
version=${TAG_VERSION#"v"}
# Install the OpenSSH client
sudo apt-get install -y openssh-client
# Clear the remote directory
sshpass -p "${{ secrets.SERVER_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p ${{ secrets.SERVER_PORT }} ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} "rm -rf ${{ secrets.REMOTE_PATH }}/*"
# Use SSH to upload the file to the remote server
sshpass -p "${{ secrets.SERVER_PASSWORD }}" scp -o StrictHostKeyChecking=no -P ${{ secrets.SERVER_PORT }} $version.zip ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:${{ secrets.REMOTE_PATH }}