Skip to content

Commit dfec667

Browse files
committed
try running this on gha now
1 parent 500bf49 commit dfec667

File tree

2 files changed

+74
-22
lines changed

2 files changed

+74
-22
lines changed

.github/workflows/byond-mirror.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: BYOND Mirror Update
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
mirror:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.12'
19+
20+
# - name: List installed packages (for debugging)
21+
# run: apt list --installed
22+
23+
- name: Install Chromium
24+
run: sudo apt install -y chromium-browser
25+
26+
- name: Install Python dependencies
27+
run: |
28+
pip install --upgrade pip
29+
pip install -r scripts/requirements.txt
30+
pip install webdriver-manager selenium
31+
32+
- name: Run BYOND mirror script
33+
run: python scripts/download_byond_builds.py
34+
35+
- name: Commit and push if content changed
36+
run: |
37+
git config user.name "GitHub Actions"
38+
git config user.email "[email protected]"
39+
git add -A
40+
timestamp=$(date -u)
41+
git commit -m "Latest data: ${timestamp}" || exit 0
42+
git push

scripts/download_byond_builds.py

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,35 @@
1111
from selenium.webdriver.common.by import By
1212
from selenium.webdriver.support.wait import WebDriverWait
1313
from selenium.webdriver.support import expected_conditions as EC
14+
from webdriver_manager.chrome import ChromeDriverManager
15+
from webdriver_manager.utils import ChromeType
16+
from selenium.webdriver.chrome.service import Service
17+
18+
def create_chrome_browser(tmpdirname=None, download=True):
19+
"""Create a Selenium Chrome browser with all recommended options for CI/headless use."""
20+
chrome_service = Service(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install())
21+
chrome_options = webdriver.ChromeOptions()
22+
chrome_options.add_argument('--safebrowsing-disable-download-protection')
23+
options = [
24+
"--headless",
25+
"--disable-gpu",
26+
"--window-size=1920,1200",
27+
"--ignore-certificate-errors",
28+
"--disable-extensions",
29+
"--no-sandbox",
30+
"--disable-dev-shm-usage"
31+
]
32+
for option in options:
33+
chrome_options.add_argument(option)
34+
if download and tmpdirname:
35+
prefs = {
36+
"download.default_directory": tmpdirname,
37+
"download.prompt_for_download": False,
38+
"download.directory_upgrade": True,
39+
"safebrowsing.enabled": True
40+
}
41+
chrome_options.add_experimental_option("prefs", prefs)
42+
return webdriver.Chrome(service=chrome_service, options=chrome_options)
1443

1544
# Set up logging
1645
logging.basicConfig(
@@ -36,8 +65,7 @@ def get_available_builds(version, manual_pause=False):
3665
logger.error(f"Unknown version: {version}")
3766
return []
3867
try:
39-
options = webdriver.ChromeOptions()
40-
browser = webdriver.Chrome(options=options)
68+
browser = create_chrome_browser(download=False)
4169
browser.get(url)
4270
if manual_pause:
4371
input(f"\n[Manual Step] Please solve any CAPTCHAs or Cloudflare challenges in the browser window, then press Enter to continue...")
@@ -64,16 +92,7 @@ def download_file(url, target_path, manual_pause=False, timeout=120):
6492
try:
6593
# Use a unique temp directory for this download
6694
with tempfile.TemporaryDirectory() as tmpdirname:
67-
options = webdriver.ChromeOptions()
68-
options.add_argument('--safebrowsing-disable-download-protection')
69-
prefs = {
70-
"download.default_directory": tmpdirname,
71-
"download.prompt_for_download": False,
72-
"download.directory_upgrade": True,
73-
"safebrowsing.enabled": True
74-
}
75-
options.add_experimental_option("prefs", prefs)
76-
browser = webdriver.Chrome(options=options)
95+
browser = create_chrome_browser(tmpdirname=tmpdirname, download=True)
7796
file_name = os.path.basename(target_path)
7897
browser.get(url)
7998
if manual_pause:
@@ -203,18 +222,9 @@ def download_builds(manual_pause=False):
203222
"""Main function to download BYOND builds"""
204223
output_dir = Path("public")
205224
output_dir.mkdir(exist_ok=True)
206-
options = webdriver.ChromeOptions()
207-
options.add_argument('--safebrowsing-disable-download-protection')
208225
with tempfile.TemporaryDirectory() as tmpdirname:
209-
prefs = {
210-
"download.default_directory": tmpdirname,
211-
"download.prompt_for_download": False,
212-
"download.directory_upgrade": True,
213-
"safebrowsing.enabled": True
214-
}
215226
logger.info(f"Using temporary directory for downloads: {tmpdirname}")
216-
options.add_experimental_option("prefs", prefs)
217-
browser = webdriver.Chrome(options=options)
227+
browser = create_chrome_browser(tmpdirname=tmpdirname, download=True)
218228
try:
219229
for version in BASE_URLS:
220230
version_dir = output_dir / version

0 commit comments

Comments
 (0)