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

Update msi package process and get latest json version when msi pf upgrade #2045

Merged
merged 2 commits into from
Feb 20, 2024
Merged
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
25 changes: 18 additions & 7 deletions .github/workflows/build_msi_installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ jobs:
- name: Python Setup
uses: "./.github/actions/step_create_python_environment"

- name: Setup and Install dev promptflow
if: ${{ github.event.inputs.version == null || github.event.inputs.version == '' }}
uses: "./.github/actions/step_sdk_setup"
with:
setupType: promptflow_with_extra
scriptPath: ${{ env.testWorkingDirectory }}

- name: Install stable promptflow
if: ${{ github.event.inputs.version != null && github.event.inputs.version != '' }}
run: |
Expand Down Expand Up @@ -98,6 +91,24 @@ jobs:
MSI_PRIVATE_VERSION: ${{ github.event.inputs.set_msi_private_version }}
shell: pwsh

- name: Update promptflow package version when set msi private version
YingChen1996 marked this conversation as resolved.
Show resolved Hide resolved
if: ${{ github.event.inputs.set_msi_private_version != null && github.event.inputs.set_msi_private_version != '' }}
run: |
$override_version = 'VERSION = "{0}"' -f $env:MSI_PRIVATE_VERSION
Write-Host "'$override_version' as version"
$override_version | Out-File -FilePath "./src/promptflow/promptflow/_version.py" -Encoding ASCII
shell: pwsh
env:
MSI_PRIVATE_VERSION: ${{ github.event.inputs.set_msi_private_version }}

- name: Setup and Install dev promptflow
if: ${{ github.event.inputs.version == null || github.event.inputs.version == '' }}
uses: "./.github/actions/step_sdk_setup"
with:
setupType: promptflow_with_extra
scriptPath: ${{ env.testWorkingDirectory }}


- name: Build Pyinstaller project
working-directory: ${{ github.workspace }}/scripts/installer/windows/scripts
run: |
Expand Down
12 changes: 6 additions & 6 deletions src/promptflow/promptflow/_cli/_pf/_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ def upgrade_version(args):
from packaging.version import parse

from promptflow._constants import _ENV_PF_INSTALLER, CLI_PACKAGE_NAME
from promptflow._utils.version_hint_utils import get_latest_version_from_pypi
from promptflow._utils.version_hint_utils import get_latest_version
from promptflow._version import VERSION as local_version

latest_version = get_latest_version_from_pypi(CLI_PACKAGE_NAME)
installer = os.getenv(_ENV_PF_INSTALLER) or ""
installer = installer.upper()
print(f"installer: {installer}")
latest_version = get_latest_version(CLI_PACKAGE_NAME, installer=installer)
if not latest_version:
logger.warning("Failed to get the latest prompt flow version.")
return
Expand All @@ -53,9 +56,6 @@ def upgrade_version(args):

yes = args.yes
exit_code = 0
installer = os.getenv(_ENV_PF_INSTALLER) or ""
installer = installer.upper()
print(f"installer: {installer}")
latest_version_msg = (
"Upgrading prompt flow CLI version to {}.".format(latest_version)
if yes
Expand All @@ -82,7 +82,7 @@ def upgrade_version(args):
"pip",
"install",
"--upgrade",
"promptflow[azure,executable,azureml-serving]",
"promptflow[azure,executable,azureml-serving,executor-service]",
"-vv",
"--disable-pip-version-check",
"--no-cache-dir",
Expand Down
30 changes: 18 additions & 12 deletions src/promptflow/promptflow/_utils/version_hint_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
import logging

from promptflow._constants import (
LAST_HINT_TIME,
LAST_CHECK_TIME,
PF_VERSION_CHECK,
CLI_PACKAGE_NAME,
HINT_INTERVAL_DAY,
CURRENT_VERSION,
GET_PYPI_INTERVAL_DAY,
HINT_INTERVAL_DAY,
LAST_CHECK_TIME,
LAST_HINT_TIME,
LATEST_VERSION,
CURRENT_VERSION,
PF_VERSION_CHECK,
)
from promptflow._sdk._constants import HOME_PROMPT_FLOW_DIR


HINT_ACTIVITY_NAME = [
"pf.flows.test",
"pf.runs.create_or_update",
Expand All @@ -44,20 +43,26 @@ def dump_cached_versions(cached_versions):
json.dump(cached_versions, f)


def get_latest_version_from_pypi(package_name):
pypi_url = f"https://pypi.org/pypi/{package_name}/json"
def get_latest_version(package_name, installer="PIP"):
if installer == "MSI":
url = "https://promptflowartifact.blob.core.windows.net/msi-installer/latest_version.json"
else:
url = f"https://pypi.org/pypi/{package_name}/json"
try:
import requests

response = requests.get(pypi_url, timeout=3)
response = requests.get(url, timeout=3)
if response.status_code == 200:
data = response.json()
latest_version = data["info"]["version"]
if installer == "MSI":
latest_version = data[package_name]
else:
latest_version = data["info"]["version"]
return latest_version
else:
return None
except Exception as ex: # pylint: disable=broad-except
logger.debug(f"Failed to get the latest version from '{pypi_url}'. {str(ex)}")
logger.debug(f"Failed to get the latest version from '{url}'. {str(ex)}")
return None


Expand All @@ -73,7 +78,8 @@ def check_latest_version():
if last_check_time is None or (
datetime.datetime.now() > last_check_time + datetime.timedelta(days=GET_PYPI_INTERVAL_DAY)
):
version = get_latest_version_from_pypi(CLI_PACKAGE_NAME)
# For hint, we can't know pfazure installed way for now, so we only check the latest version from pypi.
version = get_latest_version(CLI_PACKAGE_NAME)
if version is not None:
cached_versions[LATEST_VERSION] = version
cached_versions[LAST_CHECK_TIME] = str(datetime.datetime.now())
Expand Down
Loading