From 8eb2a7c2d6c2b4d60c5c7174411cbd4716edd633 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} | 37 +++++++++++++++------ setup.py | 8 ++--- 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 +- 6 files changed, 44 insertions(+), 26 deletions(-) rename .github/workflows/{cd.yaml => release.yaml} (54%) diff --git a/.github/workflows/cd.yaml b/.github/workflows/release.yaml similarity index 54% rename from .github/workflows/cd.yaml rename to .github/workflows/release.yaml index c679c88..f20fb06 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/release.yaml @@ -1,19 +1,13 @@ -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: + Release: runs-on: ubuntu-latest steps: - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." @@ -27,6 +21,29 @@ jobs: 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${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${RELEASE_VERSION}', + name: 'Release v${RELEASE_VERSION}', + generate_release_notes: true + }) - name: 📦 Package run: devbox run build - name: 🚀 Publish to PyPI 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"