Skip to content

Commit

Permalink
Merge pull request #25 from tawanda-kembo/ci/streamline-release-process
Browse files Browse the repository at this point in the history
ci: improve versioning and PyPI deployment process
  • Loading branch information
tawandakembo authored Jul 27, 2024
2 parents 6a686f8 + 90d289d commit 2108d86
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/tag-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
jobs:
tag-and-release:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.bump_version.outputs.NEW_VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -76,9 +78,8 @@ jobs:
python -m pip install --upgrade pip
pip install build
- name: Build package
env:
PACKAGE_VERSION: ${{ needs.tag-and-release.outputs.new_version }}
run: python -m build
- name: Publish package
uses: pypa/[email protected]
# with:
# user: ${{ secrets.PYPI_PASSWORD }}
# password: ${{ secrets.PYPI_PASSWORD }}
uses: pypa/[email protected]
23 changes: 17 additions & 6 deletions code_collator/collate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def setup_logging():
force=True
)


def is_binary_file(filepath):
"""Check if a file is binary."""
try:
Expand All @@ -22,6 +23,7 @@ def is_binary_file(filepath):
logging.error("Error reading file %s: %s", filepath, e)
return False


def read_gitignore(path):
"""Read the .gitignore file and return patterns to ignore."""
gitignore_path = os.path.join(path, '.gitignore')
Expand All @@ -45,6 +47,7 @@ def should_ignore(file_path, ignore_patterns):
return True
return any(fnmatch(file_path, pattern) for pattern in ignore_patterns)


def collate_codebase(path, output_file):
"""Aggregate the codebase into a single Markdown file."""
ignore_patterns = read_gitignore(path)
Expand All @@ -57,7 +60,7 @@ def collate_codebase(path, output_file):
if should_ignore(file_path, ignore_patterns):
logging.info("Ignored file %s", file_path)
continue

output.write(f"## {file_path}\n\n")
is_binary = is_binary_file(file_path)
logging.info("File %s is binary: %s", file_path, is_binary)
Expand All @@ -76,19 +79,27 @@ def collate_codebase(path, output_file):
logging.info("Collated codebase written to %s", output_file)
except Exception as e:
logging.error("Error writing to output file %s: %s", output_file, e)



def main():
"""Parse arguments and initiate codebase collation."""
setup_logging()
parser = argparse.ArgumentParser(description="Aggregate codebase into a single Markdown file.")
parser.add_argument('-p', '--path', type=str, default='.', help="Specify the path to the codebase directory (default: current directory)")
parser.add_argument('-o', '--output', type=str, default='collated-code.md', help="Specify output file (default: collated-code.md)")

parser.add_argument(
'-p',
'--path',
type=str,
default='.',
help="Specify the path to the codebase directory (default: current directory)")
parser.add_argument('-o', '--output', type=str, default='collated-code.md',
help="Specify output file (default: collated-code.md)")

args = parser.parse_args()

logging.info("Starting code collation for directory: %s", args.path)
collate_codebase(args.path, args.output)
logging.info("Code collation completed.")


if __name__ == "__main__":
main()
9 changes: 3 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from setuptools import setup, find_packages
import pathlib
import subprocess
import os

here = pathlib.Path(__file__).parent.resolve()

def get_version():
try:
version = subprocess.check_output(['git', 'describe', '--tags', '--always']).decode().strip()
return version.lstrip('v')
except subprocess.CalledProcessError:
return '0.0.0'
version = os.environ.get('PACKAGE_VERSION', '0.0.0')
return version

setup(
name="code-collator",
Expand Down

0 comments on commit 2108d86

Please sign in to comment.