diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml deleted file mode 100644 index c679c88..0000000 --- a/.github/workflows/cd.yaml +++ /dev/null @@ -1,37 +0,0 @@ -name: CD Pipeline -run-name: CD 📦🚀 - -on: - workflow_run: - workflows: ["CI Pipeline"] - types: [completed] - branches: - - "main" - paths: - - "src/**" - - "requirements.txt" - - "LICENSE" - -jobs: - CD: - runs-on: ubuntu-latest - steps: - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code - uses: actions/checkout@v4 - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: Installing Devbox ⚙️ - uses: jetpack-io/devbox-install-action@v0.8.0 - - name: Install all dependencies 📦 - run: devbox run install - - name: 📦 Package - run: devbox run build - - name: 🚀 Publish to PyPI - run: devbox run publish - env: - TWINE_USERNAME: "__token__" - TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} - - run: echo "🍏 This job's status is ${{ job.status }}." diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..ae2aac3 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,56 @@ +name: Release Pipeline +run-name: Release 📦🚀 + +on: + workflow_dispatch: + branches: + - "main" + +jobs: + Release: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: Installing Devbox ⚙️ + uses: jetpack-io/devbox-install-action@v0.8.0 + - name: Install all dependencies 📦 + run: devbox run install + - name: Release Version + run: export RELEASE_VERSION="0.1.$(date +%s)" && echo "🏷️ Tag name is ${RELEASE_VERSION}" + - name: Create Tag + uses: actions/github-script@v7 + with: + script: | + github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: 'refs/tags/v${{ env.RELEASE_VERSION }}', + sha: context.sha + }) + - name: Create Release + uses: actions/github-script@v7 + with: + script: | + github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: 'v${{ env.RELEASE_VERSION }}', + name: 'Release v${{ env.RELEASE_VERSION }}', + generate_release_notes: true + }) + - name: 📦 Package + env: + RELEASE_VERSION: ${{ env.RELEASE_VERSION }} + run: devbox run build +# - name: 🚀 Publish to PyPI +# run: devbox run publish +# env: +# TWINE_USERNAME: "__token__" +# TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} + - run: echo "🍏 This job's status is ${{ job.status }}." diff --git a/setup.py b/setup.py index cb9dab1..87f8b1e 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,9 @@ +import os from typing import List from setuptools import setup, find_packages -import calendar -import time -gmt = time.gmtime() -ts = calendar.timegm(gmt) +version = os.environ.get("RELEASE_VERSION") with open("README.md", "r") as fh: long_description = fh.read() @@ -27,7 +25,7 @@ setup( name="yaml-to-markdown", - version=f"0.1.{ts}", + version=version, description="Converts a YAML/JSON file or python Dict/List to a Markdown file", packages=find_packages(where="src"), package_dir={"": "src"}, diff --git a/src/yaml_to_markdown/convert.py b/src/yaml_to_markdown/convert.py index 238f886..5fbffd7 100644 --- a/src/yaml_to_markdown/convert.py +++ b/src/yaml_to_markdown/convert.py @@ -50,21 +50,26 @@ def main( json_file: Optional[str], show_help: bool, ) -> None: - if show_help or (yaml_file is None and json_file is None) or output_file is None: + if show_help: _help() return + _verify_inputs(output_file=output_file, yaml_file=yaml_file, json_file=json_file) convert(output_file=output_file, yaml_file=yaml_file, json_file=json_file) +def _verify_inputs( + output_file: str, yaml_file: Optional[str], json_file: Optional[str] +) -> None: + if (yaml_file is None and json_file is None) or output_file is None: + _help() + exit(1) + + def convert( output_file: str, yaml_file: Optional[str] = None, json_file: Optional[str] = None ) -> None: - if yaml_file is None and json_file is None or output_file is None: - _help() - raise RuntimeError( - "One of yaml_file or json_file is required along with output_file" - ) + _verify_inputs(output_file=output_file, yaml_file=yaml_file, json_file=json_file) data = _get_json_data(json_file) if json_file else _get_yaml_data(yaml_file) with io.open(output_file, "w", encoding="utf-8") as md_file: diff --git a/src/yaml_to_markdown/convert_test.py b/src/yaml_to_markdown/convert_test.py index 895a809..e49e9a5 100644 --- a/src/yaml_to_markdown/convert_test.py +++ b/src/yaml_to_markdown/convert_test.py @@ -11,9 +11,7 @@ def test_convert_with_no_file() -> None: # Execute - with pytest.raises( - RuntimeError, match="One of yaml_file or json_file is required." - ): + with pytest.raises(SystemExit): convert(output_file="some.md") diff --git a/src/yaml_to_markdown/md_converter.py b/src/yaml_to_markdown/md_converter.py index 5fc81d3..74a99fe 100644 --- a/src/yaml_to_markdown/md_converter.py +++ b/src/yaml_to_markdown/md_converter.py @@ -30,7 +30,7 @@ def set_custom_section_processors( custom_processors: Dict[ str, Callable[[MDConverter, Optional[str], Any, int], str] ], - ): + ) -> None: """ Set custom section processors, the key must match a section name/key and the processor must take 4 arguments and return a Markdown string: diff --git a/src/yaml_to_markdown/utils_test.py b/src/yaml_to_markdown/utils_test.py index d0d967f..e9c1008 100644 --- a/src/yaml_to_markdown/utils_test.py +++ b/src/yaml_to_markdown/utils_test.py @@ -2,5 +2,5 @@ class TestUtils: - def test_convert_to_title_case(self): + def test_convert_to_title_case(self) -> None: assert convert_to_title_case("test-case") == "Test Case"