From e7ff35b026c9223a2bdb5ffc2a9a635aa8d1c70f Mon Sep 17 00:00:00 2001 From: Jared Hendrickson Date: Sun, 14 Aug 2022 17:32:32 -0600 Subject: [PATCH 1/5] ci: adding staging workflows --- .github/workflows/staging-pages.yml | 46 ++++++++++++++++++++++ .github/workflows/staging-pypi.yml | 42 ++++++++++++++++++++ mail2beyond/__init__.py | 3 ++ scripts/mail2beyond | 2 +- setup.py | 59 +++++++++++++++++++++-------- 5 files changed, 136 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/staging-pages.yml create mode 100644 .github/workflows/staging-pypi.yml diff --git a/.github/workflows/staging-pages.yml b/.github/workflows/staging-pages.yml new file mode 100644 index 0000000..9a7bcc8 --- /dev/null +++ b/.github/workflows/staging-pages.yml @@ -0,0 +1,46 @@ +# Simple workflow for deploying static content to GitHub Pages +name: Documentation + +on: + # Runs on pushes targeting the staging branch + push: + branches: ["staging"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow one concurrent deployment +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + # Single deploy job since we're just deploying + deploy: + environment: + name: staging + url: ${{ steps.deployment.outputs.page_url }}/staging + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Pages + uses: actions/configure-pages@v1 + - name: Build documentation + run: | + python -m pip install --upgrade pip + pip install . + pdoc3 mail2beyond --html --force --output-dir docs/html + - name: Upload artifact + uses: actions/upload-pages-artifact@v1 + with: + path: './docs/html/mail2beyond' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@main diff --git a/.github/workflows/staging-pypi.yml b/.github/workflows/staging-pypi.yml new file mode 100644 index 0000000..5d5f6c6 --- /dev/null +++ b/.github/workflows/staging-pypi.yml @@ -0,0 +1,42 @@ +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Staging PyPI + +on: + pull_request: + branches: [ "master", "staging" ] + +permissions: + contents: read + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Build package + run: | + export __MAIL2BEYOND_REVISION__="${GITHUB_RUN_ID}" + python -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.TEST_PYPI_API_TOKEN }} + repository_url: https://test.pypi.org/legacy/ \ No newline at end of file diff --git a/mail2beyond/__init__.py b/mail2beyond/__init__.py index 7d843df..a20856d 100644 --- a/mail2beyond/__init__.py +++ b/mail2beyond/__init__.py @@ -6,5 +6,8 @@ from . import parsers from . import tools +# Set the version of this package +__version__ = "0.0.1" + # Don't include tests module in generated documentation. __pdoc__ = {"tests": False} diff --git a/scripts/mail2beyond b/scripts/mail2beyond index fdc58c2..ec411d2 100644 --- a/scripts/mail2beyond +++ b/scripts/mail2beyond @@ -89,7 +89,7 @@ class Mail2BeyondCLI: parser.add_argument( '--version', "-V", action='version', - version='%(prog)s v{version}'.format(version=pkg_resources.require("mail2beyond")[0].version) + version='%(prog)s v{version}'.format(version=mail2beyond.__version__) ) parser.add_argument( "--verbose", "--debug", "-v", diff --git a/setup.py b/setup.py index 85beda4..93341d8 100644 --- a/setup.py +++ b/setup.py @@ -1,26 +1,55 @@ """Module used to setup and install the mail2beyond package.""" +import os +import codecs + from setuptools import setup -def read_me(): +def read(rel_path): + """Reads a specified file.""" + here = os.path.abspath(os.path.dirname(__file__)) + with codecs.open(os.path.join(here, rel_path), 'r') as filepath: + return filepath.read() + + +def get_readme(): """Opens the README.md file for this package so it can by used in setup.py.""" # Read the readme file - with open('README.md', encoding="utf-8") as read_me_file: - return read_me_file.read() + return read("README.md") + + +def get_requirements(): + """Opens the requirements.txt file for this package so it can be used in setup.py.""" + reqs = read("requirements.txt").split("\n") + + # Remove empty items if any + while "" in reqs: + reqs.remove("") + + return reqs + +def get_version(rel_path): + """ + Gets the current version of the package. If a __MAIL2BEYOND_REVISION__ environment variable exists, it will + be read and appended to the current package version. This is used to ensure the setup version can always be unique + for PyPI dev builds triggered by CI/CD workflows. + """ + # Variables + revision = "" -def requirements(): - """Opens the requirements.txt file for this package so it can by used in setup.py.""" - with open('requirements.txt', encoding="utf-8") as requirements_file: - # Read the requirements file and split string in list by newline - reqs = requirements_file.read().split("\n") + # If a __MAIL2BEYOND_REVISION__ environment variable exists, set it as the dev revision. + if "__MAIL2BEYOND_REVISION__" in os.environ: + revision = "." + os.environ.get("__MAIL2BEYOND_REVISION__") - # Remove empty items if any - while "" in reqs: - reqs.remove("") + # Otherwise, look for the version in the package. + for line in read(rel_path).splitlines(): + if line.startswith('__version__'): + delim = '"' if '"' in line else "'" + return line.split(delim)[1] + revision - return reqs + raise RuntimeError("Unable to find version string.") setup( @@ -31,12 +60,12 @@ def requirements(): license="MIT", description="A Python based SMTP server package and CLI that redirects incoming SMTP messages to upstream APIs like" " Google Chat, Slack and more!.", - long_description=read_me(), + long_description=get_readme(), long_description_content_type="text/markdown", - version="1.0.0", + version=get_version("mail2beyond/__init__.py"), scripts=['scripts/mail2beyond'], packages=["mail2beyond", "mail2beyond.connectors", "mail2beyond.parsers"], - install_requires=requirements(), + install_requires=get_requirements(), classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", From d4e38da2ff301a725fd14bedac69eb095223a5b8 Mon Sep 17 00:00:00 2001 From: Jared Hendrickson Date: Sun, 14 Aug 2022 17:37:32 -0600 Subject: [PATCH 2/5] ci: fix staging pages url --- .github/workflows/staging-pages.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/staging-pages.yml b/.github/workflows/staging-pages.yml index 9a7bcc8..df79ec7 100644 --- a/.github/workflows/staging-pages.yml +++ b/.github/workflows/staging-pages.yml @@ -1,5 +1,5 @@ # Simple workflow for deploying static content to GitHub Pages -name: Documentation +name: Staging Documentation on: # Runs on pushes targeting the staging branch @@ -25,7 +25,7 @@ jobs: deploy: environment: name: staging - url: ${{ steps.deployment.outputs.page_url }}/staging + url: ${{ steps.deployment.outputs.page_url }}staging/ runs-on: ubuntu-latest steps: - name: Checkout From b4d0b975e726afc16c0aa3169ef1dd6496d4f147 Mon Sep 17 00:00:00 2001 From: Jared Hendrickson Date: Sun, 14 Aug 2022 17:42:45 -0600 Subject: [PATCH 3/5] ci: fix staging pages url --- .github/workflows/staging-pages.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/staging-pages.yml b/.github/workflows/staging-pages.yml index df79ec7..e4542f6 100644 --- a/.github/workflows/staging-pages.yml +++ b/.github/workflows/staging-pages.yml @@ -37,10 +37,11 @@ jobs: python -m pip install --upgrade pip pip install . pdoc3 mail2beyond --html --force --output-dir docs/html + mv ./docs/html/mail2beyond ./docs/html/staging - name: Upload artifact uses: actions/upload-pages-artifact@v1 with: - path: './docs/html/mail2beyond' + path: './docs/html' - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@main From f2a525243300d86d150df0690dae3d2a023dd974 Mon Sep 17 00:00:00 2001 From: Jared Hendrickson Date: Sun, 14 Aug 2022 17:52:52 -0600 Subject: [PATCH 4/5] ci: scrapped staging docuementation --- .../{codeql-analysis.yml => codeql.yml} | 0 .../{pages.yml => documentation.yml} | 0 .github/workflows/staging-pages.yml | 47 ------------------- README.md | 4 +- 4 files changed, 2 insertions(+), 49 deletions(-) rename .github/workflows/{codeql-analysis.yml => codeql.yml} (100%) rename .github/workflows/{pages.yml => documentation.yml} (100%) delete mode 100644 .github/workflows/staging-pages.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql.yml similarity index 100% rename from .github/workflows/codeql-analysis.yml rename to .github/workflows/codeql.yml diff --git a/.github/workflows/pages.yml b/.github/workflows/documentation.yml similarity index 100% rename from .github/workflows/pages.yml rename to .github/workflows/documentation.yml diff --git a/.github/workflows/staging-pages.yml b/.github/workflows/staging-pages.yml deleted file mode 100644 index e4542f6..0000000 --- a/.github/workflows/staging-pages.yml +++ /dev/null @@ -1,47 +0,0 @@ -# Simple workflow for deploying static content to GitHub Pages -name: Staging Documentation - -on: - # Runs on pushes targeting the staging branch - push: - branches: ["staging"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages -permissions: - contents: read - pages: write - id-token: write - -# Allow one concurrent deployment -concurrency: - group: "pages" - cancel-in-progress: true - -jobs: - # Single deploy job since we're just deploying - deploy: - environment: - name: staging - url: ${{ steps.deployment.outputs.page_url }}staging/ - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup Pages - uses: actions/configure-pages@v1 - - name: Build documentation - run: | - python -m pip install --upgrade pip - pip install . - pdoc3 mail2beyond --html --force --output-dir docs/html - mv ./docs/html/mail2beyond ./docs/html/staging - - name: Upload artifact - uses: actions/upload-pages-artifact@v1 - with: - path: './docs/html' - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@main diff --git a/README.md b/README.md index 17f38b2..6fb8f7e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ Mail2Beyond ========= -[![Documentation Build](https://github.com/soluna-studios/mail2beyond/actions/workflows/pages.yml/badge.svg)](https://github.com/soluna-studios/mail2beyond/actions/workflows/pages.yml) +[![Documentation Build](https://github.com/soluna-studios/mail2beyond/actions/workflows/documentation.yml/badge.svg)](https://github.com/soluna-studios/mail2beyond/actions/workflows/documentation.yml) [![Unit Tests](https://github.com/soluna-studios/mail2beyond/actions/workflows/unittest.yml/badge.svg)](https://github.com/soluna-studios/mail2beyond/actions/workflows/unittest.yml) [![PyLint](https://github.com/soluna-studios/mail2beyond/actions/workflows/pylint.yml/badge.svg)](https://github.com/soluna-studios/mail2beyond/actions/workflows/pylint.yml) -[![CodeQL](https://github.com/soluna-studios/mail2beyond/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/soluna-studios/mail2beyond/actions/workflows/codeql-analysis.yml) +[![CodeQL](https://github.com/soluna-studios/mail2beyond/actions/workflows/codeql.yml/badge.svg)](https://github.com/soluna-studios/mail2beyond/actions/workflows/codeql.yml) Mail2Beyond is a Python-based SMTP server designed to redirect incoming SMTP messages to upstream APIs such as Google Chat, Slack, or even your own API! This includes a command line interface (CLI) that can be used to run From 2e6314bf85ef6e093201b5239c74143186aa17d4 Mon Sep 17 00:00:00 2001 From: Jared Hendrickson Date: Sun, 14 Aug 2022 18:14:10 -0600 Subject: [PATCH 5/5] ci: added production pypi deploy workflow --- .github/workflows/pypi.yml | 39 ++++++++++++++++++++++++++++++ .github/workflows/staging-pypi.yml | 8 ------ README.md | 2 +- 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/pypi.yml diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml new file mode 100644 index 0000000..6dedd77 --- /dev/null +++ b/.github/workflows/pypi.yml @@ -0,0 +1,39 @@ +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: PyPI + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Build package + run: python -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/staging-pypi.yml b/.github/workflows/staging-pypi.yml index 5d5f6c6..a6c4d6d 100644 --- a/.github/workflows/staging-pypi.yml +++ b/.github/workflows/staging-pypi.yml @@ -1,11 +1,3 @@ -# This workflow will upload a Python Package using Twine when a release is created -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - name: Staging PyPI on: diff --git a/README.md b/README.md index 6fb8f7e..af254d9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Mail2Beyond ========= - +[![PyPI](https://github.com/soluna-studios/mail2beyond/actions/workflows/pypi.yml/badge.svg)](https://github.com/soluna-studios/mail2beyond/actions/workflows/pypi.yml) [![Documentation Build](https://github.com/soluna-studios/mail2beyond/actions/workflows/documentation.yml/badge.svg)](https://github.com/soluna-studios/mail2beyond/actions/workflows/documentation.yml) [![Unit Tests](https://github.com/soluna-studios/mail2beyond/actions/workflows/unittest.yml/badge.svg)](https://github.com/soluna-studios/mail2beyond/actions/workflows/unittest.yml) [![PyLint](https://github.com/soluna-studios/mail2beyond/actions/workflows/pylint.yml/badge.svg)](https://github.com/soluna-studios/mail2beyond/actions/workflows/pylint.yml)