feat: make check action generate unstable commits
This commit is contained in:
parent
b9ce80f179
commit
db08fe9c91
2 changed files with 33 additions and 10 deletions
10
action.yaml
10
action.yaml
|
|
@ -8,11 +8,11 @@ inputs:
|
||||||
pypi-base-url:
|
pypi-base-url:
|
||||||
description: "The PyPI registry URL"
|
description: "The PyPI registry URL"
|
||||||
required: true
|
required: true
|
||||||
override-version:
|
|
||||||
description: "Don't check GitHub for the latest version, use this one"
|
|
||||||
required: false
|
|
||||||
github-repository:
|
github-repository:
|
||||||
description: "The package's GitHub repository name (owner/repo). Required if override-version is unset"
|
description: "The package's GitHub repository name (owner/repo)"
|
||||||
|
required: true
|
||||||
|
unstable-branch:
|
||||||
|
description: "Whether to get a version representing the latest commit on this branch"
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
|
|
@ -32,5 +32,5 @@ runs:
|
||||||
REPOSITORY: ${{ inputs.github-repository }}
|
REPOSITORY: ${{ inputs.github-repository }}
|
||||||
PACKAGE: ${{ inputs.pypi-package }}
|
PACKAGE: ${{ inputs.pypi-package }}
|
||||||
BASE_URL: ${{ inputs.pypi-base-url }}
|
BASE_URL: ${{ inputs.pypi-base-url }}
|
||||||
VERSION: ${{ inputs.override-version }}
|
BRANCH: ${{ inputs.unstable-branch }}
|
||||||
|
|
||||||
|
|
|
||||||
33
check.py
33
check.py
|
|
@ -5,14 +5,39 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
def get_github_version(repository: str) -> str:
|
|
||||||
|
def get_release_version(repository: str) -> str:
|
||||||
try:
|
try:
|
||||||
return requests.get(f"https://api.github.com/repos/{repository}/releases/latest").json()["tag_name"].removeprefix("v")
|
return requests.get(f"https://api.github.com/repos/{repository}/releases/latest").json()["tag_name"].removeprefix("v")
|
||||||
except Exception:
|
except Exception:
|
||||||
return requests.get(f"https://api.github.com/repos/{repository}/tags").json()[0]["name"].removeprefix("v")
|
return requests.get(f"https://api.github.com/repos/{repository}/tags").json()[0]["name"].removeprefix("v")
|
||||||
|
|
||||||
|
|
||||||
|
def get_unstable_version(repository: str, branch: str) -> str:
|
||||||
|
base_url = f"https://api.github.com/repos/{repository}/commits?sha={branch}"
|
||||||
|
|
||||||
|
latest_commit = requests.get(f"{base_url}&per_page=1").json()[0]
|
||||||
|
commit_date = datetime.strptime(latest_commit["commit"]["committer"]["date"], "%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
|
||||||
|
since_iso = commit_date.replace(hour=0, minute=0, second=0, microsecond=0).isoformat().replace("+00:00", "Z")
|
||||||
|
|
||||||
|
commit_count = 0
|
||||||
|
page = 1
|
||||||
|
|
||||||
|
while True:
|
||||||
|
commits = requests.get(f"{base_url}&since={since_iso}&per_page=100&page={page}").json()
|
||||||
|
commit_count += len(commits)
|
||||||
|
|
||||||
|
if len(commits) < 100:
|
||||||
|
break
|
||||||
|
|
||||||
|
page += 1
|
||||||
|
|
||||||
|
return f"{branch}.{commit_date.strftime("%Y%m%d")}.dev{commit_count}"
|
||||||
|
|
||||||
|
|
||||||
def does_pypi_version_exist(base_url: str, package: str, version: str) -> bool:
|
def does_pypi_version_exist(base_url: str, package: str, version: str) -> bool:
|
||||||
base_url = base_url.removesuffix("/")
|
base_url = base_url.removesuffix("/")
|
||||||
version = version.replace(".", "\\.")
|
version = version.replace(".", "\\.")
|
||||||
|
|
@ -24,11 +49,9 @@ def does_pypi_version_exist(base_url: str, package: str, version: str) -> bool:
|
||||||
def main():
|
def main():
|
||||||
package = os.environ["PACKAGE"]
|
package = os.environ["PACKAGE"]
|
||||||
base_url = os.environ["BASE_URL"]
|
base_url = os.environ["BASE_URL"]
|
||||||
|
repository = os.environ["REPOSITORY"]
|
||||||
|
|
||||||
version = os.environ.get(
|
version = get_release_version(repository) if not os.environ.get("BRANCH", False) else get_unstable_version(repository, os.environ["BRANCH"])
|
||||||
"VERSION",
|
|
||||||
get_github_version(os.environ["REPOSITORY"])
|
|
||||||
)
|
|
||||||
|
|
||||||
if does_pypi_version_exist(base_url, package, version):
|
if does_pypi_version_exist(base_url, package, version):
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue