Skip to content

Commit

Permalink
add auto-tag gh action (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpmcginty committed Feb 29, 2024
1 parent 6c40d51 commit 86cb5de
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 8 deletions.
41 changes: 33 additions & 8 deletions .github/scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
import json
import subprocess

# Import the version directly if it's part of your package's namespace
# from my_package.version import __version__ as current_version


def get_version_from_file(file_path: str) -> str:
"""Extract version from a Python file."""
version = {}
with open(file_path) as file:
exec(file.read(), version)
return version["__version__"]


def get_last_version() -> str:
"""Return the version number of the last release."""
Expand All @@ -15,7 +26,6 @@ def get_last_version() -> str:
.stdout.decode("utf8")
.strip()
)

return json.loads(json_string)["tagName"]


Expand All @@ -28,21 +38,36 @@ def bump_patch_number(version_number: str) -> str:
def create_new_patch_release():
"""Create a new patch release on GitHub."""
try:
last_version_number = get_last_version()
current_version = get_version_from_file("path/to/your/version.py")
except subprocess.CalledProcessError as err:
if err.stderr.decode("utf8").startswith("HTTP 404:"):
# The project doesn't have any releases yet.
new_version_number = "0.0.1"
else:
raise
raise
else:
new_version_number = bump_patch_number(last_version_number)
new_version_number = bump_patch_number(current_version)

subprocess.run(
["gh", "release", "create", "--generate-notes", new_version_number],
check=True,
)


# def create_new_patch_release():
# """Create a new patch release on GitHub."""
# try:
# last_version_number = get_last_version()
# except subprocess.CalledProcessError as err:
# if err.stderr.decode("utf8").startswith("HTTP 404:"):
# # The project doesn't have any releases yet.
# new_version_number = "0.0.1"
# else:
# raise
# else:
# new_version_number = bump_patch_number(last_version_number)

# subprocess.run(
# ["gh", "release", "create", "--generate-notes", new_version_number],
# check=True,
# )


if __name__ == "__main__":
create_new_patch_release()
64 changes: 64 additions & 0 deletions .github/workflows/auto_tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Auto Tag

on:
# push:
# branches: [ main ]
# paths:
# - 'src/**.py'
# - 'test/**.py'
# - 'Makefile'
# - 'pyproject.toml'
# paths-ignore:
# - '**/__version__.py'

workflow_dispatch:
inputs:
bump_type:
description: 'version bump type'
type: choice
options: ['major', 'minor', 'patch', 'none']
required: false
default: 'patch'

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Set up AllenInstitute Repo Authorization
uses: ./.github/actions/setup-ai-github-urls
with:
token: ${{ secrets.AI_PACKAGES_TOKEN }}
ssh_private_key: ${{ secrets.AIBSGITHUB_PRIVATE_KEY }}
- name: Run Packaging
run: |
make release
shell: bash
tag:
name: Tag and Release
runs-on: ubuntu-latest
needs: build
steps:
- name: Bump patch version and tag
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEFAULT_BUMP: ${{ github.event.inputs.bump_type || 'patch' }}
WITH_V: "true"
RELEASE_BRANCHES: main
DRY_RUN: true




4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ name: Build and Test
on:
pull_request:
branches: [ main ]
paths-ignore:
- '**/_version.py'
push:
branches: [ main ]
paths-ignore:
- '**/_version.py'

jobs:
test:
Expand Down

0 comments on commit 86cb5de

Please sign in to comment.