This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
408 lines (368 loc) · 14.8 KB
/
action.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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
---
# This action sets up a Plex Media Server for testing.
name: "Plex Media Server Setup"
description: "This action will install and prepare a Plex Media Server for testing."
inputs:
accept_eula:
description: Accept Plex's EULA.
default: "false"
required: false
additional_server_queries:
description: >-
Space separated list of additional requests to send to the server. The type of request should be at the beginning
of the endpoint, followed by a `|`. If no `|` is found the default request type of `PUT` will be used.
The requests are sent before the library sections are created.
You can use this to enable third party metadata agents, as an example.
e.g. `put|/system/agents/com.plexapp.agents.imdb/config/1?order=com.plexapp.agents.imdb%2C<my_movie_agent>`
default: ""
required: false
bootstrap_timeout:
description: Timeout for each step of bootstrap, in seconds.
default: "540"
required: false
docker_tag:
description: Docker image to to install. Only used when `use_docker` is `true`.
default: "latest"
required: false
expose_plex_data_files_for_docker:
description: >-
When using docker, expose the Plex Media Server application data files to the remainder of your workflow at
./plex.
default: "false"
required: false
language:
description: Language to set inside Plex. Only used when `use_docker` is `false`.
default: "en-US.UTF-8"
required: false
plugin_bundles_to_install:
description: >-
Space separated list of plugin bundles to install. Provide the relative or absolute path to the bundle.
default: ""
required: false
timezone:
description: Timezone to set inside Plex. Only used when `use_docker` is `false`.
default: "UTC"
required: false
use_docker:
description: Use Docker to run Plex Media Server. This is only supported on Linux.
default: "false"
required: false
without_movies:
description: Do not create a Movies library (new agent).
default: "false"
required: false
without_movies_imdb:
description: Do not create a Movies library (IMDB agent).
default: "false"
required: false
without_movies_tmdb:
description: Do not create a Movies library (TMDB agent).
default: "false"
required: false
without_music:
description: Do not create a Music library.
default: "false"
required: false
without_photos:
description: Do not create a Photos library.
default: "false"
required: false
without_shows:
description: Do not create a TV Shows library.
default: "false"
required: false
without_shows_tmdb:
description: Do not create a TV Shows library (TMDB agent).
default: "false"
required: false
without_shows_tvdb:
description: Do not create a TV Shows library (TVDB agent).
default: "false"
required: false
outputs:
PLEXTOKEN:
description: The Plex Media Server authentication token.
value: ${{ steps.token.outputs.plex_token }}
PLEX_APP_DATA_PATH:
description: The path to the Plex Media Server application data.
value: ${{ steps.plex.outputs.app_data_path }}
PLEX_PLUGIN_LOG_PATH:
description: The path to the Plex Media Server plugin logs.
value: ${{ steps.plex.outputs.plugin_log_path }}
PLEX_PLUGIN_PATH:
description: The path to the Plex Media Server plugins.
value: ${{ steps.plex.outputs.plugin_path }}
PLEX_SERVER_BASEURL:
description: The base URL of the Plex Media Server.
value: http://127.0.0.1:32400
runs:
using: "composite"
steps:
- name: Setup Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: "3.11"
update-environment: false
- name: Create venv
id: venv
shell: bash
working-directory: ${{ github.action_path }}
run: |
echo "::group::Create venv"
if [[ "${{ runner.os }}" == "Windows" ]]; then
# use cygpath to convert windows path to unix path while creating venv
$(cygpath.exe -u "${{ steps.setup-python.outputs.python-path }}") -m venv venv
# set python executable as step output
echo "python-path=$(cygpath.exe -u $(pwd)\\venv\\Scripts\\python.exe)" >> $GITHUB_OUTPUT
else
${{ steps.setup-python.outputs.python-path }} -m venv venv
# set python executable as step output
echo "python-path=$(pwd)/venv/bin/python" >> $GITHUB_OUTPUT
fi
echo "::endgroup::"
- name: Build plist
shell: bash
working-directory: ${{ github.action_path }}
run: |
echo "::group::Build plist"
"${{ steps.venv.outputs.python-path }}" ./scripts/build_plist.py
echo "::endgroup::"
- name: Setup plexhints.bundle
shell: bash
working-directory: ${{ github.action_path }}
run: |
echo "::group::Setup plexhints.bundle"
mkdir -p ./plexhints.bundle/Contents
# put Contents directory in bundle
cp -r ./Contents/. ./plexhints.bundle/Contents
echo "::endgroup::"
- name: Install Python Requirements
shell: bash
working-directory: ${{ github.action_path }}
run: |
echo "::group::Install Python Requirements"
# install the plexhints library
"${{ steps.venv.outputs.python-path }}" -m pip install -e .
# install requirements required for this action to complete
"${{ steps.venv.outputs.python-path }}" -m pip install -r requirements-action.txt
echo "::endgroup::"
- name: Install Plex Media Server
id: plex
shell: bash
working-directory: ${{ github.action_path }}
run: |
echo "::group::Install Plex Media Server"
if [[ "${{ inputs.use_docker }}" == "true" ]]; then
if [[ "${{ runner.os }}" != "Linux" ]]; then
echo "Docker install not supported on ${{ runner.os }}"
exit 1
fi
if [[ "${{ inputs.expose_plex_data_files_for_docker }}" == "true" ]]; then
docker_prefix_path="${{ github.workspace }}/plex"
else
docker_prefix_path="${{ github.action_path }}/plex"
fi
app_data_path="${docker_prefix_path}/db/Library/Application Support/Plex Media Server"
plugin_path="${app_data_path}/Plug-ins"
plugin_log_path="${app_data_path}/Logs/PMS Plugin Logs"
elif [[ "${{ runner.os }}" == "Windows" ]]; then
app_data_path=$(cygpath.exe -u "${LOCALAPPDATA}/Plex Media Server")
plugin_path=$(cygpath.exe -u "${app_data_path}/Plug-ins")
plugin_log_path=$(cygpath.exe -u "${app_data_path}/Logs/PMS Plugin Logs")
choco install plexmediaserver
# starting with pmps 1.32.2 servers must be claimed... disable that
# https://forums.plex.tv/t/new-claiming-requirement-for-windows/839096
REG ADD "HKCU\Software\Plex, Inc.\Plex Media Server" //v enableLocalSecurity //t REG_DWORD //d 0 //f
elif [[ "${{ runner.os }}" == "macOS" ]]; then
app_data_path="${HOME}/Library/Application Support/Plex Media Server"
plugin_path="${app_data_path}/Plug-ins"
plugin_log_path="${HOME}/Library/Logs/Plex Media Server/PMS Plugin Logs"
brew install --cask plex-media-server
# starting with pms 1.29.2 servers must be claimed... disable that
# https://forums.plex.tv/t/new-server-claiming-requirement-for-macos/816337
defaults write com.plexapp.plexmediaserver enableLocalSecurity -bool FALSE
# start plex after plugins are copied
elif [[ "${{ runner.os }}" == "Linux" ]]; then
app_data_path="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server"
plugin_path="${app_data_path}/Plug-ins"
plugin_log_path="${app_data_path}/Logs/PMS Plugin Logs"
curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -
echo deb https://downloads.plex.tv/repo/deb public main | \
sudo tee /etc/apt/sources.list.d/plexmediaserver.list
sudo apt-get update
sudo apt-get install plexmediaserver
# stop service
sudo systemctl stop plexmediaserver
# debug
cat /lib/systemd/system/plexmediaserver.service
# do not edit service directly, use override
# example:
# [Service]
# Environment="TMPDIR=/path/to/new/tmp"
# Environment="PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/home/myusername/Library/Application Support"
# User=myusername
# Group=mygroup
override=/etc/systemd/system/plexmediaserver.service.d/override.conf
sudo mkdir -p $(dirname ${override})
sudo touch ${override}
echo "[Service]" | sudo tee ${override}
# echo "Environment=PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=12" | sudo tee -a ${override}
echo "User=$USER" | sudo tee -a ${override}
# take ownership
sudo chown -R $USER:$USER "${app_data_path}"
else
echo "Unknown OS: ${{ runner.os }}"
exit 1
fi
# copy plugins
# first plexhints
echo "creating ${plugin_path}"
mkdir -p "${plugin_path}"
echo "copying ./plexhints.bundle to ${plugin_path}"
cp -r ./plexhints.bundle "${plugin_path}/"
echo "plexhints plugin contents:"
ls -la "${plugin_path}/plexhints.bundle"
# then additional plugins
for bundle in ${{ inputs.plugin_bundles_to_install }}; do
if [[ -d "${bundle}" ]]; then
echo "copying ${bundle} to ${plugin_path}"
cp -r "${bundle}" "${plugin_path}/"
elif [[ -d "${{ github.workspace }}/${bundle}" ]]; then
echo "copying ${{ github.workspace }}/${bundle} to ${plugin_path}"
cp -r "${{ github.workspace }}/${bundle}" "${plugin_path}/"
else
echo "${bundle} not found"
exit 1
fi
echo "plugin contents:"
ls -la "${plugin_path}/${bundle}"
done
# start/restart plex
if [[ "${{ inputs.use_docker }}" == "true" ]]; then
echo "using docker, no need to restart"
elif [[ "${{ runner.os }}" == "Windows" ]]; then
# restart plex
# first stop "Plex Media Server.exe"
taskkill //IM "Plex*" //F
# wait 5 seconds
sleep 5
# then start it again, cygpath converts windows path to unix path
plex_path=$(cygpath.exe -u "${PROGRAMFILES}/Plex/Plex Media Server/Plex Media Server.exe")
if [[ -f "${plex_path}" ]]; then
"${plex_path}" &
else
echo "${plex_path} not found"
exit 1
fi
elif [[ "${{ runner.os }}" == "macOS" ]]; then
# start plex
open "/Applications/Plex Media Server.app"
elif [[ "${{ runner.os }}" == "Linux" ]]; then
# reload daemon
sudo systemctl daemon-reload
# start
sudo systemctl start plexmediaserver
fi
# outputs
if [[ "${{ runner.os }}" == "Windows" ]]; then
app_data_path=$(cygpath.exe -w "${app_data_path}")
plugin_path=$(cygpath.exe -w "${plugin_path}")
plugin_log_path=$(cygpath.exe -w "${plugin_log_path}")
fi
echo "app_data_path=${app_data_path}" >> $GITHUB_OUTPUT
echo "plugin_path=${plugin_path}" >> $GITHUB_OUTPUT
echo "plugin_log_path=${plugin_log_path}" >> $GITHUB_OUTPUT
echo "::endgroup::"
- name: Bootstrap Plex server
env:
PLEX_APP_DATA_PATH: ${{ steps.plex.outputs.app_data_path }}
PLEX_PLUGIN_LOG_PATH: ${{ steps.plex.outputs.plugin_log_path }}
PLEX_PLUGIN_PATH: ${{ steps.plex.outputs.plugin_path }}
PLEXAPI_PLEXAPI_TIMEOUT: "60"
id: bootstrap
shell: bash
working-directory: ${{ github.action_path }}
run: |
echo "::group::Bootstrap Plex server"
# check inputs
if [[ "${{ inputs.accept_eula }}" == "true" ]]; then
accept_eula="--accept-eula"
fi
if [[ -n "${{ inputs.additional_server_queries }}" ]]; then
echo "additional_server_queries: ${{ inputs.additional_server_queries }}"
server_queries_put="--additional-server-queries ${{ inputs.additional_server_queries }}"
fi
if [[ "${{ inputs.use_docker }}" == "false" ]]; then
use_docker="--no-docker"
else
if [[ -n "${{ inputs.docker_tag }}" ]]; then
docker_tag="--docker-tag ${{ inputs.docker_tag }}"
fi
fi
if [[ -n "${{ inputs.language }}" ]]; then
language="--language ${{ inputs.language }}"
fi
if [[ -n "${{ inputs.timezone }}" ]]; then
timezone="--timezone ${{ inputs.timezone }}"
fi
if [[ "${{ inputs.without_movies }}" == "true" ]]; then
without_movies="--without-movies"
fi
if [[ "${{ inputs.without_movies_imdb }}" == "true" ]]; then
without_movies_imdb="--without-movies-imdb"
fi
if [[ "${{ inputs.without_movies_tmdb }}" == "true" ]]; then
without_movies_tmdb="--without-movies-tmdb"
fi
if [[ "${{ inputs.without_music }}" == "true" ]]; then
without_music="--without-music"
fi
if [[ "${{ inputs.without_photos }}" == "true" ]]; then
without_photos="--without-photos"
fi
if [[ "${{ inputs.without_shows }}" == "true" ]]; then
without_shows="--without-shows"
fi
if [[ "${{ inputs.without_shows_tmdb }}" == "true" ]]; then
without_shows_tmdb="--without-shows-tmdb"
fi
if [[ "${{ inputs.without_shows_tvdb }}" == "true" ]]; then
without_shows_tvdb="--without-shows-tvdb"
fi
"${{ steps.venv.outputs.python-path }}" \
-u scripts/plex_bootstraptest.py \
--destination plex \
--advertise-ip 127.0.0.1 \
--bootstrap-timeout ${{ inputs.bootstrap_timeout }} \
--server-name plex-test-${{ runner.os }}-${{ github.run_id }} \
--show-token-plexhints \
${accept_eula} \
${server_queries_put} \
${docker_tag} \
${language} \
${timezone} \
${use_docker} \
${without_movies} \
${without_movies_imdb} \
${without_movies_tmdb} \
${without_music} \
${without_photos} \
${without_shows} \
${without_shows_tmdb} \
${without_shows_tvdb} \
--unclaimed
echo "::endgroup::"
- name: Get token from file
id: token
shell: bash
working-directory: ${{ github.action_path }}
run: |
echo "::group::Get token from file"
if [[ -f .plex_token ]]; then
echo "plex_token=$(cat .plex_token)" >> $GITHUB_OUTPUT
else
echo ".plex_token not found"
exit 1
fi
echo "::endgroup::"