From af2406e4eaed621ffac9fa8ae5962f24533f243a Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Sun, 18 Feb 2024 19:11:53 +0400 Subject: [PATCH] chore: GitHub workflow to publish pushes on `main` branch to PyPI chore: create GitHub release for main branch in GitHub workflows refactor: fix lint issues and typing issues --- .github/workflows/integration_delivery.yml | 215 +++++++++++++++++++++ CHANGELOG.md | 6 + pyproject.toml | 2 +- todo_demo.py | 2 + 4 files changed, 224 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/integration_delivery.yml diff --git a/.github/workflows/integration_delivery.yml b/.github/workflows/integration_delivery.yml new file mode 100644 index 0000000..5212237 --- /dev/null +++ b/.github/workflows/integration_delivery.yml @@ -0,0 +1,215 @@ +name: CI/CD + +on: + push: + pull_request: + workflow_dispatch: + +env: + PYTHON_VERSION: '3.11' + +jobs: + dependencies: + name: Install Dependencies + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + name: Checkout + + - uses: actions/setup-python@v5 + name: Setup Python + with: + python-version: ${{ env.PYTHON_VERSION }} + architecture: x64 + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + virtualenvs-create: true + + - name: Install dependencies + run: poetry install --with dev + + - name: Save Cached Poetry + id: cached-poetry + uses: actions/cache/save@v4 + with: + path: | + ~/.cache + ~/.local + key: poetry-0 + + type-check: + name: Type Check + needs: + - dependencies + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + name: Checkout + + - uses: actions/setup-python@v5 + name: Setup Python + with: + python-version: ${{ env.PYTHON_VERSION }} + architecture: x64 + + - name: Load Cached Poetry + id: cached-poetry + uses: actions/cache/restore@v4 + with: + path: | + ~/.cache + ~/.local + key: poetry-0 + + - name: Type Check + run: poetry run poe typecheck + + lint: + name: Lint + needs: + - dependencies + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + name: Checkout + + - uses: actions/setup-python@v5 + name: Setup Python + with: + python-version: ${{ env.PYTHON_VERSION }} + architecture: x64 + + - name: Load Cached Poetry + id: cached-poetry + uses: actions/cache/restore@v4 + with: + path: | + ~/.cache + ~/.local + key: poetry-0 + + - name: Lint + run: poetry run poe lint + + build: + name: Build + needs: + - dependencies + runs-on: ubuntu-latest + outputs: + version: ${{ steps.extract_version.outputs.version }} + name: ${{ steps.extract_version.outputs.name }} + steps: + - uses: actions/checkout@v4 + name: Checkout + with: + lfs: true + + - uses: actions/setup-python@v5 + name: Setup Python + with: + python-version: ${{ env.PYTHON_VERSION }} + architecture: x64 + + - name: Load Cached Poetry + id: cached-poetry + uses: actions/cache/restore@v4 + with: + path: | + ~/.cache + ~/.local + key: poetry-0 + + - name: Build + run: poetry build + + - name: Extract Version + id: extract_version + run: | + echo "version=$(poetry version --short)" >> "$GITHUB_OUTPUT" + echo "name=$(poetry version | cut -d' ' -f1)" >> "$GITHUB_OUTPUT" + + - name: Upload wheel + uses: actions/upload-artifact@v4 + with: + name: wheel + path: dist/*.whl + if-no-files-found: error + + - name: Upload binary + uses: actions/upload-artifact@v4 + with: + name: binary + path: dist/*.tar.gz + if-no-files-found: error + + pypi-publish: + name: Publish to PyPI + if: >- + github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + needs: + - type-check + - lint + - build + runs-on: ubuntu-latest + environment: + name: release + url: https://pypi.org/p/${{ needs.build.outputs.name }} + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: wheel + path: dist + + - uses: actions/download-artifact@v4 + with: + name: binary + path: dist + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: dist + verbose: true + + release: + name: Release + needs: + - type-check + - lint + - build + - pypi-publish + environment: + name: release + url: https://pypi.org/p/${{ needs.build.outputs.name }} + runs-on: ubuntu-latest + permissions: + contents: write + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + steps: + - name: Procure Wheel + uses: actions/download-artifact@v4 + with: + name: wheel + path: artifacts + + - name: Procure Binary + uses: actions/download-artifact@v4 + with: + name: binary + path: artifacts + + - name: Release + uses: softprops/action-gh-release@v1 + with: + files: artifacts/* + tag_name: v${{ needs.build.outputs.version }} + body: | + Release of version ${{ needs.build.outputs.version }} + PyPI package: https://pypi.org/project/${{ needs.build.outputs.name }}/${{ needs.build.outputs.version }} + prerelease: false + draft: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 507e952..f3db32b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Version 0.10.4 + +- chore: GitHub workflow to publish pushes on `main` branch to PyPI +- chore: create GitHub release for main branch in GitHub workflows +- refactor: fix lint issues and typing issues + ## Version 0.10.0 - refactor: remove `create_store` closure in favor of `Store` class with identical diff --git a/pyproject.toml b/pyproject.toml index 6dfaa23..c41b845 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "python-redux" -version = "0.10.0" +version = "0.10.4" description = "Redux implementation for Python" authors = ["Sassan Haradji "] license = "Apache-2.0" diff --git a/todo_demo.py b/todo_demo.py index 770ad52..2260b72 100644 --- a/todo_demo.py +++ b/todo_demo.py @@ -95,6 +95,8 @@ def main() -> None: def reaction(content: str | None) -> None: print(content) + _ = reaction + # event listener, note that this will run async in a separate thread, so it can # include async operations like API calls, etc: dummy_api_call = print