From 40c1ba6785478ed1e8c9e5d8c50bef0527e44ebf Mon Sep 17 00:00:00 2001 From: Antony Nevis Date: Mon, 8 Apr 2024 21:28:37 +1000 Subject: [PATCH] Create tag and release --- .github/workflows/{cd.yaml => release.yaml} | 35 +++++++++++++++------ src/yaml_to_markdown/convert.py | 17 ++++++---- src/yaml_to_markdown/convert_test.py | 4 +-- src/yaml_to_markdown/md_converter.py | 2 +- src/yaml_to_markdown/utils_test.py | 2 +- 5 files changed, 40 insertions(+), 20 deletions(-) rename .github/workflows/{cd.yaml => release.yaml} (56%) diff --git a/.github/workflows/cd.yaml b/.github/workflows/release.yaml similarity index 56% rename from .github/workflows/cd.yaml rename to .github/workflows/release.yaml index c679c88..2e9802c 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/release.yaml @@ -1,16 +1,10 @@ -name: CD Pipeline -run-name: CD 📦🚀 +name: Release Pipeline +run-name: Release 📦🚀 on: - workflow_run: - workflows: ["CI Pipeline"] - types: [completed] + workflow_dispatch: branches: - "main" - paths: - - "src/**" - - "requirements.txt" - - "LICENSE" jobs: CD: @@ -27,6 +21,29 @@ jobs: uses: jetpack-io/devbox-install-action@v0.8.0 - name: Install all dependencies 📦 run: devbox run install + - name: Tag Name + run: export TAG_NAME="0.1.$(date +%s)" && echo "🏷️ Tag name is $TAG_NAME" + - 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/$TAG_NAME', + 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: '$TAG_NAME', + name: 'Release $TAG_NAME', + generate_release_notes: true + }) - name: 📦 Package run: devbox run build - name: 🚀 Publish to PyPI 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"