Skip to content

Commit

Permalink
Merge branch 'main' into refactor-submit-results
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarbuzzi authored Dec 12, 2024
2 parents 87e58c7 + 51ad2f8 commit 6544123
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 21 deletions.
35 changes: 23 additions & 12 deletions actions/get-pypi-latest-versions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
required: true
num_of_latest:
description: number of latest versions
default: 1
default: '1'

outputs:
versions:
Expand All @@ -22,15 +22,26 @@ runs:
id: getpypi
shell: bash
run: |-
URL="https://pypi.org/project/${{ inputs.package_name }}/#history"
curl --header 'Accept: application/vnd.pypi.simple.v1+json' ${URL} > history.log
all=`cat history.log | grep 'release__card' | sed 's/.*project\///g' | cut -d'/' -f2`
latest=${{ inputs.num_of_latest }}
if [[ -z "${{ inputs.num_of_latest }}" ]]; then
latest=1
fi
versions=`echo "${all}" | head -${latest} | tr '\n' ';'`
echo "versions=${versions}" >> "$GITHUB_OUTPUT"
if [ -z "${versions}" ]; then
exit 1
echo "::group::get-pypi-latest-versions - preparing virtual environment"
VENV_NAME="venv-pypi-versions"
python -m venv "$VENV_NAME"
source "$VENV_NAME/bin/activate"
pip install requests rss-parser
echo "::endgroup::"
echo "get-pypi-latest-versions - getting latest '$NUM_VERSIONS' version(s) of '$PACKAGE_NAME'"
versions=$(python "$ACTION_PATH/get-versions.py" "$PACKAGE_NAME" --num_versions "$NUM_VERSIONS")
echo "... result: $versions"
echo "get-pypi-latest-versions - cleaning up virtual environment"
rm -r "$VENV_NAME"
if [ -z "$versions" ]; then
exit 1
fi
echo "versions=$versions" >> $GITHUB_OUTPUT
env:
PACKAGE_NAME: ${{ inputs.package_name }}
NUM_VERSIONS: ${{ inputs.num_of_latest }}
ACTION_PATH: ${{ github.action_path }}
48 changes: 48 additions & 0 deletions actions/get-pypi-latest-versions/get-versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import argparse # noqa: INP001
from dataclasses import dataclass
from functools import cached_property

import requests
from rss_parser import RSSParser

DEFAULT_NUM_VERSIONS = 1


@dataclass
class Config:
package_name: str
num_versions: int


def parse_args() -> Config:
parser = argparse.ArgumentParser()
parser.add_argument("package_name", type=str)
parser.add_argument(
"-n",
"--num_versions",
type=int,
default=DEFAULT_NUM_VERSIONS,
dest="num_versions",
)
args = parser.parse_args()
return Config(args.package_name, args.num_versions)


class PackageVersionFeed:
def __init__(self, package: str) -> None:
self.feed_url = f"https://pypi.org/rss/project/{package}/releases.xml"
response = requests.get(self.feed_url, timeout=30)
self.feed = RSSParser.parse(response.text)

@cached_property
def versions(self) -> list[str]:
_versions: list[str] = []
for item in self.feed.channel.items:
_versions.append(str(item.title.content))
return _versions


if __name__ == "__main__":
config = parse_args()
pvf = PackageVersionFeed(config.package_name)
print(";".join(pvf.versions[: config.num_versions])) # noqa: T201
25 changes: 16 additions & 9 deletions actions/install-whl/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ runs:
using: composite
steps:
- id: install_whl
env:
VENV: ${{ inputs.venv }}
NAME: ${{ inputs.name }}
EXTRA: ${{ inputs.extra }}
run: |
source ${{ inputs.venv }}/bin/activate
python --version
WHL=$(find . -type f -iname "${{ inputs.name }}*.whl")
if [ ! -z "${{ inputs.extra }}" ]; then
pip install ${WHL}${{ inputs.extra }}
else
pip install ${WHL}
source "$VENV/bin/activate"
whl=$(find . -type f -iname "$NAME*.whl")
if [ -n "$EXTRA" ]; then
whl="$whl$EXTRA"
fi
version=$(pip freeze | grep "${{ inputs.name }}")
echo "installed ${version}"
echo "::group::pip install $whl"
pip install "$whl"
version=$(pip freeze | grep "$NAME")
echo "installed $version"
echo "::endgroup::"
shell: bash

0 comments on commit 6544123

Please sign in to comment.