Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 85 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
deploy:

runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v7
Expand Down Expand Up @@ -55,12 +57,24 @@ jobs:
raise SystemExit("Could not find __version__")
PY
)"
latest_pypi_version="$(uv run python - <<'PY'
pypi_version_exists="$(CURRENT_VERSION="$current_version" uv run python - <<'PY'
import json
import os
import urllib.request
import urllib.error

with urllib.request.urlopen("https://pypi.org/pypi/leet2git/json", timeout=20) as response:
print(json.load(response)["info"]["version"])
current_version = os.environ["CURRENT_VERSION"]
url = f"https://pypi.org/pypi/leet2git/{current_version}/json"
try:
with urllib.request.urlopen(url, timeout=20) as response:
json.load(response)
except urllib.error.HTTPError as e:
if e.code == 404:
print("false")
else:
raise
else:
print("true")
PY
)"

Expand All @@ -69,7 +83,7 @@ jobs:
if [ "$NEW_TAG_VERSION" != "$TAG_VERSION" ]; then
release_version="$NEW_TAG_VERSION"
release_reason="tag"
elif [ "$current_version" != "$latest_pypi_version" ]; then
elif [ "$pypi_version_exists" != "true" ]; then
release_reason="package-version"
fi

Expand All @@ -79,13 +93,13 @@ jobs:
fi

echo "current_version=$current_version" >> "$GITHUB_OUTPUT"
echo "latest_pypi_version=$latest_pypi_version" >> "$GITHUB_OUTPUT"
echo "pypi_version_exists=$pypi_version_exists" >> "$GITHUB_OUTPUT"
echo "version=$release_version" >> "$GITHUB_OUTPUT"
echo "reason=$release_reason" >> "$GITHUB_OUTPUT"
echo "should_release=$should_release" >> "$GITHUB_OUTPUT"

echo "Current version: $current_version"
echo "Latest PyPI version: $latest_pypi_version"
echo "Current version exists on PyPI: $pypi_version_exists"
echo "Release version: $release_version"
echo "Release reason: $release_reason"
- name: Update app version
Expand Down Expand Up @@ -122,3 +136,68 @@ jobs:
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
- name: Verify PyPI release
if: ${{ steps.release_version.outputs.should_release == 'true' }}
env:
RELEASE_VERSION: ${{ steps.release_version.outputs.version }}
run: |
uv run python - <<'PY'
import json
import os
import time
import urllib.request

release_version = os.environ["RELEASE_VERSION"]
url = f"https://pypi.org/pypi/leet2git/{release_version}/json"

for _ in range(12):
try:
with urllib.request.urlopen(url, timeout=20) as response:
payload = json.load(response)
except Exception:
time.sleep(5)
continue
if payload["info"]["version"] == release_version:
print(f"Verified leet2git {release_version} on PyPI")
break
time.sleep(5)
else:
raise SystemExit(f"Could not verify leet2git {release_version} on PyPI")
PY
- name: Create GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_VERSION: ${{ steps.release_version.outputs.version }}
run: |
tag="v$RELEASE_VERSION"
if ! uv run python - <<'PY'
import json
import os
import urllib.error
import urllib.request

release_version = os.environ["RELEASE_VERSION"]
url = f"https://pypi.org/pypi/leet2git/{release_version}/json"
try:
with urllib.request.urlopen(url, timeout=20) as response:
json.load(response)
except urllib.error.HTTPError as e:
if e.code == 404:
raise SystemExit(1)
raise
PY
then
echo "leet2git $RELEASE_VERSION is not on PyPI yet; skipping GitHub release"
exit 0
fi

if gh release view "$tag" >/dev/null 2>&1; then
echo "Release $tag already exists"
else
if ! git ls-remote --exit-code --tags origin "refs/tags/$tag" >/dev/null 2>&1; then
git tag "$tag"
git push origin "$tag"
fi
gh release create "$tag" --title "$tag" --generate-notes
fi
71 changes: 0 additions & 71 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
[![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
[![Code style: Ruff](https://img.shields.io/badge/code%20style-ruff-46a2f1.svg)](https://docs.astral.sh/ruff/)
[![Linting: Ruff & ty](https://img.shields.io/badge/linting-ruff%20%26%20ty-green)](https://docs.astral.sh/)
[![Stable Version](https://img.shields.io/github/v/tag/yurirocha15/leetcode2github)](https://img.shields.io/github/v/tag/yurirocha15/leetcode2github)
[![Latest Release](https://img.shields.io/github/v/release/yurirocha15/leetcode2github?color=%233D9970)](https://img.shields.io/github/v/release/yurirocha15/leetcode2github?color=%233D9970)
[![Stable Version](https://img.shields.io/github/v/tag/yurirocha15/leetcode2github)](https://github.com/yurirocha15/leetcode2github/tags)
[![Latest Release](https://img.shields.io/github/v/release/yurirocha15/leetcode2github?color=%233D9970)](https://github.com/yurirocha15/leetcode2github/releases/latest)
[![Pypi Version](https://img.shields.io/pypi/v/leet2git)](https://pypi.org/project/leet2git/)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg)](#contributors-)
Expand Down