diff --git a/.github/workflows/auto-update-ubuntu.yml b/.github/workflows/auto-update-ubuntu.yml new file mode 100644 index 00000000..8af4a8a0 --- /dev/null +++ b/.github/workflows/auto-update-ubuntu.yml @@ -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 diff --git a/mxpy-up.py b/mxpy-up.py index 8cfacc3e..316c3b7e 100644 --- a/mxpy-up.py +++ b/mxpy-up.py @@ -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": @@ -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()