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

[ci] Get latest Nightly from TestPyPi sort by upload_time #2064

Merged
merged 1 commit into from
Nov 18, 2024
Merged

Conversation

VietND96
Copy link
Member

@VietND96 VietND96 commented Nov 18, 2024

User description

Thanks for contributing to the Selenium site and documentation!
A PR well described will help maintainers to review and merge it quickly

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, and help reviewers by making them as simple and short as possible.

Description

In case latest release is not on the first index of release history
image

Get latest Nightly from TestPyPi via JSON attr upload_time instead of release name

Motivation and Context

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • Code example added (and I also added the example to all translated languages)
  • Improved translation
  • Added new translation (and I also added a notice to each document missing translation)

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

PR Type

enhancement


Description

  • Enhanced the script to fetch the latest nightly version from TestPyPi by sorting based on the upload_time attribute instead of the version name.
  • Removed the use of regex for sorting version names, simplifying the logic.
  • Improved accuracy in determining the latest version by directly using the upload time.

Changes walkthrough 📝

Relevant files
Enhancement
latest-python-nightly-version.py
Sort and retrieve latest version by upload time                   

scripts/latest-python-nightly-version.py

  • Removed sorting by version name using regex.
  • Added sorting by upload time using JSON attribute.
  • Extracted versions and their upload times from JSON data.
  • Updated logic to determine the latest version.
  • +4/-4     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling
    The script lacks error handling for HTTP requests and JSON parsing. Network issues or invalid JSON responses could cause crashes.

    Data Validation
    No validation is performed on the JSON data structure or the presence of required fields like upload_time in the version data

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add error handling for HTTP request failures and invalid responses

    Add error handling for the HTTP request to handle potential network issues or
    invalid responses.

    scripts/latest-python-nightly-version.py [4-5]

     response = requests.get("https://test.pypi.org/pypi/selenium/json")
    +response.raise_for_status()
     data = response.json()
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: Adding raise_for_status() is essential for catching HTTP errors before attempting to process the response. This prevents silent failures and provides clear error messages for network issues.

    9
    Add defensive programming to handle edge cases when processing version data from the API

    Add error handling for the case when the response from TestPyPi is empty or has no
    releases, or when the first version has no upload timestamps.

    scripts/latest-python-nightly-version.py [8-10]

     versions = data['releases']
    +if not versions:
    +    raise ValueError("No releases found in TestPyPi response")
     sorted_versions = sorted(versions.items(), key=lambda item: item[1][0]['upload_time'], reverse=True)
    +if not sorted_versions:
    +    raise ValueError("No valid versions with upload timestamps found")
     latest_version = sorted_versions[0][0]
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion adds crucial error handling for empty or invalid responses, which could prevent runtime errors in production. This is particularly important for API interactions where response content cannot be guaranteed.

    8
    Possible bug
    Handle missing dictionary keys safely to prevent KeyError exceptions

    Wrap the key access to upload_time in a try-except block as some versions might not
    have this field.

    scripts/latest-python-nightly-version.py [9]

    -sorted_versions = sorted(versions.items(), key=lambda item: item[1][0]['upload_time'], reverse=True)
    +sorted_versions = sorted(versions.items(), key=lambda item: item[1][0].get('upload_time', ''), reverse=True)
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using dict.get() with a default value is a robust way to handle potential missing 'upload_time' keys, preventing KeyError exceptions that could crash the script.

    7

    💡 Need additional feedback ? start a PR chat

    Copy link

    netlify bot commented Nov 18, 2024

    Deploy Preview for selenium-dev ready!

    Name Link
    🔨 Latest commit e524b4a
    🔍 Latest deploy log https://app.netlify.com/sites/selenium-dev/deploys/673ae843b1ff1c0008567e0c
    😎 Deploy Preview https://deploy-preview-2064--selenium-dev.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    @VietND96 VietND96 merged commit 0e011c5 into trunk Nov 18, 2024
    6 checks passed
    @VietND96 VietND96 deleted the py-nightly branch November 18, 2024 07:16
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant