Skip to content

Commit 3488166

Browse files
authored
Merge pull request #4198 from seleniumbase/gha-option-for-sbase-mkdir
Add a GitHub Actions option for `sbase mkdir DIR`
2 parents 6627ae4 + cd65c7e commit 3488166

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,15 @@ ui_tests/
831831
832832
Of those files, the `pytest.ini` config file is the most important, followed by a blank `__init__.py` file. There's also a `setup.cfg` file (for pynose). Finally, the `requirements.txt` file can be used to help you install seleniumbase into your environments (if it's not already installed).
833833
834+
<b>ProTip™:</b> Add `--gha` to include a GitHub Actions `.yml` file with default settings:
835+
836+
```zsh
837+
ui_tests/
838+
└── .github
839+
└── workflows/
840+
└── python-package.yml
841+
```
842+
834843
--------
835844
836845
<h3><img src="https://seleniumbase.github.io/img/logo7.png" title="SeleniumBase" width="32" /> Log files from failed tests:</h3>

seleniumbase/console_scripts/ReadMe.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ sbase mkdir ui_tests
296296
297297
```zsh
298298
-b / --basic (Only config files. No tests added.)
299+
--gha (Include GitHub Actions YML with defaults.)
299300
```
300301
301302
* Output:
@@ -340,6 +341,15 @@ ui_tests/
340341
└── setup.cfg
341342
```
342343
344+
If running with the `--gha` option, this is added:
345+
346+
```zsh
347+
ui_tests/
348+
└── .github
349+
└── workflows/
350+
└── python-package.yml
351+
```
352+
343353
<h3>mkfile</h3>
344354
345355
* Usage:

seleniumbase/console_scripts/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def show_mkdir_usage():
248248
print(" sbase mkdir ui_tests")
249249
print(" Options:")
250250
print(" -b / --basic (Only config files. No tests added.)")
251+
print(" --gha (Include GitHub Actions YML with defaults.)")
251252
print(" Output:")
252253
print(" Creates a new folder for running SBase scripts.")
253254
print(" The new folder contains default config files,")

seleniumbase/console_scripts/sb_mkdir.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1111
Options:
1212
-b / --basic (Only config files. No tests added.)
13+
--gha (Include GitHub Actions YML with defaults.)
1314
1415
Output:
1516
Creates a new folder for running SBase scripts.
@@ -32,6 +33,7 @@ def invalid_run_command(msg=None):
3233
exp += " sbase mkdir ui_tests\n"
3334
exp += " Options:\n"
3435
exp += " -b / --basic (Only config files. No tests added.)\n"
36+
exp += " --gha (Include GitHub Actions YML with defaults.)\n"
3537
exp += " Output:\n"
3638
exp += " Creates a new folder for running SBase scripts.\n"
3739
exp += " The new folder contains default config files,\n"
@@ -58,6 +60,7 @@ def main():
5860
c7 = colorama.Fore.BLACK + colorama.Back.MAGENTA
5961
cr = colorama.Style.RESET_ALL
6062

63+
gha = False
6164
basic = False
6265
help_me = False
6366
error_msg = None
@@ -89,6 +92,8 @@ def main():
8992
help_me = True
9093
elif option == "-b" or option == "--basic":
9194
basic = True
95+
elif option == "--gha":
96+
gha = True
9297
else:
9398
invalid_cmd = "\n===> INVALID OPTION: >> %s <<\n" % option
9499
invalid_cmd = invalid_cmd.replace(">> ", ">>" + c5 + " ")
@@ -321,9 +326,69 @@ def main():
321326
file.writelines("\r\n".join(data))
322327
file.close()
323328

329+
if gha:
330+
dir_name_b = dir_name + "/" + ".github"
331+
os.mkdir(dir_name_b)
332+
dir_name_c = dir_name_b + "/" + "workflows"
333+
os.mkdir(dir_name_c)
334+
335+
data = []
336+
data.append("name: CI build")
337+
data.append("on:")
338+
data.append(" push:")
339+
data.append(" branches:")
340+
data.append(" pull_request:")
341+
data.append(" branches:")
342+
data.append(" workflow_dispatch:")
343+
data.append(" branches:")
344+
data.append("jobs:")
345+
data.append(" build:")
346+
data.append(" env:")
347+
data.append(' PY_COLORS: "1"')
348+
data.append(" strategy:")
349+
data.append(" fail-fast: false")
350+
data.append(" max-parallel: 15")
351+
data.append(" matrix:")
352+
data.append(" os: [ubuntu-latest]")
353+
data.append(' python-version: ["3.x"]')
354+
data.append(" runs-on: ${{ matrix.os }}")
355+
data.append(" steps:")
356+
data.append(" - uses: actions/checkout@v6")
357+
data.append(" - name: Set up Python ${{ matrix.python-version }}")
358+
data.append(" uses: actions/setup-python@v6")
359+
data.append(" with:")
360+
data.append(" python-version: ${{ matrix.python-version }}")
361+
data.append(" - name: Install dependencies")
362+
data.append(" run: |")
363+
data.append(" python -m pip install --upgrade pip")
364+
data.append(" pip install -r requirements.txt")
365+
data.append(" - name: Install Chrome")
366+
data.append(" if: matrix.os == 'ubuntu-latest'")
367+
data.append(" run: sudo apt install google-chrome-stable")
368+
data.append(" - name: Download chromedriver")
369+
data.append(" run: sbase get chromedriver")
370+
data.append(" - name: Run pytest")
371+
data.append(" run: pytest -v -s --rs --crumbs --reruns=1")
372+
data.append(" - name: Upload artifacts")
373+
data.append(" if: ${{ always() }}")
374+
data.append(" uses: actions/upload-artifact@v6")
375+
data.append(" with:")
376+
data.append(" name: seleniumbase-artifacts")
377+
data.append(" path: ./latest_logs/")
378+
data.append(" if-no-files-found: ignore")
379+
data.append("")
380+
file_path = "%s/%s" % (dir_name_c, "python-package.yml")
381+
file = open(file_path, mode="w+", encoding="utf-8")
382+
file.writelines("\r\n".join(data))
383+
file.close()
384+
324385
if basic:
325386
data = []
326387
data.append(" %s/" % dir_name)
388+
if gha:
389+
data.append(" ├── .github")
390+
data.append(" │ └── workflows/")
391+
data.append(" │ └── python-package.yml")
327392
data.append(" ├── __init__.py")
328393
data.append(" ├── pytest.ini")
329394
data.append(" ├── requirements.txt")
@@ -741,6 +806,10 @@ def main():
741806

742807
data = []
743808
data.append(" %s/" % dir_name)
809+
if gha:
810+
data.append(" ├── .github")
811+
data.append(" │ └── workflows/")
812+
data.append(" │ └── python-package.yml")
744813
data.append(" ├── __init__.py")
745814
data.append(" ├── my_first_test.py")
746815
data.append(" ├── parameterized_test.py")

0 commit comments

Comments
 (0)