Skip to content
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

Mxpy auto-update command #368

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/auto-update-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Auto-Update mxpy (Ubuntu)

on:
pull_request:
branches: [main, feat/*]
workflow_dispatch:

env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}

jobs:
install:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.11]

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install
run: |
wget -O mxpy-up.py https://raw.githubusercontent.com/multiversx/mx-sdk-py-cli/$BRANCH_NAME/mxpy-up.py
python3 mxpy-up.py --exact-version=9.0.0 --not-interactive
- name: Smoke test
run: |
export PATH="~/multiversx-sdk:${PATH}"
mxpy --version
- name: Auto-Update
run: |
export PATH="~/multiversx-sdk:${PATH}"
mxpy-update
mxpy --version
27 changes: 24 additions & 3 deletions mxpy-up.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,32 @@ def install_mxpy(exact_version: str, from_branch: str, verbose: bool):
logger.debug(f"Shortcut does not exist yet: {shortcut_path}")
pass

shortcut_content = get_mxpy_shortcut_content()
operating_system = get_operating_system()
shortcut_content = get_mxpy_shortcut_content(operating_system)
shortcut_path.write_text(shortcut_content)

st = os.stat(shortcut_path)
os.chmod(shortcut_path, st.st_mode | stat.S_IEXEC)

update_shortcut_path = sdk_path / "mxpy-update"

try:
update_shortcut_path.unlink()
logger.debug(f"Removed existing shortcut: {update_shortcut_path}")
except FileNotFoundError:
logger.debug(f"Shortcut does not exist yet: {update_shortcut_path}")
pass

update_shortcut_content = get_mxpy_update_shortcut_content(operating_system)
update_shortcut_path.write_text(update_shortcut_content)

st = os.stat(update_shortcut_path)
os.chmod(update_shortcut_path, st.st_mode | stat.S_IEXEC)

logger.info("You have successfully installed mxpy.")


def get_mxpy_shortcut_content():
operating_system = get_operating_system()
def get_mxpy_shortcut_content(operating_system: str):
venv_path = get_mxpy_venv_path()

if operating_system == "windows":
Expand All @@ -206,6 +221,12 @@ def get_mxpy_shortcut_content():
"""


def get_mxpy_update_shortcut_content(operating_system: str):
return f"""#!/bin/sh
wget -O mxpy-up.py https://raw.githubusercontent.com/multiversx/mx-sdk-py-cli/mxpy-update/mxpy-up.py && python3 mxpy-up.py --not-interactive "$@"
"""


def run_in_venv(args: List[str], venv_path: Path, verbose: bool):
env = os.environ.copy()

Expand Down