Skip to content

Commit 5cc761b

Browse files
authored
Yet some more changes (#91)
Do a lot of changes Signed-off-by: RaphaelIT7 <[email protected]> modified: .github/actions/build_and_push/action.yml modified: .github/workflows/run_tests.yml modified: .github/workflows/self_tests.yml modified: docker/Dockerfile modified: docker/docker-compose.yml modified: docker/entrypoint.sh modified: lua/gluatest/init.lua modified: lua/gluatest/runner/log_helpers.lua modified: lua/gluatest/runner/logger.lua modified: lua/tests/gluatest/runner/log_helpers/getFileLines.lua
1 parent 539a24f commit 5cc761b

File tree

10 files changed

+38
-57
lines changed

10 files changed

+38
-57
lines changed

.github/actions/build_and_push/action.yml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,7 @@ runs:
4949
run: |
5050
cd ${{ inputs.path }}/docker
5151
52-
if [ "${{ inputs.gmod_branch }}" = "x86-64" ]; then
53-
BASE=ghcr.io/cfc-servers/gluatest/64bit
54-
elif [ "${{ inputs.gmod_branch }}" = "dev" ]; then
55-
BASE=ghcr.io/cfc-servers/gluatest/dev
56-
elif [ "${{ inputs.gmod_branch }}" = "prerelease" ]; then
57-
BASE=ghcr.io/cfc-servers/gluatest/prerelease
58-
else
59-
BASE=ghcr.io/cfc-servers/gluatest
60-
fi
52+
BASE=ghcr.io/cfc-servers/gluatest/${{ inputs.gmod_branch }}
6153
6254
rawVersionTag=${{ inputs.tag_name }}
6355
id=${{ inputs.game_version }}
@@ -101,14 +93,6 @@ runs:
10193
- name: Tag and push slim image
10294
shell: bash
10395
run: |
104-
if [ "${{ inputs.gmod_branch }}" = "x86-64" ]; then
105-
BASE=ghcr.io/cfc-servers/gluatest/64bit
106-
elif [ "${{ inputs.gmod_branch }}" = "dev" ]; then
107-
BASE=ghcr.io/cfc-servers/gluatest/dev
108-
elif [ "${{ inputs.gmod_branch }}" = "prerelease" ]; then
109-
BASE=ghcr.io/cfc-servers/gluatest/prerelease
110-
else
111-
BASE=ghcr.io/cfc-servers/gluatest
112-
fi
96+
BASE=ghcr.io/cfc-servers/gluatest/${{ inputs.gmod_branch }}
11397
11498
docker push "$BASE" --all-tags

.github/workflows/run_tests.yml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ on:
5959
branch:
6060
type: string
6161
required: false
62-
description: "Which GMod branch to run your tests on. Must be: `live`, `x86-64`, `prerelease`, or `dev`"
63-
default: "live"
62+
description: "Which GMod branch to run your tests on. Must be: `public`, `x86-64`, `prerelease`, or `dev`"
63+
default: "public"
6464

6565
gluatest-repo:
6666
type: string
@@ -211,25 +211,10 @@ jobs:
211211
212212
- name: Pull GLuaTest Runner
213213
if: inputs.dockerbuild != 'true'
214+
env:
215+
GMOD_BRANCH: "${{ inputs.branch }}"
214216
run: |
215217
cd $GITHUB_WORKSPACE/gluatest/docker
216-
if [ ${{ inputs.branch }} = "x86-64" ]; then
217-
echo "Updating compose file to use x86-64 image"
218-
# Replace 'cfc-servers/gluatest' with 'cfc-servers/gluatest/64bit'
219-
sed -i 's/cfc-servers\/gluatest/cfc-servers\/gluatest\/64bit/g' docker-compose.yml
220-
fi
221-
222-
if [ ${{ inputs.branch }} = "dev" ]; then
223-
echo "Updating compose file to use dev image"
224-
# Replace 'cfc-servers/gluatest' with 'cfc-servers/gluatest/dev'
225-
sed -i 's/cfc-servers\/gluatest/cfc-servers\/gluatest\/dev/g' docker-compose.yml
226-
fi
227-
228-
if [ ${{ inputs.branch }} = "prerelease" ]; then
229-
echo "Updating compose file to use prerelease image"
230-
# Replace 'cfc-servers/gluatest' with 'cfc-servers/gluatest/prerelease'
231-
sed -i 's/cfc-servers\/gluatest/cfc-servers\/gluatest\/prerelease/g' docker-compose.yml
232-
fi
233218
234219
docker compose pull
235220
@@ -246,7 +231,7 @@ jobs:
246231
--build-arg="GMOD_BRANCH=${{ inputs.branch }}" \
247232
--build-arg="GLUATEST_REPO=${{ inputs.gluatest-repo }}.git" \
248233
--build-arg="GLUATEST_REF=${{ inputs.gluatest-ref }}" \
249-
--tag ghcr.io/cfc-servers/gluatest:latest .
234+
--tag ghcr.io/cfc-servers/gluatest/${{ inputs.branch }}:latest .
250235
251236
- name: Run GLuaTest
252237
env:

.github/workflows/self_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- "x86-64"
1515
- "dev"
1616
- "prerelease"
17-
- "live"
17+
- "public"
1818
fail-fast: false
1919

2020
uses: ./.github/workflows/run_tests.yml

docker/Dockerfile

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM ghcr.io/cfc-servers/steamcmd:latest
22

3-
ARG GMOD_BRANCH=live
3+
ARG GMOD_BRANCH=public
44
ARG GLUATEST_REF=main
55
ARG GLUATEST_REPO=https://github.com/CFC-Servers/GLuaTest.git
66

@@ -13,19 +13,8 @@ ARG gmodroot=$home/gmodserver
1313
ARG server=$home/gmodserver/garrysmod
1414

1515
USER steam
16-
RUN if [ "$GMOD_BRANCH" = "x86-64" ]; then \
17-
echo "Downloading x86-64 branch"; \
18-
./steamcmd.sh +force_install_dir $gmodroot +login anonymous +app_update 4020 -beta x86-64 validate +quit; \
19-
elif [ "$GMOD_BRANCH" = "dev" ]; then \
20-
echo "Downloading dev branch"; \
21-
./steamcmd.sh +force_install_dir $gmodroot +login anonymous +app_update 4020 -beta dev validate +quit; \
22-
elif [ "$GMOD_BRANCH" = "prerelease" ]; then \
23-
echo "Downloading prerelease branch"; \
24-
./steamcmd.sh +force_install_dir $gmodroot +login anonymous +app_update 4020 -beta prerelease validate +quit; \
25-
else \
26-
echo "Downloading live branch"; \
27-
./steamcmd.sh +force_install_dir $gmodroot +login anonymous +app_update 4020 validate +quit; \
28-
fi
16+
RUN echo "Downloading $GMOD_BRANCH branch"; \
17+
./steamcmd.sh +force_install_dir $gmodroot +login anonymous +app_update 4020 -beta $GMOD_BRANCH validate +quit;
2918

3019
# Initial server config
3120
RUN touch $gmodroot/custom_server.cfg && \
@@ -70,5 +59,6 @@ RUN git clone --depth 1 $GLUATEST_REPO $server/addons/gluatest && \
7059
RUN mkdir --parents --verbose $server/data
7160
RUN mkdir --parents --verbose $server/addons/gluatest/data_static
7261
RUN echo "$GLUATEST_REF" > $server/addons/gluatest/data_static/gluatest_version.txt
62+
RUN echo "$GMOD_BRANCH" > $server/garrysmod_branch.txt
7363

7464
ENTRYPOINT ["/home/steam/gmodserver/entrypoint.sh"]

docker/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
runner:
3-
image: ghcr.io/cfc-servers/gluatest:latest
3+
image: ghcr.io/cfc-servers/gluatest/$GMOD_BRANCH:latest
44
build: .
55
container_name: gluatest_runner
66
stop_grace_period: 2s

docker/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ base_srcds_args=(
136136
)
137137
srcds_args="$EXTRA_STARTUP_ARGS ${base_srcds_args[@]}"
138138

139-
if [ "$gmodbranch" = "x86-64" ]; then
139+
if [ -x "$gmodroot/srcds_run_x64" ]; then
140140
echo "Starting 64-bit server"
141141
unbuffer timeout "$timeout" "$gmodroot"/srcds_run_x64 "$srcds_args"
142142
else

lua/gluatest/init.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
local fileHandle = file.Open( "garrysmod_branch.txt", "rb", "MOD" ) --[[@as File]]
2+
if fileHandle then -- NOTE: This file is created in our docker file / BRANCH will only be accurate inside of the Docker images
3+
BRANCH = fileHandle:ReadLine() -- prerelease shows unknown instead of prerelease as BRANCH. Not useful for tests.
4+
BRANCH = string.Trim( BRANCH )
5+
fileHandle:Close()
6+
end
7+
18
local RED = Color( 255, 0, 0 )
29

310
--- @type VersionTools

lua/gluatest/runner/log_helpers.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ LogHelpers.fileLinesCache = {
6161
--- Reads a given file path and returns the contents split by newline
6262
--- Cached for future calls
6363
--- @param filePath string
64-
--- @return string[]
64+
--- @return string[]?
6565
function LogHelpers.getFileLines( filePath )
6666
local cached = LogHelpers.fileLinesCache:get( filePath )
6767
if cached then return cached end
6868

6969
local cleanPath = LogHelpers.cleanPathForRead( filePath )
7070
local testFile = file.Open( cleanPath, "r", "LUA" ) --[[@as File]]
71+
if not testFile then return nil end
7172
local fileContents = testFile:Read( testFile:Size() )
7273
testFile:Close()
7374

@@ -126,6 +127,7 @@ end
126127
function LogHelpers.GetLineWithContext( path, line, context )
127128
if not context then context = 5 end
128129
local fileLines = LogHelpers.getFileLines( path )
130+
if not fileLines then return {} end
129131

130132
local lineWithContext = {}
131133
for i = line - context, line do

lua/gluatest/runner/logger.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ function ResultLogger.logCodeContext( errInfo )
109109
end
110110
end
111111

112+
if lineCount == 0 then
113+
MsgC( colors.grey, " | ", colors.red, "No source code found!\n" )
114+
end
115+
112116
if lineNumber == -1 then
113117
MsgC( colors.grey, " | ", colors.red, reason, "\n" )
114118
end

lua/tests/gluatest/runner/log_helpers/getFileLines.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ local function fakeFileOpenResponse( read, size )
2020
}
2121
end
2222

23+
-- We need this for getFileLines because LuaLS loves to complain even though expect( lines ).toNot.beNil() checks for it!
24+
---@diagnostic disable: need-check-nil
2325
return {
2426
groupName = "LogHelpers.getFileLines Tests",
2527

@@ -38,6 +40,7 @@ return {
3840
)
3941

4042
local lines = getFileLines( filePath )
43+
expect( lines ).toNot.beNil()
4144
expect( #lines ).to.equal( 3 )
4245
expect( lines[1] ).to.equal( "Line1" )
4346
expect( lines[2] ).to.equal( "Line2" )
@@ -55,6 +58,7 @@ return {
5558

5659
-- First call should open the file
5760
local initialLines = getFileLines( filePath )
61+
expect( initialLines ).toNot.beNil()
5862
expect( #initialLines ).to.equal( 2 )
5963
expect( initialLines[1] ).to.equal( "CachedLine1" )
6064
expect( initialLines[2] ).to.equal( "CachedLine2" )
@@ -67,6 +71,7 @@ return {
6771

6872
-- Second call should use cache and not invoke file.Open
6973
local cachedLines = getFileLines( filePath )
74+
expect( cachedLines ).toNot.beNil()
7075
expect( #cachedLines ).to.equal( 2 )
7176
expect( cachedLines[1] ).to.equal( "CachedLine1" )
7277
expect( cachedLines[2] ).to.equal( "CachedLine2" )
@@ -83,6 +88,7 @@ return {
8388
)
8489

8590
local lines = getFileLines( filePath )
91+
expect( lines ).toNot.beNil()
8692
expect( #lines ).to.equal( 1 )
8793
expect( lines[1] ).to.equal( "SingleLineContent" )
8894
end
@@ -97,6 +103,7 @@ return {
97103
)
98104

99105
local lines = getFileLines( filePath )
106+
expect( lines ).toNot.beNil()
100107
expect( #lines ).to.equal( 1 )
101108
expect( lines[1] ).to.equal( "" )
102109
end
@@ -107,7 +114,9 @@ return {
107114
local filePath = "addons/testaddon/lua/tests/non_existent.txt"
108115

109116
stub( file, "Open" ).returns( nil )
110-
expect( getFileLines, filePath ).to.err()
117+
118+
local lines = getFileLines( filePath )
119+
expect( lines ).to.beNil()
111120
end
112121
}
113122
}

0 commit comments

Comments
 (0)