From 96d94622b3344aff8e20a9583ad9239ef7c1b093 Mon Sep 17 00:00:00 2001 From: Parul <71857851+sparul93@users.noreply.github.com> Date: Wed, 18 Sep 2024 13:53:21 -0700 Subject: [PATCH] setup CD to publish to PyPI (#14) * setup CD to publish to PyPI * fix version number in publish.yml * v1.0.1 - fix ReadME --- .github/workflows/publish.yml | 93 +++++++++++++++++ README.md | 191 ++++++++++++++++++---------------- pyproject.toml | 7 +- 3 files changed, 200 insertions(+), 91 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..fe94f31 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,93 @@ +name: Publish Filepass Python Package to PyPI + +on: + push: + tags: + - 'v1.*.*' # Trigger workflow on version tags v1.0.0 onwards + + +jobs: + build: + name: Build distribution + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install pypa/build + run: >- + python3 -m + pip install + build + --user + - name: Build a binary wheel and a source tarball + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: dist/ + publish-to-pypi: + name: >- + Publish Filepass Python Package to PyPI + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes + needs: + - build + runs-on: ubuntu-latest + environment: pypi + permissions: + id-token: write # Required for OIDC token exchange with PyPI + contents: read + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish Filepass Python Package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + github-release: + name: >- + Publish Filepass Python Package to GitHub Release + needs: + - publish-to-pypi + runs-on: ubuntu-latest + + permissions: + contents: write # IMPORTANT: mandatory for making GitHub Releases + id-token: write # IMPORTANT: mandatory for sigstore + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Sign the dists with Sigstore + uses: sigstore/gh-action-sigstore-python@v2.1.1 + with: + inputs: >- + ./dist/*-1.*.tar.gz + ./dist/*-1.*.whl + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + run: >- + gh release create + '${{ github.ref_name }}' + --repo '${{ github.repository }}' + --notes "" + - name: Upload artifact signatures to GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + # Upload to GitHub Release using the `gh` CLI. + # `dist/` contains the built packages, and the + # sigstore-produced signatures and certificates. + run: >- + gh release upload + '${{ github.ref_name }}' dist/** + --repo '${{ github.repository }}' diff --git a/README.md b/README.md index 2888c9b..9ae39a8 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,14 @@ # Filepass Package # -Filepass package is a comprehensive Python package designed to facilitate the transfer of the files across different locations and protocols with ease. +__Filepass__ package is a comprehensive Python package designed to facilitate the transfer of the files across different locations and protocols with ease. It supports SFTP, SMB, and LOCAL file systems, and offers functionalities like file renaming (in single file mode) and selective file transfer based on assigned filter. It also offeres advanced file management features such as conditional deletion of files. With support for both custom handler and local logging, 'Filepass' ensures that you can keep a detailed log of your file trasnfers, making troubleshooting and monitoring a breeze. +This package is available as: +* A __PyPI library__, which can be installed via ```pip```. +* A __GitHub Container Registry (GHCR) package__, allowing you to pull and run it via ```docker```. + ## Features ## @@ -28,89 +32,100 @@ Enable custom logging handler by defining the server name, port number and addin ## Installation ## +### From PyPI ### +To install the package from PyPI, run: +```bash pip install filepass +``` + +### From GitHub Container Registry ### +To pull and run the image using Docker, run: +```bash +docker pull ghcr.io/cityofkamloops/filepass:latest + +docker run ghcr.io/cityofkamloops/filepass:latest +``` ## Quick Start ## 1. Import Filepass package: - e.g.: - ```from filepass import file_pass, ConnectionDetails, FilepassMethod``` - -2. Set up connection - create a connection object (ConnectionDetails) based on your protocol of choice. FilepassMethod offers three protocols: SFTP, SMB, and LOCAL - e.g.: - - ```python - sourceServer = ConnectionDetails( - method=FilepassMethod.SMB, - user="user", - password="password", - server="servername", - port="portnumber", - dir="directory/folder", - share="SMB share", - ) - destinationServer = ConnectionDetails( - method=FilepassMethod.SFTP, - user="user", - password="password", - server="servername", - port="portnumber", - dir="directory/folder", - ) - ``` - - -3. Configure Logging: - (Optional) - If you want to enable custom handler logging, such as Graylog logging. Set the server details as follows: - Example: Graylog - * Import the required library for custom logging - import graypy - * Add the handler to your defined logger: - - ```python - handler = graypy. graypy.GELFTCPHandler( - ("servername"), int("portnumber") - ) - ``` - - If you want to simply use local logging: - * Import python logging package. - * Define the logger and handler. - * E.g., handler = logging.StreamHandler(sys.stdout) - * Add the handler to your defined logger. +e.g.: +```from filepass import file_pass, ConnectionDetails, FilepassMethod``` + +2. Set up connection - create a connection object (ConnectionDetails) based on your protocol of choice. +FilepassMethod offers three protocols: SFTP, SMB, and LOCAL. e.g.: +``` +sourceServer = ConnectionDetails( +method=FilepassMethod.SMB, +user="user", +password="password", +server="servername", +port="portnumber", +dir="directory/folder", +share="SMB share", +) +destinationServer = ConnectionDetails( + method=FilepassMethod.SFTP, + user="user", + password="password", + server="servername", + port="portnumber", + dir="directory/folder", +) +``` + +3. Configure Logging:(Optional) +If you want to enable custom handler logging, such as Graylog logging. Set the server details as follows: +Example: +Graylog +* Import the required library for custom logging - import graypy +* Add the handler to your defined logger: + +``` +handler = graypy. graypy.GELFTCPHandler( + ("servername"), int("portnumber") +) +``` + +If you want to simply use local logging: +* Import python logging package. +* Define the logger and handler. + * * E.g., handler = logging.StreamHandler(sys.stdout) +* Add the handler to your defined logger. 4. Define the required parameters for file transfer: - * from_filter = "filename/wildcard" - * e.g. - ```python - from_filter = "*.txt" #transfers all files in the directory, with .txt extension. - from_filter = "transfer_file.csv" #transfers the selected file.``` - * to_delete = "yes or no". - * from_delete = "yes or no". - * logger = set custom handler or local handler. +* from_filter = "filename/wildcard" +e.g. +``` +from_filter = "*.txt" #transfers all files in the directory, with .txt extension. +from_filter = "transfer_file.csv" #transfers the selected file. +``` +* to_delete = "yes or no". +* from_delete = "yes or no". +* logger = set custom handler or local handler. 5. Rename file in single file transfer mode: - Rename a file during transfer by specifying the new_filename parameter such as: - * e.g., - ```python - new_filename = "newfilename" - ``` +Rename a file during transfer by specifying the new_filename parameter such as: +* e.g., +``` +new_filename = "newfilename" +``` - Defaults to 'None', if parameter is not defined. +Defaults to 'None', if parameter is not defined. 6. Transfer Files: - Use the file_pass method to move files to move files from one location to another. - * e.g., - ```python - file_pass( - logger, - from_conn, - to_conn, - from_filter, - to_delete, - from_delete, - new_filename, - ) - ``` +Use the file_pass method to move files to move files from one location to another. +* e.g., +``` +file_pass( + logger, + from_conn, + to_conn, + from_filter, + to_delete, + from_delete, + new_filename, +) +``` ## Support ## If you encounter any issues or have questions, please file an issue on our [GitHub Issues Page](https://github.com/cityofkamloops/filepass/issues) @@ -119,30 +134,30 @@ If you encounter any issues or have questions, please file an issue on our [GitH ## Contributing ## Contributions to Filepass are welcome! Please refer to our [Contribution Guidelines](https://docs.github.com/en/contributing) ### Ways to Contribute ### - * Submit bug reports and feature requests. - * Write and improve documentation. - * Write code for new features and bug fixes. - * Review pull requests. - * Enhance the package's test coverage. +* Submit bug reports and feature requests. +* Write and improve documentation. +* Write code for new features and bug fixes. +* Review pull requests. +* Enhance the package's test coverage. ### Code of Conduct ### - - Participation in this project is governed by The City of Kamloops Code of Conduct. We expect everyone to uphold the principles of respect, kindness and cooperation. +* Participation in this project is governed by The City of Kamloops Code of Conduct. We expect everyone to uphold the principles of respect, kindness and cooperation. ### How to submit contributions ### * Reporting bugs: - - Use the issue tracker to report bugs. - - Describe the bug and include steps to reproduce. +- Use the issue tracker to report bugs. +- Describe the bug and include steps to reproduce. * Feature Requests: - - Submit feature requests using the issue tracker. - - Please include an explanation why the feature would be useful, and how it should work if possible. +- Submit feature requests using the issue tracker. +- Please include an explanation why the feature would be useful, and how it should work if possible. * Pull Requests: - - Fork the repository and create your branch from 'main'. - - If you have added code, please include tests. - - Ensure your project lints and follows the project's coding conventions. - - Write a clear and descriptive commit message. - - Open a pull request with a clear title and description. +- Fork the repository and create your branch from 'main'. +- If you have added code, please include tests. +- Ensure your project lints and follows the project's coding conventions. +- Write a clear and descriptive commit message. +- Open a pull request with a clear title and description. ## Thank you!! ## diff --git a/pyproject.toml b/pyproject.toml index eb7b8aa..28bb849 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "filepass" -version = "0.5.2" +version = "1.0.1" authors = [ { name="Orlund Norstrom", email="onorstrom@kamloops.ca" }, { name="Marco Lussetti", email="mlussetti@kamloops.ca" }, @@ -12,11 +12,12 @@ authors = [ ] description = "Wrapper around fs libraries to synchronized files between different system types including SMB, SFTP, FSTP." readme = "README.md" -license = { file="LICENSE" } -requires-python = ">=3.7" +license = { text= "Apache-2.0" } +requires-python = ">=3.10" classifiers = [ "Programming Language :: Python :: 3", "Operating System :: OS Independent", + "License :: OSI Approved :: Apache Software License", ] [project.urls]