Skip to content

[ci] Update script to fetch Nightly version for examples run #2040

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

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

VietND96
Copy link
Member

@VietND96 VietND96 commented Nov 4, 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

  • Convert to a Python script for executing in both non-Windows and Windows runners.
  • Fix for Nightly Python examples run.
    • Issue found: If not set explicit version, e.g run pip install -i https://test.pypi.org/simple/ selenium. It installed 4.22 only
    • Fixed: Fetch latest version from TestPypi, then install pypi with that version

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, other


Description

  • Replaced shell and PowerShell scripts with a Python script to fetch the latest nightly version of packages.
  • Updated GitHub workflows for various languages (dotnet, JS, Python, Ruby) to use the new Python script.
  • Added a script to specifically fetch the latest nightly version of the Selenium package from TestPyPI.
  • Updated Java version in the Java workflow from 11 to 17.
  • Introduced a requirements file to manage Python dependencies.

Changes walkthrough 📝

Relevant files
Enhancement
latest-nightly-version.py
Add Python script for fetching latest nightly version       

scripts/latest-nightly-version.py

  • Added a Python script to fetch the latest nightly version of a
    package.
  • Utilizes GitHub API to retrieve package versions.
  • Replaces previous shell and PowerShell scripts for version fetching.
  • +31/-0   
    latest-python-nightly-version.py
    Fetch latest nightly Python version from TestPyPI               

    scripts/latest-python-nightly-version.py

  • Added a script to fetch the latest nightly version of the Selenium
    package from TestPyPI.
  • Parses JSON response to determine the latest version.
  • +12/-0   
    Dependencies
    requirements.txt
    Add requests library to requirements                                         

    scripts/requirements.txt

    • Added requests library as a dependency.
    +1/-0     
    Configuration changes
    dotnet-examples.yml
    Update dotnet workflow to use Python script                           

    .github/workflows/dotnet-examples.yml

  • Updated workflow to use Python script for fetching nightly versions.
  • Added step to install Python dependencies.
  • +5/-2     
    js-examples.yml
    Update JS workflow to use Python script                                   

    .github/workflows/js-examples.yml

  • Updated workflow to use Python script for fetching nightly versions.
  • Added step to install Python dependencies.
  • +5/-2     
    python-examples.yml
    Update Python workflow for nightly version fetching           

    .github/workflows/python-examples.yml

  • Updated workflow to use Python script for fetching nightly versions.
  • Added separate steps for non-Windows and Windows environments.
  • +15/-4   
    ruby-examples.yml
    Update Ruby workflow to use Python script                               

    .github/workflows/ruby-examples.yml

  • Updated workflow to use Python script for fetching nightly versions.
  • Added step to install Python dependencies.
  • +5/-2     
    java-examples.yml
    Update Java version in workflow                                                   

    .github/workflows/java-examples.yml

    • Updated Java version from 11 to 17.
    +1/-1     

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

    Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
    Copy link
    Contributor

    qodo-merge-pro bot commented Nov 5, 2024

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    Potential Security Risk
    The use of '--break-system-packages' flag when installing packages could potentially override system-wide Python packages, which might lead to system instability.

    Error Handling
    The script raises a generic Exception when the GitHub API call fails. Consider using more specific exception types and providing more detailed error messages.

    Error Handling
    The script lacks error handling for potential network issues or invalid responses from the TestPyPI API.

    Copy link
    Contributor

    qodo-merge-pro bot commented Nov 5, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Implement error handling for HTTP requests to improve reliability and provide meaningful error messages

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

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

    -response = requests.get("https://test.pypi.org/pypi/selenium/json")
    -data = response.json()
    +try:
    +    response = requests.get("https://test.pypi.org/pypi/selenium/json")
    +    response.raise_for_status()
    +    data = response.json()
    +except requests.RequestException as e:
    +    print(f"Error fetching data from TestPyPI: {e}")
    +    sys.exit(1)
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: Adding error handling for HTTP requests is crucial for reliability and provides clear error messages, significantly improving the script's stability and maintainability.

    9
    Possible issue
    Add error handling for empty API responses to prevent potential IndexError

    Consider adding error handling for the case when the API response is empty or
    doesn't contain any versions. This will prevent potential IndexError when accessing
    versions[0]['name'].

    scripts/latest-nightly-version.py [18-20]

     versions = json.loads(result.stdout)
    +if not versions:
    +    raise Exception("No versions found for the package")
     latest_version = versions[0]['name']
     return latest_version
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: This suggestion addresses a potential runtime error that could occur if the API response is empty, improving the script's robustness and error handling.

    8
    Enhancement
    Use a dedicated version parsing library for more reliable version comparisons

    Consider using a more robust version parsing library like packaging.version instead
    of the custom sorting function, which may not handle all version string formats
    correctly.

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

    -sorted_versions = sorted(versions, key=lambda s: [int(part) if part.isdigit() else part for part in re.split(r'(\d+)', s)])
    +from packaging import version
    +sorted_versions = sorted(versions, key=version.parse)
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using a dedicated version parsing library like 'packaging.version' ensures more accurate and reliable version comparisons, especially for complex version strings.

    7
    Maintainability
    Standardize the Python script execution syntax across different operating systems in the workflow

    Consider using a consistent approach for executing the Python script across
    different operating systems. Currently, the Windows version uses a different
    variable assignment syntax.

    .github/workflows/python-examples.yml [55-64]

     latest_nightly_python=$(python ./scripts/latest-python-nightly-version.py)
     ...
    -$latest_nightly_python = python ./scripts/latest-python-nightly-version.py
    +latest_nightly_python=$(python ./scripts/latest-python-nightly-version.py)
    Suggestion importance[1-10]: 6

    Why: Standardizing the syntax improves consistency and maintainability of the workflow across different operating systems, reducing potential errors and confusion.

    6

    💡 Need additional feedback ? start a PR chat

    Copy link

    netlify bot commented Nov 5, 2024

    Deploy Preview for selenium-dev ready!

    Name Link
    🔨 Latest commit c42f906
    🔍 Latest deploy log https://app.netlify.com/sites/selenium-dev/deploys/67295ffeb0b7bd0008c6841c
    😎 Deploy Preview https://deploy-preview-2040--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 e2defad into trunk Nov 5, 2024
    10 of 12 checks passed
    @VietND96 VietND96 deleted the nightly-script branch November 5, 2024 00:03
    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