-
Notifications
You must be signed in to change notification settings - Fork 20
225 lines (202 loc) · 8.34 KB
/
Copy pathupdate_services.yml
File metadata and controls
225 lines (202 loc) · 8.34 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: Build MafiaHub Services
on:
workflow_dispatch:
push:
branches:
- develop
jobs:
check_submodule:
name: Check for services-adapter changes
runs-on: ubuntu-latest
if: github.event_name == 'push'
outputs:
should_build: ${{ steps.check_changes.outputs.changed }}
steps:
- name: Checkout services-adapter repository
uses: actions/checkout@v4
with:
repository: MafiaHub/services-adapter
path: services-adapter-repo
token: ${{ secrets.FW_SERVICES_PAT }}
fetch-depth: 0
- name: Get latest commits and check for changes
id: check_changes
run: |
cd services-adapter-repo
# Get the timestamp of the last successful build from build.txt
LAST_BUILD_TIMESTAMP=$(curl -s -f -L https://github.com/MafiaHub/Framework/releases/download/MafiaHub-Services/build.txt || echo "0")
echo "Raw timestamp response: '$LAST_BUILD_TIMESTAMP'"
# Trim whitespace and make sure we have a valid number
LAST_BUILD_TIMESTAMP=$(echo "$LAST_BUILD_TIMESTAMP" | tr -d '[:space:]')
if ! [[ "$LAST_BUILD_TIMESTAMP" =~ ^[0-9]+$ ]]; then
echo "Invalid timestamp format, defaulting to 0"
LAST_BUILD_TIMESTAMP=0
fi
# Convert UNIX timestamp to date format for git log (Linux format)
if [ "$LAST_BUILD_TIMESTAMP" -gt 0 ]; then
LAST_BUILD_TIME=$(date -d "@$LAST_BUILD_TIMESTAMP" "+%Y-%m-%d %H:%M:%S")
else
# Default to a very old date if build.txt doesn't exist or can't be retrieved
LAST_BUILD_TIME="2000-01-01 00:00:00"
fi
echo "Last successful build timestamp: $LAST_BUILD_TIMESTAMP"
echo "Last successful build time: $LAST_BUILD_TIME"
# Check if there are any commits after the last build time
RECENT_COMMITS=$(git log --since="$LAST_BUILD_TIME" --pretty=format:"%h %s" --no-merges)
if [ -n "$RECENT_COMMITS" ]; then
echo "Recent commits found in services-adapter:"
echo "$RECENT_COMMITS"
echo "changed=true" >> $GITHUB_OUTPUT
echo "Services adapter has changed since last build. Triggering build."
else
echo "No new commits in services-adapter since last build."
echo "changed=false" >> $GITHUB_OUTPUT
fi
notify_start:
name: Send Start Notification
needs: check_submodule
if: github.event_name == 'workflow_dispatch' || needs.check_submodule.outputs.should_build == 'true'
runs-on: ubuntu-latest
steps:
- name: Send Discord Notification
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.RELEASES_WEBHOOK }}
title: "MafiaHub Services updating..."
nodetail: true
description: |
Do not sync your Framework repository until this process is finished.
color: 0x440000
username: MafiaHub Services
build:
name: Build MafiaHubServices on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: notify_start
if: github.event_name == 'workflow_dispatch' || needs.check_submodule.outputs.should_build == 'true'
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
include:
- os: windows-latest
cmake_generator: "Visual Studio 17 2022"
build_type: "Release"
- os: ubuntu-latest
cmake_generator: "Unix Makefiles"
build_type: "Release"
- os: macos-latest
cmake_generator: "Unix Makefiles"
build_type: "Release"
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.FW_SERVICES_PAT }}
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '16.2.0'
if: runner.os == 'macOS'
- name: Install tools on Ubuntu
run: sudo apt-get install -y ninja-build build-essential libcurl4-openssl-dev
if: runner.os == 'Linux'
- name: Set up CMake
uses: lukka/get-cmake@latest
with:
cmakeVersion: "~3.31.0"
- name: Set up Visual Studio shell
if: runner.os == 'Windows'
uses: egor-tensin/vs-shell@v2
- name: Configure CMake (Windows)
if: runner.os == 'Windows'
run: |
cmake -B build -G "Ninja" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
- name: Configure CMake (Unix)
if: runner.os != 'Windows'
run: |
cmake -G "${{ matrix.cmake_generator }}" -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
- name: Build MafiaHubServices
run: |
cmake --build build --target MafiaHubServices --config ${{ matrix.build_type }}
- name: Upload MafiaHub Services
uses: actions/upload-artifact@v4
with:
name: mafiahub-services-${{ matrix.os }}
path: |
${{ github.workspace }}/code/framework/src/services/lib
${{ github.workspace }}/code/framework/src/services/services
if-no-files-found: error
release:
name: Create or Update Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: temp-artifacts
- name: Create build.txt with timestamp
run: |
mkdir -p release-artifacts
# Create a clean timestamp without newlines or whitespace
echo -n "$(date +%s)" > release-artifacts/build.txt
cat release-artifacts/build.txt
echo "Created build.txt with timestamp: $(cat release-artifacts/build.txt)"
- name: Zip artifacts by platform
run: |
# Zip each platform's artifacts separately
for platform in temp-artifacts/*; do
platform_name=$(basename "$platform")
cd "$platform"
zip -r "../../release-artifacts/$platform_name.zip" .
cd "../.."
done
- name: Check for existing release
id: check_release
run: |
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/MafiaHub-Services" | \
jq -r '.id // "null"')
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV
if [ "$RELEASE_ID" != "null" ]; then
echo "release_exists=true" >> $GITHUB_OUTPUT
else
echo "release_exists=false" >> $GITHUB_OUTPUT
fi
- name: Delete existing release assets
if: steps.check_release.outputs.release_exists == 'true'
run: |
# Get all assets for the release
assets=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}/assets")
# Delete each asset
for asset_id in $(echo $assets | jq -r '.[].id'); do
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/assets/$asset_id"
done
- name: Create or update release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: MafiaHub-Services
name: MafiaHub Services
draft: false
prerelease: false
body: "MafiaHub Services automated build from ${{ github.sha }}"
files: release-artifacts/*.*
fail_on_unmatched_files: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Send Discord Notification
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.RELEASES_WEBHOOK }}
title: "MafiaHub Services updated! 🎉"
nodetail: true
description: |
Make sure your Framework repository is up-to-date to avoid any conflicts.
color: 0x440000
username: MafiaHub Services