-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7fc3734
Showing
5 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import subprocess | ||
import urllib.request | ||
import os | ||
import sys | ||
import tempfile | ||
|
||
|
||
def main(): | ||
log("Building database...") | ||
|
||
dryrun = False | ||
if len(sys.argv) >= 2 and sys.argv[1] == "-d": | ||
log("Dry run") | ||
dryrun = True | ||
|
||
github_repo = os.getenv("GITHUB_REPOSITORY", "theypsilon/test") | ||
db_id = os.getenv("DB_ID", None) | ||
if db_id is None: | ||
db_id = github_repo | ||
|
||
if not dryrun: | ||
cleanup_build_py(github_repo) | ||
|
||
log("downloading db_operator.py") | ||
urllib.request.urlretrieve( | ||
"https://raw.githubusercontent.com/MiSTer-devel/Distribution_MiSTer/main/.github/db_operator.py", | ||
"/tmp/distribution_db_operator.py", | ||
) | ||
|
||
db_url = f"https://raw.githubusercontent.com/{github_repo}/db/db.json.zip" | ||
base_files_url = f"https://raw.githubusercontent.com/{github_repo}/%s/" | ||
|
||
subprocess.run(["rm *.sh"], shell=True, stderr=subprocess.STDOUT) | ||
|
||
run(["python3", "-m", "pip", "install", "Pillow"]) | ||
|
||
external_files = "external_files.csv" | ||
external_repos_check = subprocess.run( | ||
["git", "ls-remote", "--heads", "origin", "external_repos_files"], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
text=True, | ||
) | ||
if "refs/heads/external_repos_files" in external_repos_check.stdout: | ||
run(["git", "fetch", "origin", "external_repos_files"]) | ||
run(["git", "checkout", "FETCH_HEAD", "--", "external_repos_files.csv"]) | ||
external_files = "external_files.csv external_repos_files.csv" | ||
log("Added external_repos_files.csv from branch external_repos_files!") | ||
|
||
run( | ||
["python3", "/tmp/distribution_db_operator.py", "build", "."], | ||
env={ | ||
"DB_ID": db_id, | ||
"DB_URL": db_url, | ||
"DB_JSON_NAME": "db.json", | ||
"BASE_FILES_URL": base_files_url, | ||
"FINDER_IGNORE": os.getenv("FINDER_IGNORE", "") + " " + external_files, | ||
"BROKEN_MRAS_IGNORE": os.getenv("BROKEN_MRAS_IGNORE", "true"), | ||
"EXTERNAL_FILES": external_files, | ||
}, | ||
) | ||
|
||
if not dryrun and os.path.exists("db.json") and passes_db_tests(db_id): | ||
log("Pushing database...") | ||
run(["zip", "db.json.zip", "db.json"]) | ||
run(["git", "checkout", "--orphan", "db"]) | ||
run(["git", "reset"]) | ||
run(["git", "add", "db.json.zip"]) | ||
run(["git", "commit", "-m", "Creating database"]) | ||
run(["git", "push", "--force", "origin", "db"]) | ||
|
||
return 0 | ||
|
||
|
||
def passes_db_tests(db_id): | ||
log("Testing database...") | ||
|
||
with tempfile.TemporaryDirectory() as temp_folder: | ||
log("downloading downloader.sh") | ||
urllib.request.urlretrieve( | ||
"https://raw.githubusercontent.com/MiSTer-devel/Downloader_MiSTer/main/downloader.sh", | ||
temp_folder + "/downloader.sh", | ||
) | ||
run(["chmod", "+x", "downloader.sh"], cwd=temp_folder) | ||
|
||
downloader_ini_content = f""" | ||
[MiSTer] | ||
base_path = {temp_folder}/ | ||
base_system_path = {temp_folder}/ | ||
update_linux = false | ||
allow_reboot = 0 | ||
verbose = false | ||
downloader_retries = 0 | ||
[{db_id}] | ||
db_url = {os.getcwd()}/db.json | ||
""" | ||
log("downloader.ini content:") | ||
log(downloader_ini_content) | ||
|
||
with open(temp_folder + "/downloader.ini", "w") as fini: | ||
fini.write(downloader_ini_content) | ||
|
||
run(["./downloader.sh"], cwd=temp_folder, env={"DEBUG": "true", "CURL_SSL": ""}) | ||
log("The test went well.") | ||
|
||
return True | ||
|
||
|
||
def cleanup_build_py(github_repo): | ||
if github_repo.lower().strip() == "theypsilon/db-template_mister": | ||
log("Skipping cleanup_build_py") | ||
return | ||
|
||
needs_commit = False | ||
if os.path.exists("build_db.py"): | ||
run(["git", "rm", "build_db.py"]) | ||
needs_commit = True | ||
|
||
if os.path.exists(".github/build_db.py"): | ||
run(["git", "rm", ".github/build_db.py"]) | ||
needs_commit = True | ||
|
||
if needs_commit: | ||
run(["git", "commit", "-m", "BOT: Cleaning build_db.py"]) | ||
run(["git", "push"]) | ||
|
||
|
||
def run(commands, env=None, cwd=None): | ||
log(" ".join(commands)) | ||
if env is not None: | ||
log("with env:", env) | ||
if cwd is not None: | ||
log("with cwd:", cwd) | ||
subprocess.run(commands, cwd=cwd, env=env, check=True, stderr=subprocess.STDOUT) | ||
|
||
|
||
def log(*text): | ||
print(*text, flush=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Build Custom Database | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
permissions: write-all | ||
|
||
jobs: | ||
build_db: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Install apt-get utilities | ||
run: sudo apt-get install detox sharutils | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- uses: qoomon/actions--setup-git@v1 | ||
with: | ||
user: bot | ||
|
||
- name: Build Custom Database for MiSTer Downloader | ||
run: set -o pipefail && curl --fail --location https://raw.githubusercontent.com/theypsilon/Downloader_DB-Template_MiSTer/main/.github/build_db.py | python3 - | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITHUB_REPOSITORY: ${{ github.repository }} | ||
DB_ID: remote_game_gallery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Diego Figueroa | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# remote_game_gallery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Path in MiSTer, URL, Size in bytes (optional but recommended), MD5 Hash (optional but recommended), Filter Terms (optional) |