Repository navigation
276 lines (224 loc) · 12.3 KB
/
Copy pathtest-run.yaml
File metadata and controls
276 lines (224 loc) · 12.3 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
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
name: Run upload test
on:
release:
types:
- published
workflow_dispatch:
jobs:
test-upload:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install FFmpeg
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg
- name: Install Oxipng
run: |
# Get the latest release info from the correct repository
RELEASE_INFO=$(curl -s "https://api.github.com/repos/oxipng/oxipng/releases/latest")
# Extract the download URL using jq (more reliable than grep)
OXIPNG_LATEST_URL=$(echo "$RELEASE_INFO" | jq -r '.assets[] | select(.name | contains("x86_64-unknown-linux-musl.tar.gz")) | .browser_download_url')
if [ -z "$OXIPNG_LATEST_URL" ] || [ "$OXIPNG_LATEST_URL" = "null" ]; then
echo "Failed to find latest Oxipng release URL for x86_64-unknown-linux-musl"
echo "Available assets:"
echo "$RELEASE_INFO" | jq -r '.assets[].name'
exit 1
fi
echo "Downloading Oxipng from $OXIPNG_LATEST_URL"
curl -L -o oxipng.tar.gz "$OXIPNG_LATEST_URL"
tar -xzf oxipng.tar.gz
# Find the oxipng binary and move it
find . -name "oxipng" -type f -executable | head -1 | xargs -I {} sudo mv {} /usr/local/bin/
sudo chmod +x /usr/local/bin/oxipng
oxipng --version # Verify installation
- name: Install dependencies
run: |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Download test video
run: |
curl -L -o big.buck.bunny.2008.m4v "https://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_640x360.m4v"
- name: Copy config template
run: cp data/templates/config.py data/config.py
- name: Insert API key into config.py
run: |
echo "Attempting to insert API key."
echo "Length of MY_API_KEY environment variable: ${#MY_API_KEY}"
if [ -z "${MY_API_KEY}" ]; then
echo "Warning: MY_API_KEY environment variable is empty or not set."
else
echo "MY_API_KEY environment variable is set."
fi
sed -i "s|\${API_KEY}|${MY_API_KEY}|g" data/config.py
env:
MY_API_KEY: ${{ secrets.MY_API_KEY }}
- name: Run upload.py with test file and check for errors
run: |
set -e # Exit immediately if a command exits with a non-zero status.
set -o pipefail # Causes a pipeline to return the exit status of the last command in the pipe that returned a non-zero return value.
OUTPUT_FILE="upload_output.txt"
# Run the script, redirecting both stdout and stderr to the console and to a file
python upload.py big.buck.bunny.2008.m4v -ua -ns --debug 2>&1 | tee $OUTPUT_FILE
# The 'python' command above will cause the script to exit if 'upload.py' itself exits non-zero,
# due to 'set -e' and 'set -o pipefail'.
# Now, we check the content of $OUTPUT_FILE for errors that the script might have printed
# even if it exited with code 0.
echo "--- Full Upload Script Output (for debugging) ---"
cat $OUTPUT_FILE
echo "--- End of Full Upload Script Output ---"
# Define error patterns to search for. Add more specific patterns as needed.
# Note: Escape special characters for grep if using complex regex.
ERROR_PATTERNS=(
"Traceback (most recent call last):"
"An unexpected error occurred:"
"Connection refused"
"\[Errno 111\] Connection refused" # Escaped for grep
"Error: Unable to import config."
# Add any other critical error messages your script might print
)
ERROR_FOUND=0
for pattern in "${ERROR_PATTERNS[@]}"; do
if grep -q "$pattern" $OUTPUT_FILE; then
echo "::error::Detected error pattern in script output: $pattern"
ERROR_FOUND=1
fi
done
if [ $ERROR_FOUND -eq 1 ]; then
echo "Critical error patterns found in script output. Failing the step."
exit 1
else
echo "No critical error patterns detected in script output."
fi
- name: Download test video
run: |
curl -L -o tears.of.steel.2012.mkv "https://media.xiph.org/tearsofsteel/tears_of_steel_1080p.webm"
- name: Run upload.py with test file and check for errors
run: |
set -e # Exit immediately if a command exits with a non-zero status.
set -o pipefail # Causes a pipeline to return the exit status of the last command in the pipe that returned a non-zero return value.
OUTPUT_FILE="upload_output.txt"
# Run the script, redirecting both stdout and stderr to the console and to a file
python upload.py tears.of.steel.2012.mkv -ua -ns -siu --tmdb movie/133701 --imdb tt2285752 --tvdb 37711 --debug 2>&1 | tee $OUTPUT_FILE
# The 'python' command above will cause the script to exit if 'upload.py' itself exits non-zero,
# due to 'set -e' and 'set -o pipefail'.
# Now, we check the content of $OUTPUT_FILE for errors that the script might have printed
# even if it exited with code 0.
echo "--- Full Upload Script Output (for debugging) ---"
cat $OUTPUT_FILE
echo "--- End of Full Upload Script Output ---"
# Define error patterns to search for. Add more specific patterns as needed.
# Note: Escape special characters for grep if using complex regex.
ERROR_PATTERNS=(
"Traceback (most recent call last):"
"An unexpected error occurred:"
"Connection refused"
"\[Errno 111\] Connection refused" # Escaped for grep
"Error: Unable to import config."
# Add any other critical error messages your script might print
)
ERROR_FOUND=0
for pattern in "${ERROR_PATTERNS[@]}"; do
if grep -q "$pattern" $OUTPUT_FILE; then
echo "::error::Detected error pattern in script output: $pattern"
ERROR_FOUND=1
fi
done
if [ $ERROR_FOUND -eq 1 ]; then
echo "Critical error patterns found in script output. Failing the step."
exit 1
else
echo "No critical error patterns detected in script output."
fi
- name: Update README badge for master branch
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master'
run: |
DATE_STR=$(date -u "+%Y-%m-%d %H:%M UTC")
# Read the first line of README.md
FIRST_LINE=$(head -1 README.md)
echo "Current line: $FIRST_LINE"
# Extract existing badges using WORKING regex patterns
DOCKER_BADGE=$(echo "$FIRST_LINE" | grep -o '\[\!\[Create and publish a Docker image\][^]]*\]([^)]*)' || echo "[](https://github.com/Audionut/Upload-Assistant/actions/workflows/docker-image.yml)")
echo "Docker badge: $DOCKER_BADGE"
# Extract existing TAG badge (preserve it) - using WORKING pattern
TAG_BADGE=$(echo "$FIRST_LINE" | grep -o '\[\!\[Test run ([^)]*[0-9][0-9]*\.[0-9][^)]*)\][^]]*\]([^)]*)' || echo "")
echo "Tag badge: $TAG_BADGE"
# Create new MASTER badge
MASTER_BADGE="[)](https://github.com/Audionut/Upload-Assistant/actions/workflows/test-run.yaml?query=branch%3Amaster)"
echo "Master badge: $MASTER_BADGE"
# Combine badges (keep existing TAG badge if present)
if [ -n "$TAG_BADGE" ]; then
NEW_FIRST_LINE="$DOCKER_BADGE $MASTER_BADGE $TAG_BADGE"
echo "Including TAG badge in output"
else
NEW_FIRST_LINE="$DOCKER_BADGE $MASTER_BADGE"
echo "No TAG badge found to preserve"
fi
echo "New line: $NEW_FIRST_LINE"
# Update the first line
echo "$NEW_FIRST_LINE" > README.md.new
# Get rest of file (skip first line)
tail -n +2 README.md >> README.md.new
# Replace the file
mv README.md.new README.md
# Commit and push
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git commit -m "Update master branch badge with latest run date [skip ci]" || echo "No changes to commit"
git push
- name: Update README badge for latest tag
if: github.event_name == 'release'
run: |
TAG_NAME="${{ github.event.release.tag_name }}"
DATE_STR=$(date -u "+%Y-%m-%d %H:%M UTC")
# Read the first line of README.md
FIRST_LINE=$(head -1 README.md)
echo "Current line: $FIRST_LINE"
# Extract existing badges using WORKING regex patterns
DOCKER_BADGE=$(echo "$FIRST_LINE" | grep -o '\[\!\[Create and publish a Docker image\][^]]*\]([^)]*)' || echo "[](https://github.com/Audionut/Upload-Assistant/actions/workflows/docker-image.yml)")
echo "Docker badge: $DOCKER_BADGE"
# Extract existing MASTER badge (preserve it) - using WORKING pattern
MASTER_BADGE=$(echo "$FIRST_LINE" | grep -o '\[\!\[Test run (Master Branch)\][^]]*\]([^)]*)' || echo "")
echo "Master badge: $MASTER_BADGE"
# Create new TAG badge
TAG_BADGE="[)](https://github.com/Audionut/Upload-Assistant/actions/workflows/test-run.yaml?query=branch%3A${TAG_NAME})"
echo "New Tag badge: $TAG_BADGE"
# Combine badges (keep existing MASTER badge if present)
if [ -n "$MASTER_BADGE" ]; then
NEW_FIRST_LINE="$DOCKER_BADGE $MASTER_BADGE $TAG_BADGE"
echo "Including MASTER badge in output"
else
NEW_FIRST_LINE="$DOCKER_BADGE $TAG_BADGE"
echo "No MASTER badge found to preserve"
fi
echo "New line: $NEW_FIRST_LINE"
# Update the first line
echo "$NEW_FIRST_LINE" > README.md.new
# Get rest of file (skip first line)
tail -n +2 README.md >> README.md.new
# Replace the file
mv README.md.new README.md
# First commit change to the current detached HEAD
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git commit -m "Update badge for tag ${TAG_NAME} [skip ci]" || echo "No changes to commit"
# Now fetch master branch and apply the same changes there
git fetch origin master:master
git checkout master
# Apply the same badge update to master branch
echo "$NEW_FIRST_LINE" > README.md.new
tail -n +2 README.md >> README.md.new
mv README.md.new README.md
# Commit and push to master
git add README.md
git commit -m "Update badge for tag ${TAG_NAME} [skip ci]" || echo "No changes to commit"
git push origin master
- name: Cleanup config.py
if: always()
run: rm -f data/config.py