Skip to content

Commit

Permalink
utility to fetch a new branch
Browse files Browse the repository at this point in the history
  • Loading branch information
sayakpaul committed Mar 11, 2024
1 parent 571fb06 commit 72d27bf
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
29 changes: 27 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,43 @@ on:
- "*"

jobs:
find-and-checkout-latest-branch:
runs-on: ubuntu-latest
outputs:
latest_branch: ${{ steps.set_latest_branch.outputs.latest_branch }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8'

- name: Fetch latest branch
id: fetch_latest_branch
run: |
pip install -U requests packaging
LATEST_BRANCH=$(python find_latest_release_branch.py)
echo "Latest branch: $LATEST_BRANCH"
echo "latest_branch=$LATEST_BRANCH" >> $GITHUB_ENV
- name: Set latest branch output
id: set_latest_branch
run: echo "::set-output name=latest_branch::${{ env.latest_branch }}"

release:
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
ref: ${{ github.event.ref }}
ref: ${{ needs.find-and-checkout-latest-branch.outputs.latest_branch }}

- name: Print the commit info
env:
REF: ${{ github.event.ref }}
REF: ${{ needs.find-and-checkout-latest-branch.outputs.latest_branch }}
run: echo "Commit $REF"

- name: Setup Python
Expand Down
52 changes: 52 additions & 0 deletions fetch_latest_release_branch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import requests
from packaging.version import parse

# GitHub repository details
USER = "sayakpaul"
REPO = "blossom"


def fetch_all_branches(user, repo):
branches = [] # List to store all branches
page = 1 # Start from first page
while True:
# Make a request to the GitHub API for the branches
response = requests.get(f"https://api.github.com/repos/{user}/{repo}/branches", params={"page": page})

# Check if the request was successful
if response.status_code == 200:
# Add the branches from the current page to the list
branches.extend([branch["name"] for branch in response.json()])

# Check if there is a 'next' link for pagination
if "next" in response.links:
page += 1 # Move to the next page
else:
break # Exit loop if there is no next page
else:
print("Failed to retrieve branches:", response.status_code)
break

return branches


def main():
# Fetch all branches
branches = fetch_all_branches(USER, REPO)

# Filter branches.
# print(f"Total branches: {len(branches)}")
filtered_branches = []
for branch in branches:
if branch.startswith("v"):
filtered_branches.append(branch)
# print(f"Filtered: {branch}")

sorted_branches = sorted(filtered_branches, key=lambda x: parse(x.split("-")[0][1:]), reverse=True)
latest_branch = sorted_branches[0]
# print(f"Latest branch: {latest_branch}")
return latest_branch


if __name__ == "__main__":
print(main())
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="blossoms_sayak",
version="0.15.0",
version="0.16.0",
description="A simple Python package for math operations and geometry calculations.",
long_description=open("README.md", "r", encoding="utf-8").read(),
long_description_content_type="text/markdown",
Expand Down
2 changes: 1 addition & 1 deletion src/blossoms_sayak/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.15.0"
__version__ = "0.16.0"

from .geometry import circle_area
from .operations import add, subtract, multiply, divide

0 comments on commit 72d27bf

Please sign in to comment.