Skip to content

Commit

Permalink
add action to get pypi package latest versions
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuangnm authored and dhuangnm committed Sep 19, 2024
1 parent 4515269 commit 34c6d43
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions actions/get-pypi-latest-versions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: get package latest versions on PyPi
description: get package latest versions on PyPi

inputs:
package_name:
description: name of the package
required: true
num_of_latest:
description: number of latest versions
default: 1

outputs:
versions:
description: return latest versions of package on PyPi
value: ${{ steps.getpypi.outputs.versions }}

runs:
using: composite
steps:
- id: getpypi
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}`
echo "versions=${versions}" >> "$GITHUB_OUTPUT"
shell: bash

0 comments on commit 34c6d43

Please sign in to comment.