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

feat: save distribution channel and prompt for update #426

Merged
merged 15 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 23 additions & 0 deletions .github/actions/build-binaries/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ inputs:
python_version:
description: "Python version to use"
required: true
distribution:
description: "Distribution channel to use"
required: true

runs:
using: "composite"
Expand Down Expand Up @@ -58,6 +61,8 @@ runs:
cd dist/algokit/
if [ "${{ inputs.production_release }}" == "true" ]; then
tar -zcvf ../../algokit-${{ env.RELEASE_VERSION }}-${{ inputs.operating_system }}-${{ inputs.architecture }}-py${{ inputs.python_version }}.tar.gz *
echo ${{ inputs.distribution }} > ./_internal/distribution_channel/distribution_channel.txt
negar-abbasi marked this conversation as resolved.
Show resolved Hide resolved
tar -zcvf ../../algokit-${{ env.RELEASE_VERSION }}-${{ inputs.distribution }}-${{ inputs.architecture }}-py${{ inputs.python_version }}.tar.gz *
else
tar -zcvf ../../algokit-${{ inputs.operating_system }}-${{ inputs.architecture }}-py${{ inputs.python_version }}.tar.gz *
fi
Expand All @@ -78,6 +83,14 @@ runs:
name: algokit-${{ inputs.operating_system }}-${{ inputs.architecture }}-py${{ inputs.python_version }}
path: algokit-${{ inputs.operating_system }}-${{ inputs.architecture }}-py${{ inputs.python_version }}.tar.gz

- name: Upload binary as artifact (distribution)
if: ${{ inputs.production_release == 'true' }}
uses: actions/upload-artifact@v4
with:
name: algokit-${{ inputs.distribution }}-${{ inputs.architecture }}-py${{ inputs.python_version }}
path: algokit-${{ env.RELEASE_VERSION }}-${{ inputs.distribution }}-${{ inputs.architecture }}-py${{ inputs.python_version }}.tar.gz


- name: Append binary to release
continue-on-error: true
if: ${{ inputs.production_release == 'true' }}
Expand All @@ -87,3 +100,13 @@ runs:
algokit-${{ env.RELEASE_VERSION }}-${{ inputs.operating_system }}-${{ inputs.architecture }}-py${{ inputs.python_version }}.tar.gz
tag_name: ${{ env.RELEASE_VERSION }}
prerelease: ${{ contains(env.RELEASE_VERSION, 'beta') }}

- name: Append binary to release (distribution)
continue-on-error: true
if: ${{ inputs.production_release == 'true' }}
uses: softprops/action-gh-release@v1
with:
files: |
algokit-${{ env.RELEASE_VERSION }}-${{ inputs.distribution }}-${{ inputs.architecture }}-py${{ inputs.python_version }}.tar.gz
tag_name: ${{ env.RELEASE_VERSION }}
prerelease: ${{ contains(env.RELEASE_VERSION, 'beta') }}
1 change: 1 addition & 0 deletions misc/distribution_channel.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
None
negar-abbasi marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ docs_generate = "sphinx-build -b markdown -E docs/sphinx docs/cli"
docs_toc = "gfm-toc docs/cli/index.md -e 3"
docs_title = {shell = "(echo \"# AlgoKit CLI Reference Documentation\\n\\n\"; cat docs/cli/index.md) > docs/cli/temp.md && mv docs/cli/temp.md docs/cli/index.md"}
docs = ["docs_generate", "docs_toc", "docs_title"]
package_unix = "pyinstaller --clean --onedir --hidden-import jinja2_ansible_filters --hidden-import multiformats_config --copy-metadata algokit --name algokit --noconfirm src/algokit/__main__.py --add-data './misc/multiformats_config/multibase-table.json:multiformats_config/' --add-data './misc/multiformats_config/multicodec-table.json:multiformats_config/'"
package_windows = "pyinstaller --clean --onedir --hidden-import jinja2_ansible_filters --hidden-import multiformats_config --copy-metadata algokit --name algokit --noconfirm src/algokit/__main__.py --add-data ./misc/multiformats_config/multibase-table.json;multiformats_config/ --add-data ./misc/multiformats_config/multicodec-table.json;multiformats_config/"

package_unix = "pyinstaller --clean --onedir --hidden-import jinja2_ansible_filters --hidden-import multiformats_config --copy-metadata algokit --name algokit --noconfirm src/algokit/__main__.py --add-data './misc/multiformats_config/multibase-table.json:multiformats_config/' --add-data './misc/multiformats_config/multicodec-table.json:multiformats_config/' --add-data './misc/distribution_channel.txt:distribution_channel/'"
package_windows = "pyinstaller --clean --onedir --hidden-import jinja2_ansible_filters --hidden-import multiformats_config --copy-metadata algokit --name algokit --noconfirm src/algokit/__main__.py --add-data ./misc/multiformats_config/multibase-table.json;multiformats_config/ --add-data ./misc/multiformats_config/multicodec-table.json;multiformats_config/ --add-data ./misc/distribution_channel.txt;distribution_channel/"

[tool.ruff]
line-length = 120
Expand Down
8 changes: 8 additions & 0 deletions src/algokit/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,11 @@ def get_base_python_path() -> str | None:
return str(candidate_path)
# give up, we tried...
return this_python


def is_binary_mode() -> bool:
"""
Check if the current Python interpreter is running in a native binary frozen environment.
return: True if running in a native binary frozen environment, False otherwise.
"""
return getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS")
35 changes: 34 additions & 1 deletion src/algokit/core/version_prompt.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import logging
import re
from datetime import timedelta
from pathlib import Path
from time import time

import click
import httpx

from algokit.core.conf import get_app_config_dir, get_app_state_dir, get_current_package_version
from algokit.core.utils import is_binary_mode

logger = logging.getLogger(__name__)

LATEST_URL = "https://api.github.com/repos/algorandfoundation/algokit-cli/releases/latest"
VERSION_CHECK_INTERVAL = timedelta(weeks=1).total_seconds()
DISABLE_CHECK_MARKER = "disable-version-prompt"

VERSION_UPDATE_MESSAGES = {
"snap": "snap refresh algokit",
"winget": "winget upgrade algokit",
"brew": "brew upgrade algokit",
}


def do_version_prompt() -> None:
if _skip_version_prompt():
Expand All @@ -27,7 +35,18 @@ def do_version_prompt() -> None:
return

if _get_version_sequence(current_version) < _get_version_sequence(latest_version):
logger.info(f"You are using AlgoKit version {current_version}, however version {latest_version} is available.")
if is_binary_mode():
distribution = read_distribution_file()
update_message = VERSION_UPDATE_MESSAGES.get(distribution, "manual process.")
logger.info(
f"You are using AlgoKit version {current_version}, however version {latest_version} is available."
f"Please use {update_message} to update."
negar-abbasi marked this conversation as resolved.
Show resolved Hide resolved
)
else:
logger.info(
f"You are using AlgoKit version {current_version}, however version {latest_version} is available."
f"Please use `pipx upgrade algokit` to update."
neilcampbell marked this conversation as resolved.
Show resolved Hide resolved
)
else:
logger.debug("Current version is up to date")

Expand Down Expand Up @@ -85,6 +104,20 @@ def _skip_version_prompt() -> bool:
return disable_marker.exists()


def read_distribution_file() -> str:
negar-abbasi marked this conversation as resolved.
Show resolved Hide resolved
if not is_binary_mode():
negar-abbasi marked this conversation as resolved.
Show resolved Hide resolved
file_path = Path(__file__).resolve().parents[3] / "misc" / "distribution_channel.txt"
else:
file_path = Path(__file__).resolve().parents[2] / "distribution_channel" / "distribution_channel.txt"
with Path.open(file_path) as file:
content = file.read().strip()

if content in ["snap", "winget", "brew"]:
return content
else:
return "manual"
negar-abbasi marked this conversation as resolved.
Show resolved Hide resolved


skip_version_check_option = click.option(
"--skip-version-check",
is_flag=True,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DEBUG: 1234.56.78 found in cache {app_state}/last-version-check
DEBUG: HTTP Request: GET https://api.github.com/repos/algorandfoundation/algokit-cli/releases/latest "HTTP/1.1 200 OK"
DEBUG: Latest version tag: v{new_version}
You are using AlgoKit version {current_version}, however version {new_version} is available.
You are using AlgoKit version {current_version}, however version {new_version} is available.Please use `pipx upgrade algokit` to update.
DEBUG: Attempting to load project config from {current_working_directory}/.algokit.toml
DEBUG: No .algokit.toml file found in the project directory.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DEBUG: {app_state}/last-version-check inaccessible
DEBUG: HTTP Request: GET https://api.github.com/repos/algorandfoundation/algokit-cli/releases/latest "HTTP/1.1 200 OK"
DEBUG: Latest version tag: v{new_version}
You are using AlgoKit version {current_version}, however version {new_version} is available.
You are using AlgoKit version {current_version}, however version {new_version} is available.Please use `pipx upgrade algokit` to update.
DEBUG: Attempting to load project config from {current_working_directory}/.algokit.toml
DEBUG: No .algokit.toml file found in the project directory.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DEBUG: 1234.56.78 found in cache {app_state}/last-version-check
You are using AlgoKit version {current_version}, however version 1234.56.78 is available.
You are using AlgoKit version {current_version}, however version 1234.56.78 is available.Please use `pipx upgrade algokit` to update.
DEBUG: Attempting to load project config from {current_working_directory}/.algokit.toml
DEBUG: No .algokit.toml file found in the project directory.