Skip to content

Commit 497ba95

Browse files
committed
switch latest_versions from bash to python
1 parent 67c006e commit 497ba95

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ runs:
6060
using: "composite"
6161
steps:
6262

63+
- uses: "actions/setup-python@v2"
64+
6365
- name: Update Package Versions
6466
shell: bash
6567
run: "bash ${{ github.action_path }}/scripts/update_packages.sh \"${{ inputs.package }}\" \"${{ inputs.action_path }}\""
@@ -71,8 +73,6 @@ runs:
7173
shell: bash
7274
run: "[[ \"${{inputs.update_python}}\" == \"true\" ]] && sed -i 's/python_versions:.*/python_versions: [\"3.6\", \"3.7\", \"3.8\", \"3.9\", \"3.10\"] /' \"${{ inputs.action_path }}\""
7375

74-
- uses: "actions/setup-python@v2"
75-
7676
- name: "Install Jinja2"
7777
shell: bash
7878
run: "python -m pip install jinja2 pyyaml"

scripts/latest_versions.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/python3
2+
import os
3+
import sys
4+
import re
5+
import urllib.request
6+
7+
PACKAGE = sys.argv[1]
8+
MAX_VERSIONS = sys.argv[2] if len(sys.argv) > 2 else 10
9+
10+
# Load PyPI website for the package
11+
fp = urllib.request.urlopen(f"https://pypi.org/simple/{PACKAGE}/")
12+
html_string = fp.read().decode("utf8")
13+
fp.close()
14+
15+
# Pick a regex- either include prerelease versions or not
16+
if os.environ.get("INCLUDE_PRERELEASE", False) == 'true':
17+
version_regex = re.compile(r'-(\d+\.\d+\.\d+(a|b|rc)?\d?).+[\.whl|\.tar\.gz]')
18+
versions = [x[0] for x in version_regex.findall(html_string)]
19+
else:
20+
version_regex = re.compile(r'-(\d+\.\d+\.\d+).+[\.whl|\.tar\.gz]')
21+
versions = version_regex.findall(html_string)
22+
23+
unique_versions = list(dict.fromkeys(versions))
24+
25+
for version in unique_versions[-(int(MAX_VERSIONS)):]:
26+
print(version)

scripts/latest_versions.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

scripts/update_packages.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ echo "Package: $PACKAGE"
2424
echo "Action Path: $FILE"
2525
echo "Max Versions: $MAX_VERSIONS"
2626

27-
VERSIONS=$($SCRIPT_DIR/latest_versions.sh $PACKAGE ${MAX_VERSIONS:-10})
28-
LATEST_VERSION=$($SCRIPT_DIR/latest_versions.sh $PACKAGE 1)
27+
VERSIONS=$($SCRIPT_DIR/latest_versions.py $PACKAGE ${MAX_VERSIONS:-10})
28+
LATEST_VERSION=$($SCRIPT_DIR/latest_versions.py $PACKAGE 1)
2929

3030
echo "Found versions: $VERSIONS"
3131
VERSION_STRING=$(echo $VERSIONS | $SCRIPT_DIR/versions_to_yaml.sh -)

scripts/update_readme.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
3-
export PACKAGE_VERSIONS=$($SCRIPT_DIR/latest_versions.sh $PACKAGE ${MAX_VERSIONS:-10})
3+
export PACKAGE_VERSIONS=$($SCRIPT_DIR/latest_versions.py $PACKAGE ${MAX_VERSIONS:-10})
44

55
if [[ -z $1 ]]; then
66
echo "Please provide a file path."

0 commit comments

Comments
 (0)