Commit 1fc203f2 authored by nanahira's avatar nanahira

add OCG conflict check

parent 5ac402ec
/dist /dist
/workspace /workspace
/cards.cdb
...@@ -14,6 +14,7 @@ check: ...@@ -14,6 +14,7 @@ check:
- linux - linux
script: script:
- apt update --allow-insecure-repositories && apt -y install sqlite3 git curl - apt update --allow-insecure-repositories && apt -y install sqlite3 git curl
- wget -O cards.cdb https://cdn02.moecube.com:444/ygopro-database/zh-CN/cards.cdb
- ./run.sh - ./run.sh
variables: variables:
YGOPRO_SERVER_PATH: /ygopro-server/ygopro YGOPRO_SERVER_PATH: /ygopro-server/ygopro
......
...@@ -13,14 +13,26 @@ echo '# Auto generated by ygopro-custom-free' > dist/strings.conf ...@@ -13,14 +13,26 @@ echo '# Auto generated by ygopro-custom-free' > dist/strings.conf
CURRENT_TIME=$(date +%s) CURRENT_TIME=$(date +%s)
declare -A used_codes declare -A used_codes
declare -A ocg_codes
blacklist_files=( declare -A blacklist_files
"script/constant.lua"
"script/utility.lua" blacklist_files["script/constant.lua"]=1
"script/init.lua" blacklist_files["script/utility.lua"]=1
"script/special.lua" blacklist_files["script/init.lua"]=1
"script/procedure.lua" blacklist_files["script/special.lua"]=1
) blacklist_files["script/procedure.lua"]=1
sqlite3 cards.cdb 'select id from datas;' | while read -r code; do
if [ -z "$code" ]; then
continue
fi
ocg_codes[$code]=1
blacklist_files["script/c$code.lua"]=1
blacklist_files["pics/$code.jpg"]=1
blacklist_files["pics/$code.png"]=1
blacklist_files["pics/field/$code.jpg"]=1
blacklist_files["pics/field/$code.png"]=1
done
something_changed=0 something_changed=0
process_repo() { process_repo() {
...@@ -56,20 +68,41 @@ process_repo() { ...@@ -56,20 +68,41 @@ process_repo() {
# check last commit date # check last commit date
cd "workspace/$repo_identifer" cd "workspace/$repo_identifer"
last_commit_timestamp="$(git log -1 --format="%cd" --date=format:'%s')"
last_commit_hash="$(git log -1 --format="%H")" last_commit_timestamp="$(git log -1 --format="%cd" --date=format:'%s')"
echo "Checking last commit date of $repo_identifer: $(git log -1 --format="%cd")" last_commit_hash="$(git log -1 --format="%H")"
echo "Checking last commit date of $repo_identifer: $(git log -1 --format="%cd")"
if [ $((CURRENT_TIME - last_commit_timestamp)) -gt $((KEEP_PERIOD_DAYS * 24 * 60 * 60)) ]; then
echo "Skipping $repo_identifer due to outdated: $((CURRENT_TIME - last_commit_timestamp)) > $((KEEP_PERIOD_DAYS * 24 * 60 * 60))"
cd "$current_path"
return
fi
echo "Checking for blacklist files in $repo_identifer"
find . | while read -r file; do
if [ -z "$file" ]; then
continue
fi
if [ -n "${blacklist_files[$file]}" ]; then
echo "Skipping $repo_identifer due to blacklist file $file"
cd "$current_path"
return
fi
done
cd "$current_path" cd "$current_path"
if [ $((CURRENT_TIME - last_commit_timestamp)) -gt $((KEEP_PERIOD_DAYS * 24 * 60 * 60)) ]; then echo "Checking for OCG codes in $repo_identifer"
echo "Skipping $repo_identifer due to outdated: $((CURRENT_TIME - last_commit_timestamp)) > $((KEEP_PERIOD_DAYS * 24 * 60 * 60))"
return
fi
# check for blacklist files ls -1 workspace/$repo_identifer/*.cdb | xargs -I '{}' sqlite3 '{}' 'select id from datas;' | while read -r code; do
for file in "${blacklist_files[@]}"; do if [ -z "$code" ]; then
if [ -e "workspace/$repo_identifer/$file" ]; then continue
echo "Skipping $repo_identifer due to blacklist file: $file" fi
if [ -n "${ocg_codes[$code]}" ]; then
echo "Skipping $repo_identifer due to using OCG code $code"
return return
fi fi
done done
...@@ -84,16 +117,15 @@ process_repo() { ...@@ -84,16 +117,15 @@ process_repo() {
echo "No changes detected in $repo_identifer: $last_commit_hash" echo "No changes detected in $repo_identifer: $last_commit_hash"
fi fi
echo "Searching codes in $repo_identifer"
ls -1 workspace/$repo_identifer/*.cdb | xargs -I '{}' sqlite3 '{}' 'select id from datas where type != 0x11 and (type & 0x4000) = 0;' > "workspace/$repo_identifer-codes.txt"
echo "Checking for redtexts in $repo_identifer" echo "Checking for redtexts in $repo_identifer"
cd "$YGOPRO_SERVER_PATH" cd "$YGOPRO_SERVER_PATH"
rm expansions || rmdir expansions || true
ln -sf "$current_path/workspace/$repo_identifer" expansions
cat "$current_path/workspace/$repo_identifer-codes.txt" | xargs -I '{}' ./ygopro '{}' 2>&1 | tee "$current_path/dist/redtexts/$repo_identifer.txt" rm expansions || rmdir expansions || true
ln -sf "$current_path/workspace/$repo_identifer" expansions
ls -1 $current_path/workspace/$repo_identifer/*.cdb | xargs -I '{}' sqlite3 '{}' 'select id from datas where type != 0x11 and (type & 0x4000) = 0;' | xargs -I '{}' ./ygopro '{}' 2>&1 | tee "$current_path/dist/redtexts/$repo_identifer.txt"
cd "$current_path" cd "$current_path"
redtext_line_count=$(wc -l dist/redtexts/$repo_identifer.txt | cut -d' ' -f1) redtext_line_count=$(wc -l dist/redtexts/$repo_identifer.txt | cut -d' ' -f1)
...@@ -109,7 +141,7 @@ process_repo() { ...@@ -109,7 +141,7 @@ process_repo() {
echo "Checking for used codes in $repo_identifer" echo "Checking for used codes in $repo_identifer"
# add the codes to the used_codes array # add the codes to the used_codes array
while read -r code; do ls -1 workspace/$repo_identifer/*.cdb | xargs -I '{}' sqlite3 '{}' 'select id from datas;' | while read -r code; do
if [ -z "$code" ]; then if [ -z "$code" ]; then
continue continue
fi fi
...@@ -119,9 +151,9 @@ process_repo() { ...@@ -119,9 +151,9 @@ process_repo() {
else else
used_codes[$code]="$repo_url" used_codes[$code]="$repo_url"
fi fi
done < "workspace/$repo_identifer-codes.txt" done
echo "Copying $repo_identifer to dist/$repo_identifer" echo "Archiving $repo_identifer"
ls -1 workspace/$repo_identifer/*.cdb | xargs -I '{}' sqlite3 '{}' .dump | sqlite3 dist/custom-free.cdb || true ls -1 workspace/$repo_identifer/*.cdb | xargs -I '{}' sqlite3 '{}' .dump | sqlite3 dist/custom-free.cdb || true
# copy strings.conf if necessary # copy strings.conf if necessary
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment