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
58 changes: 55 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,44 @@ jobs:

- name: Run tests
run: pytest tests/ -v

get-next-version:
needs: test
uses: semantic-release-action/next-release-version/.github/workflows/next-release-version.yml@v4

update-version:
needs: get-next-version
runs-on: ubuntu-latest
if: needs.get-next-version.outputs.new-release-published == 'true'
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Update version
run: |
echo "Updating version..."
python scripts/update_version.py --next-version ${{ needs.get-next-version.outputs.new-release-version }}

- name: Upload updated version file
uses: actions/upload-artifact@v4
with:
name: version-file
path: casbin_cli/__version__.py

build-binaries:
needs: test
needs: update-version
if: needs.get-next-version.outputs.new-release-published == 'true'
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -54,6 +89,17 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pyinstaller

- name: Download version file
uses: actions/download-artifact@v4
with:
name: version-file
path: casbin_cli/

- name: Verify file content
run: |
echo "Content of __version__.py after update:"
cat casbin_cli/__version__.py

- name: Build binary
run: python scripts/build_binaries.py --platform ${{ matrix.platform }}
Expand Down Expand Up @@ -85,8 +131,14 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install wheel twine
npm install -g semantic-release @semantic-release/changelog @semantic-release/exec @semantic-release/github

npm install -g semantic-release @semantic-release/changelog @semantic-release/exec @semantic-release/github @semantic-release/git

- name: Download version file
uses: actions/download-artifact@v4
with:
name: version-file
path: casbin_cli/

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
Expand Down
13 changes: 7 additions & 6 deletions .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
"changelogFile": "CHANGELOG.md"
}
],
[
"@semantic-release/exec",
{
"prepareCmd": "python scripts/update_version.py ${nextRelease.version}"
}
],
[
"@semantic-release/git",
{
"assets": ["casbin_cli/__version__.py"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
],
[
"@semantic-release/github",
{
Expand Down
23 changes: 2 additions & 21 deletions casbin_cli/__version__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,2 @@
import subprocess


def get_base_tag():
try:
command = ["git", "describe", "--tags", "--abbrev=0"]

tag = subprocess.check_output(
command, text=True, stderr=subprocess.PIPE
).strip()

if tag.startswith("v"):
return tag[1:]
return tag

except subprocess.CalledProcessError:
print("Error: Failed to find any git tags.")
return None


__version__ = get_base_tag()
__version__ = "1.6.0"
__pycasbin_version__ = "2.3.0"
15 changes: 3 additions & 12 deletions casbin_cli/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from casbin_cli.enforcer_factory import EnforcerFactory
from casbin_cli.utils import process_line_breaks
from casbin_cli.__version__ import __version__
from casbin_cli.__version__ import __pycasbin_version__


class Client:
@staticmethod
Expand All @@ -26,18 +28,7 @@ def run(args=None):
return ""
elif command_name in ['-v', '--version']:
print(f"casbin-python-cli {__version__}")
try:
from importlib.metadata import version

pycasbin_version = version("pycasbin")
except ImportError:
try:
from importlib_metadata import version

pycasbin_version = version("pycasbin")
except (ImportError, Exception):
pycasbin_version = "unknown"
print(f"pycasbin {pycasbin_version}")
print(f"pycasbin {__pycasbin_version__}")
return ""
elif command_name == 'completion':
if len(args) < 2:
Expand Down
38 changes: 20 additions & 18 deletions scripts/update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,33 @@
import sys
import re
import os
import argparse

def update_version(new_version):
def update_version():
"""Update version in all relevant files"""
parser = argparse.ArgumentParser()
parser.add_argument('--next-version', help='next release version(x.x.x)')
args = parser.parse_args()

# Update setup.py
setup_py_path = "setup.py"
with open(setup_py_path, 'r') as f:
content = f.read()

# Update client.py version display
client_py_path = "casbin_cli/client.py"
with open(client_py_path, 'r') as f:
content = f.read()

new_version = args.next_version
try:
from importlib.metadata import version

pycasbin_version = version("pycasbin")
except ImportError:
try:
from importlib_metadata import version

pycasbin_version = version("pycasbin")
except (ImportError, Exception):
pycasbin_version = "unknown"
# Create __version__.py
version_py_path = "casbin_cli/__version__.py"
with open(version_py_path, 'w') as f:
f.write(f'__version__ = "{new_version}"\n')
f.write(f'__pycasbin_version__ = "{pycasbin_version}"\n')

print(f"Updated version to {new_version}")

if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python update_version.py <version>")
sys.exit(1)

new_version = sys.argv[1]
update_version(new_version)
if __name__ == "__main__":
update_version()