-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Get latest release | ||
description: Gets the latest (non-prerelease) version of a PyPI package. | ||
inputs: | ||
package: | ||
description: Name of the the package. | ||
required: true | ||
outputs: | ||
latest_version: | ||
description: Latest version of the package. | ||
value: ${{ steps.get-latest.outputs.VERSION }} | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Install packaging | ||
run: pip install packaging requests | ||
shell: bash | ||
|
||
- name: Get latest version | ||
id: get-latest | ||
run: ./.github/actions/get-latest-release/get_latest_release.py ${{ inputs.package }} >> "$GITHUB_OUTPUT" | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
|
||
import requests | ||
from packaging.version import parse as parse_version | ||
|
||
if __name__ == "__main__": | ||
arg_parser = argparse.ArgumentParser( | ||
description="Get the latest non-prerelease version of a package according to PEP440." | ||
) | ||
arg_parser.add_argument("package") | ||
args = arg_parser.parse_args() | ||
|
||
r = requests.get( | ||
f"https://pypi.org/simple/{args.package}", | ||
headers={"Accept": "application/vnd.pypi.simple.v1+json"}, | ||
timeout=30, | ||
) | ||
r.raise_for_status() | ||
versions = [parse_version(v) for v in r.json().get("versions", [])] | ||
latest = max(v for v in versions if not v.is_prerelease) | ||
if latest: | ||
print(f"VERSION={latest}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters