-
-
Notifications
You must be signed in to change notification settings - Fork 4
163 lines (133 loc) · 5.59 KB
/
run_tests.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
---
name: GLuaTest Tester
on:
workflow_call:
inputs:
server-cfg:
type: string
required: false
description: "A path (relative to project directory) with extra server config options"
default: "gluatest_custom.cfg"
requirements:
type: string
required: false
description: "A path (relative to project directory) with a list of all requirements to test this project"
default: "gluatest_requirements.txt"
gamemode:
type: string
required: false
description: "The name of the gamemode for the test server to run. (Be sure to list it as a requirement or include it in the test collection, if necessary)"
default: "sandbox"
collection:
type: string
required: false
description: "The workshop ID of the collection for the test server to use"
ssh-private-key:
type: string
required: false
description: "The Private SSH key to use when cloning the dependencies"
github-token:
type: string
required: false
description: "A GitHub Personal Access Token"
timeout:
type: string
required: false
description: "How many minutes to let the job run before killing the server (small projects shouldn't need more than 2 minutes)"
default: "2"
branch:
type: string
required: false
description: "Which GMod branch to run your tests on. Must be: 'live' or 'x86-64'"
default: "live"
custom-overrides:
type: string
required: false
description: "An absolute path with custom files to copy to the server directly. Structure should match the contents of `garrysmod/`"
jobs:
test:
name: "Run tests"
runs-on: ubuntu-latest
steps:
- name: "Check out the repo"
uses: actions/checkout@v4
with:
path: project
- name: Set up output files
run: |
cd $GITHUB_WORKSPACE
touch $GITHUB_WORKSPACE/project/${{ inputs.requirements }}
echo "gluatest_github_output 1" >> $GITHUB_WORKSPACE/project/${{ inputs.server-cfg }}
- name: Get latest GLuaTest version
id: latest-tag-getter
run: |
cd $GITHUB_WORKSPACE
git clone --single-branch --branch main --depth 1 https://github.com/CFC-Servers/GLuaTest.git gluatest
cd ./gluatest
cp docker/docker-compose.yml $GITHUB_WORKSPACE/docker-compose.yml
git fetch --quiet --tags
latest="$(git describe --tags `git rev-list --tags --max-count=1`)"
echo "Latest Tag: $latest"
echo "LATEST_TAG=$latest" >> $GITHUB_OUTPUT
cd $GITHUB_WORKSPACE
- name: Prepare the override directory
run: |
cd $GITHUB_WORKSPACE/project
get_gamemode_name () {
gamemode_file=$(grep --recursive --word-regexp --files-with-matches '"base"')
gamemode_name=$(head --quiet --lines 1 "$gamemode_file" | tr --delete '"')
echo "$gamemode_name"
}
source="$GITHUB_WORKSPACE/project"
dest="$GITHUB_WORKSPACE/garrysmod_override/"
if [ -d "garrysmod" ]; then
# The repo contains a full server
source="$GITHUB_WORKSPACE/project/garrysmod"
elif [ -d "gamemodes" ]; then
# The repo is the contents of a garrysmod/ dir - we can copy its contents directly
:
elif [ -d "gamemode" ]; then
# The repo is the contents of a gamemode
gamemode_name=$(get_gamemode_name)
dest="$GITHUB_WORKSPACE/garrysmod_override/gamemodes/$gamemode_name/"
elif [ -d "lua" ]; then
# The repo is likely an addon
dest="$GITHUB_WORKSPACE/garrysmod_override/addons/project/"
else
echo "::error title=Unknown project structure!::Please report this: https://github.com/CFC-Servers/GLuaTest/issues"
exit 1
fi
mkdir --verbose --parents "$dest"
cp --recursive --verbose $source/* "$dest/"
- name: Sync custom overrides
if: ${{ inputs.custom-overrides }}
run: |
rsync --verbose --archive ${{ inputs.custom-overrides }} $GITHUB_WORKSPACE/garrysmod_override/
- name: Pull GLuaTest Runner
env:
REQUIREMENTS: "${{ github.workspace }}/project/${{ inputs.requirements }}"
CUSTOM_SERVER_CONFIG: "${{ github.workspace }}/project/${{ inputs.server-cfg }}"
PROJECT_DIR: "${{ github.workspace }}/garrysmod_override"
run: |
if [ ${{ inputs.branch }} = "x86-64" ]; then
echo "Updating compose file to use x86-64 image"
# Replace 'cfc-servers/gluatest' with 'cfc-servers/gluatest/64bit'
sed -i 's/cfc-servers\/gluatest/cfc-servers\/gluatest\/64bit/g' docker-compose.yml
fi
docker compose pull
- name: Run GLuaTest
env:
REQUIREMENTS: "${{ github.workspace }}/project/${{ inputs.requirements }}"
CUSTOM_SERVER_CONFIG: "${{ github.workspace }}/project/${{ inputs.server-cfg }}"
PROJECT_DIR: "${{ github.workspace }}/garrysmod_override"
GAMEMODE: "${{ inputs.gamemode }}"
COLLECTION_ID: "${{ inputs.collection }}"
SSH_PRIVATE_KEY: "${{ inputs.ssh-private-key }}"
GITHUB_TOKEN: "${{ inputs.github-token }}"
TIMEOUT: "${{ inputs.timeout }}"
run: |
docker compose up --no-log-prefix --exit-code-from runner
exitstatus=$?
if [ $exitstatus -ne 0 ]; then
exit $exitstatus
fi