-
-
Notifications
You must be signed in to change notification settings - Fork 12
239 lines (207 loc) · 10.2 KB
/
check_for_updates.yml
File metadata and controls
239 lines (207 loc) · 10.2 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
name: Check for Update and Build Parallel
on:
workflow_dispatch:
inputs:
force_rebuild:
description: 'Force rebuild all images regardless of version checks'
required: false
type: boolean
default: false
schedule:
- cron: "18 */12 * * *"
jobs:
check_updates:
runs-on: ubuntu-latest
outputs:
latest_tag: ${{ steps.latest_tag.outputs.tag_name }}
latest_public: ${{ steps.latest_versions.outputs.public }}
latest_sixtyfour: ${{ steps.latest_versions.outputs.sixtyfour }}
latest_dev: ${{ steps.latest_versions.outputs.dev }}
latest_prerelease: ${{ steps.latest_versions.outputs.prerelease }}
needs_update_public: ${{ steps.needs_update.outputs.public }}
needs_update_sixtyfour: ${{ steps.needs_update.outputs.sixtyfour }}
needs_update_dev: ${{ steps.needs_update.outputs.dev }}
needs_update_prerelease: ${{ steps.needs_update.outputs.prerelease }}
any_update_needed: ${{ steps.needs_update.outputs.any }}
steps:
- name: Checkout Full Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
path: full_repo
- name: Get Latest Tag
id: latest_tag
run: |
cd "$GITHUB_WORKSPACE/full_repo"
# Robust tag matching for semver-like tags
latest_tag=$(git tag --list --sort=-v:refname '[0-9]*.[0-9]*' '[0-9]*.[0-9]*.[0-9]*' | grep -v '[^0-9.]' | head -n 1)
if [ -z "$latest_tag" ]; then
echo "Could not find a suitable latest tag."
exit 1
fi
echo "Latest tag: $latest_tag"
echo "tag_name=$latest_tag" >> $GITHUB_OUTPUT
- name: Pull the steamcmd image
run: |
docker pull ghcr.io/cfc-servers/steamcmd-slim:latest
- name: Lookup latest build IDs
id: latest_versions
run: |
# Ensure workspace directory exists if needed later
mkdir -p "$GITHUB_WORKSPACE"
docker run \
--rm \
--name version_checker \
ghcr.io/cfc-servers/steamcmd-slim:latest \
/home/steam/steamcmd/steamcmd.sh +login anonymous +app_info_request 4020 +login anonymous +app_info_print 4020 +exit \
> "$GITHUB_WORKSPACE/raw_output.txt"
# Extract just the part we care about
struct="$GITHUB_WORKSPACE/struct.txt"
sed -e '1,/"4020"$/ d' "$GITHUB_WORKSPACE/raw_output.txt" > "$struct"
# Get the latest build IDs
public=$(grep -A 2 '"public"' "$struct" | grep '"buildid"' | awk '{print $2}' | sed 's/"//g')
sixtyfour=$(grep -A 2 '"x86-64"' "$struct" | grep '"buildid"' | awk '{print $2}' | sed 's/"//g')
dev=$(grep -A 2 '"dev"' "$struct" | grep '"buildid"' | awk '{print $2}' | sed 's/"//g')
prerelease=$(grep -A 2 '"prerelease"' "$struct" | grep '"buildid"' | awk '{print $2}' | sed 's/"//g')
echo "Latest Public ID: '$public'"
echo "Latest 64bit ID: '$sixtyfour'"
echo "Latest Dev ID: '$dev'"
echo "Latest prerelease ID: '$prerelease'"
if [ -z "$public" ] || [ -z "$sixtyfour" ] || [ -z "$dev" ] || [ -z "$prerelease" ]; then
echo "Failed to get one or more latest build IDs"
echo "Raw Output from SteamCMD:"
cat "$GITHUB_WORKSPACE/raw_output.txt"
exit 1
fi
# Set the output
echo "public=$public" >> $GITHUB_OUTPUT
echo "sixtyfour=$sixtyfour" >> $GITHUB_OUTPUT
echo "dev=$dev" >> $GITHUB_OUTPUT
echo "prerelease=$prerelease" >> $GITHUB_OUTPUT
- name: Checkout last build branch
uses: actions/checkout@v4
with:
ref: build/last-build-versions
path: build_versions
- name: Read last build IDs
id: last_versions
run: |
public=$(cat $GITHUB_WORKSPACE/build_versions/last_public_build.txt 2>/dev/null || echo "0")
sixtyfour=$(cat $GITHUB_WORKSPACE/build_versions/last_64bit_build.txt 2>/dev/null || echo "0")
dev=$(cat $GITHUB_WORKSPACE/build_versions/last_dev_build.txt 2>/dev/null || echo "0")
prerelease=$(cat $GITHUB_WORKSPACE/build_versions/last_prerelease_build.txt 2>/dev/null || echo "0")
echo "Last Public ID built: '$public'"
echo "Last 64bit ID built: '$sixtyfour'"
echo "Last Dev ID built: '$dev'"
echo "Last prerelease ID built: '$prerelease'"
echo "public=$public" >> $GITHUB_OUTPUT
echo "sixtyfour=$sixtyfour" >> $GITHUB_OUTPUT
echo "dev=$dev" >> $GITHUB_OUTPUT
echo "prerelease=$prerelease" >> $GITHUB_OUTPUT
- name: Identify pending updates
id: needs_update
run: |
# Compare versions and set boolean flags (as strings 'true'/'false')
needs_public=$([[ "${{ steps.latest_versions.outputs.public }}" != "${{ steps.last_versions.outputs.public }}" ]] && echo "true" || echo "false")
needs_sixtyfour=$([[ "${{ steps.latest_versions.outputs.sixtyfour }}" != "${{ steps.last_versions.outputs.sixtyfour }}" ]] && echo "true" || echo "false")
needs_dev=$([[ "${{ steps.latest_versions.outputs.dev }}" != "${{ steps.last_versions.outputs.dev }}" ]] && echo "true" || echo "false")
needs_prerelease=$([[ "${{ steps.latest_versions.outputs.prerelease }}" != "${{ steps.last_versions.outputs.prerelease }}" ]] && echo "true" || echo "false")
# If this was a manual run with the "force_rebuild" option, update them all regardless of if they're outdated
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.force_rebuild }}" == "true" ]]; then
echo "Force rebuild requested via workflow_dispatch input. Overriding version checks."
needs_public="true"
needs_sixtyfour="true"
needs_dev="true"
needs_prerelease="true"
fi
echo "Should build Public: '$needs_public'"
echo "Should build 64bit: '$needs_sixtyfour'"
echo "Should build Dev: '$needs_dev'"
echo "Should build Prerelease: '$needs_prerelease'"
echo "public=$needs_public" >> $GITHUB_OUTPUT
echo "sixtyfour=$needs_sixtyfour" >> $GITHUB_OUTPUT
echo "dev=$needs_dev" >> $GITHUB_OUTPUT
echo "prerelease=$needs_prerelease" >> $GITHUB_OUTPUT
# Determine if any update is needed for the final commit step
any_update="false"
if [[ "$needs_public" == "true" || "$needs_sixtyfour" == "true" || "$needs_dev" == "true" || "$needs_prerelease" == "true" ]]; then
any_update="true"
fi
echo "Any update needed: $any_update"
echo "any=$any_update" >> $GITHUB_OUTPUT
trigger_builds:
needs: check_updates
runs-on: ubuntu-latest
if: needs.check_updates.outputs.any_update_needed == 'true'
strategy:
fail-fast: false
matrix:
branch: [public, x86-64, dev, prerelease]
include:
- branch: public
needs_update_flag: ${{ needs.check_updates.outputs.needs_update_public }}
game_version: ${{ needs.check_updates.outputs.latest_public }}
- branch: x86-64
needs_update_flag: ${{ needs.check_updates.outputs.needs_update_sixtyfour }}
game_version: ${{ needs.check_updates.outputs.latest_sixtyfour }}
- branch: dev
needs_update_flag: ${{ needs.check_updates.outputs.needs_update_dev }}
game_version: ${{ needs.check_updates.outputs.latest_dev }}
- branch: prerelease
needs_update_flag: ${{ needs.check_updates.outputs.needs_update_prerelease }}
game_version: ${{ needs.check_updates.outputs.latest_prerelease }}
steps:
- name: Checkout Full Repo
uses: actions/checkout@v4
with:
path: full_repo
- name: Update ${{ matrix.branch }} Build
if: matrix.needs_update_flag == 'true'
uses: ./full_repo/.github/actions/build_and_push
with:
gmod_branch: ${{ matrix.branch }}
game_version: ${{ matrix.game_version }}
tag_name: ${{ needs.check_updates.outputs.latest_tag }}
release: true
github_token: ${{ secrets.GITHUB_TOKEN }}
path: $GITHUB_WORKSPACE/full_repo
update_last_versions:
runs-on: ubuntu-latest
needs: [check_updates, trigger_builds]
if: always() && needs.check_updates.outputs.any_update_needed == 'true'
steps:
- name: Checkout last build branch
uses: actions/checkout@v4
with:
ref: build/last-build-versions
path: build_versions
- name: Update last version files
run: |
cd $GITHUB_WORKSPACE/build_versions
# Update files with the latest versions fetched in the check_updates job
echo "${{ needs.check_updates.outputs.latest_public }}" > ./last_public_build.txt
echo "${{ needs.check_updates.outputs.latest_sixtyfour }}" > ./last_64bit_build.txt
echo "${{ needs.check_updates.outputs.latest_dev }}" > ./last_dev_build.txt
echo "${{ needs.check_updates.outputs.latest_prerelease }}" > ./last_prerelease_build.txt
git config user.name "github-actions"
git config user.email "github-actions@github.com"
if [[ -z $(git status --porcelain) ]]; then
echo "No changes detected in last build version files."
exit 0
else
echo "Changes detected. Committing and pushing..."
git add .
git commit -m "Update last build versions after check [skip ci]"
git push origin build/last-build-versions
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Dispatch gmod_tests # Yes we shouldn't normally depend on this, though it really doesn't hurt.
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GH_API_KEY }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/CFC-Servers/gmod_tests/actions/workflows/branch_tests.yml/dispatches \
-d '{"ref":"main","inputs":{"force_run":"false"}}'