Skip to content

Commit

Permalink
[ci] Update script to fetch Nightly version for examples run (#2040)
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 authored Nov 5, 2024
1 parent 89a667a commit e2defad
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 32 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/dotnet-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ jobs:
if: matrix.release == 'nightly' && matrix.os != 'windows'
run:
|
latest_nightly=$(./scripts/latest-nightly-version.sh nuget Selenium.WebDriver)
pip install -r ./scripts/requirements.txt
latest_nightly=$(python ./scripts/latest-nightly-version.py nuget Selenium.WebDriver)
echo $latest_nightly
dotnet add examples/dotnet/SeleniumDocs/SeleniumDocs.csproj package Selenium.WebDriver --version $latest_nightly
dotnet add examples/dotnet/SeleniumDocs/SeleniumDocs.csproj package Selenium.Support --version $latest_nightly
env:
Expand All @@ -71,7 +73,8 @@ jobs:
shell: pwsh
run:
|
$latest_nightly = ./scripts/latest-nightly-version.ps1 nuget Selenium.WebDriver
pip install -r ./scripts/requirements.txt
$latest_nightly = python ./scripts/latest-nightly-version.py nuget Selenium.WebDriver
dotnet add examples/dotnet/SeleniumDocs/SeleniumDocs.csproj package Selenium.WebDriver --version $latest_nightly
dotnet add examples/dotnet/SeleniumDocs/SeleniumDocs.csproj package Selenium.Support --version $latest_nightly
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/java-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 11
java-version: 17
- name: Run Tests Stable
if: matrix.release == 'stable'
uses: nick-invision/[email protected]
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/js-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ jobs:
if: matrix.release == 'nightly' && matrix.os != 'windows'
run:
|
latest_nightly=$(./scripts/latest-nightly-version.sh npm selenium-webdriver)
pip install -r ./scripts/requirements.txt
latest_nightly=$(python ./scripts/latest-nightly-version.py npm selenium-webdriver)
echo $latest_nightly
npm install --prefix ./examples/javascript --save selenium-webdriver@npm:@seleniumhq/selenium-webdriver@$latest_nightly
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -102,7 +104,8 @@ jobs:
if: matrix.release == 'nightly' && matrix.os == 'windows'
run:
|
$latest_nightly = ./scripts/latest-nightly-version.ps1 npm selenium-webdriver
pip install -r ./scripts/requirements.txt
$latest_nightly = python ./scripts/latest-nightly-version.py npm selenium-webdriver
npm install --prefix ./examples/javascript --save selenium-webdriver@npm:@seleniumhq/selenium-webdriver@$latest_nightly
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
19 changes: 15 additions & 4 deletions .github/workflows/python-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,24 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies nightly
if: matrix.release == 'nightly'
working-directory: ./examples/python
- name: Install dependencies nightly non-Windows
if: matrix.release == 'nightly' && matrix.os != 'windows'
run: |
pip install -r ./scripts/requirements.txt
latest_nightly_python=$(python ./scripts/latest-python-nightly-version.py)
cd examples/python
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install --index-url https://test.pypi.org/simple/ selenium==$latest_nightly_python --extra-index-url https://pypi.org/simple/ --upgrade --force-reinstall --break-system-packages
- name: Install dependencies nightly Windows
if: matrix.release == 'nightly' && matrix.os == 'windows'
run: |
pip install -r ./scripts/requirements.txt
$latest_nightly_python = python ./scripts/latest-python-nightly-version.py
cd examples/python
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple --force-reinstall -v selenium
pip install --index-url https://test.pypi.org/simple/ selenium==$latest_nightly_python --extra-index-url https://pypi.org/simple/ --upgrade --force-reinstall --break-system-packages
- name: Install dependencies stable
if: matrix.release == 'stable'
working-directory: ./examples/python
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/ruby-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ jobs:
if: matrix.release == 'nightly' && matrix.os != 'windows'
run:
|
latest_nightly_webdriver=$(./scripts/latest-nightly-version.sh rubygems selenium-webdriver)
pip install -r ./scripts/requirements.txt
latest_nightly_webdriver=$(python ./scripts/latest-nightly-version.py rubygems selenium-webdriver)
echo $latest_nightly_webdriver
cd examples/ruby
bundle install
bundle remove selenium-webdriver
Expand All @@ -64,7 +66,8 @@ jobs:
if: matrix.release == 'nightly' && matrix.os == 'windows'
run:
|
$latest_nightly_webdriver = ./scripts/latest-nightly-version.ps1 rubygems selenium-webdriver
pip install -r ./scripts/requirements.txt
$latest_nightly_webdriver = python ./scripts/latest-nightly-version.py rubygems selenium-webdriver
cd examples/ruby
bundle install
bundle remove selenium-webdriver
Expand Down
9 changes: 0 additions & 9 deletions scripts/latest-nightly-version.ps1

This file was deleted.

31 changes: 31 additions & 0 deletions scripts/latest-nightly-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import subprocess
import json
import argparse

def get_latest_nightly_version(package_type, package_name):
path_packages_api = f"orgs/seleniumhq/packages/{package_type}/{package_name}/versions"
accept_header = "Accept: application/vnd.github+json"
version_header = "X-GitHub-Api-Version: 2022-11-28"

gh_api_command = [
"gh", "api", "-H", accept_header, "-H", version_header, path_packages_api
]

result = subprocess.run(gh_api_command, capture_output=True, text=True)
if result.returncode != 0:
raise Exception(f"Error executing gh api command: {result.stderr}")

versions = json.loads(result.stdout)
latest_version = versions[0]['name']
return latest_version

if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Get the latest nightly version of a package.')
parser.add_argument('package_type', type=str, help='The type of the package')
parser.add_argument('package_name', type=str, help='The name of the package')

args = parser.parse_args()
package_type = args.package_type
package_name = args.package_name

print(get_latest_nightly_version(package_type, package_name))
12 changes: 0 additions & 12 deletions scripts/latest-nightly-version.sh

This file was deleted.

12 changes: 12 additions & 0 deletions scripts/latest-python-nightly-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import requests
import json
import re

response = requests.get("https://test.pypi.org/pypi/selenium/json")
data = response.json()

versions = data['releases'].keys()
sorted_versions = sorted(versions, key=lambda s: [int(part) if part.isdigit() else part for part in re.split(r'(\d+)', s)])
latest_version = sorted_versions[-1]

print(latest_version)
1 change: 1 addition & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests

0 comments on commit e2defad

Please sign in to comment.