-
Notifications
You must be signed in to change notification settings - Fork 104
ci: rewrite deploy scripts with python3 #7046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
1790105
rewrite login_and_get_token
ElectricalBoy f5b7092
add deploy script
ElectricalBoy 5569f26
syntax
ElectricalBoy 37161d5
disable async deploy
ElectricalBoy 5da3213
rewrite with requests
ElectricalBoy 945712e
memoize tokens
ElectricalBoy 5a14d10
res deploy script to python
ElectricalBoy c699946
refactor
ElectricalBoy 965097e
protect_page script to python
ElectricalBoy 308f91c
protect script to python
ElectricalBoy 7c2fd6d
remove dev script to python
ElectricalBoy ec68df6
adjust main call
ElectricalBoy 6d7e592
update gitignore
ElectricalBoy ab8a99e
update workflows
ElectricalBoy e3a97bc
throw away shellscript versions
ElectricalBoy 515a4fb
disable python cache in GHA
ElectricalBoy 151fc48
update workflows
ElectricalBoy c1a656a
bump deploy bot version
ElectricalBoy 4114277
kick debugging print
ElectricalBoy cfde037
suppress python stdout buffering
ElectricalBoy ae49e94
use rglob
ElectricalBoy 25532aa
cleanup
ElectricalBoy c5ac6d7
lint
ElectricalBoy 7a20721
key safety
ElectricalBoy 511fbfd
add python check workflow
ElectricalBoy 1b2db14
adjust workflow
ElectricalBoy 621bcd1
format
ElectricalBoy f057d8f
safer no change detect
ElectricalBoy 22027dd
sort paths before looping
ElectricalBoy 6eac891
sort resources too
ElectricalBoy 5dd3643
adjust workflow
ElectricalBoy ba980c2
extract wiki deploy function
ElectricalBoy 6e7bc44
extract sleep duration to constant
ElectricalBoy 4ed1707
use ruff for styling too
ElectricalBoy 200b156
style
ElectricalBoy baf8d81
oops
ElectricalBoy 2267ac1
adjust workflow trigger
ElectricalBoy 30f2b1a
code conciseness
ElectricalBoy b075a7f
fix login in dev remove script
ElectricalBoy 984ede5
fix incorrect condition reading
ElectricalBoy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,22 @@ | ||
| name: Python Code Style | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - '**.py' | ||
| - '.github/workflows/*.yml' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| python-code-style: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| - name: Run linter | ||
| uses: astral-sh/ruff-action@v3 | ||
| with: | ||
| src: scripts/ | ||
| - name: Check styling | ||
| run: ruff format --check --diff scripts/ |
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5,3 +5,6 @@ | |
| /package-lock.json | ||
| /luacov.report.out | ||
| /luacov.stats.out | ||
| **/__pycache__/ | ||
| .env | ||
| *.ck | ||
This file contains hidden or 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,73 @@ | ||
| import itertools | ||
| import os | ||
| import pathlib | ||
| import re | ||
| import sys | ||
|
|
||
| from typing import Iterable | ||
|
|
||
| import requests | ||
|
|
||
| from deploy_util import ( | ||
| get_git_deploy_reason, | ||
| deploy_file_to_wiki, | ||
| read_cookie_jar, | ||
| read_file_from_path, | ||
| write_to_github_summary_file, | ||
| ) | ||
| from login_and_get_token import get_token | ||
|
|
||
| HEADER_PATTERN = re.compile( | ||
| r"\A---\n" r"-- @Liquipedia\n" r"-- page=(?P<pageName>[^\n]*)\n" | ||
| ) | ||
|
|
||
|
|
||
| def deploy_all_files_for_wiki( | ||
| wiki: str, file_paths: Iterable[pathlib.Path], deploy_reason: str | ||
| ) -> bool: | ||
| all_modules_deployed = True | ||
| token = get_token(wiki) | ||
| with requests.Session() as session: | ||
| session.cookies = read_cookie_jar(wiki) | ||
| for file_path in file_paths: | ||
| print(f"::group::Checking {str(file_path)}") | ||
| file_content = read_file_from_path(file_path) | ||
| header_match = HEADER_PATTERN.match(file_content) | ||
| if not header_match: | ||
| print("...skipping - no magic comment found") | ||
| write_to_github_summary_file(f"{str(file_path)} skipped") | ||
| else: | ||
| page = header_match.groupdict()["pageName"] + ( | ||
| os.getenv("LUA_DEV_ENV_NAME") or "" | ||
| ) | ||
| module_deployed, _ = deploy_file_to_wiki( | ||
| session, file_path, file_content, wiki, page, token, deploy_reason | ||
| ) | ||
| all_modules_deployed &= module_deployed | ||
| print("::endgroup::") | ||
| return all_modules_deployed | ||
|
|
||
|
|
||
| def main(): | ||
| all_modules_deployed = True | ||
| lua_files: Iterable[pathlib.Path] | ||
| git_deploy_reason: str | ||
| if len(sys.argv[1:]) == 0: | ||
| lua_files = pathlib.Path("./lua/wikis/").rglob("*.lua") | ||
| git_deploy_reason = "Automated Weekly Re-Sync" | ||
| else: | ||
| lua_files = [pathlib.Path(arg) for arg in sys.argv[1:]] | ||
| git_deploy_reason = get_git_deploy_reason() | ||
|
|
||
| for wiki, files in itertools.groupby(sorted(lua_files), lambda path: path.parts[2]): | ||
| all_modules_deployed &= deploy_all_files_for_wiki( | ||
| wiki, list(files), git_deploy_reason | ||
| ) | ||
|
|
||
| if not all_modules_deployed: | ||
| print("::warning::Some modules were not deployed!") | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also move this into a dedicated context manager to avoid repetition of cookie reading, but is also a bit overkill
In case we'd then also move the opening of this context manager to be in each main function, and then passed everywhere, we could also get rid of the cookie jar as the session will persist the cookies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think it's a bit overkill