diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..1048de4 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,30 @@ +name: 'coverage' +on: + pull_request: + branches: + - '**' +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install pytest pytest-cov + - name: Generate cov report + run: | + pytest --cov=. --cov-report=xml:cov-report.xml + + - name: Python Cov + uses: orgoro/coverage@v2 + with: + coverageFile: cov-report.xml + token: ${{ secrets.GITHUB_TOKEN }} + thresholdAll: 0.8 + thresholdNew: 0.9 + thresholdModified: 0.0 diff --git a/.github/workflows/publish_pip.yml b/.github/workflows/publish_pip.yml new file mode 100644 index 0000000..ec39f44 --- /dev/null +++ b/.github/workflows/publish_pip.yml @@ -0,0 +1,49 @@ +# 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: Upload to PIP + +# Controls when the action will run. +on: + # Triggers the workflow when a release is created + release: + types: [created] + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "upload" + upload: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + # Sets up python + - uses: actions/setup-python@v2 + with: + python-version: 3.8 + + # Install dependencies + - name: "Installs dependencies" + run: | + python3 -m pip install --upgrade pip + python3 -m pip install setuptools wheel twine + + # Build and upload to PyPI + - name: "Builds and uploads to PyPI" + run: | + python3 setup.py sdist bdist_wheel + python3 -m twine upload dist/* + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.TWINE_TOKEN }} + diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..d30bc65 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,41 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python package + +on: + push: + branches: [ "main", "dev" ] + pull_request: + branches: [ "main", "dev" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.8", "3.9", "3.10"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest pytest-cov + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest + diff --git a/README.md b/README.md index cfaeeca..76dfe4f 100644 --- a/README.md +++ b/README.md @@ -1 +1,59 @@ -# M1-2022-git \ No newline at end of file +# M1-2022-git + +## Introduction +This repository is a fork from the previous repository. +The bugs in the converter have been fixed and now we want to publish our work as a publicly available python package. + +## Getting started +You should be working from **your own repository** that is a fork of M1-2022-git-workflow. +In order to run this project, you will have to follow these steps. +1. Clone this project +2. move into the project folder +``` shell +cd M1-2022-git-workflow +``` +3. Set up a virtual environment + * Create the virtual environment + ```shell + python -m venv myvenv + ``` + * Activate venv + ```shell + . venv/bin/activate + ``` +4. Install pytest +```shell +pip install -U pytest +``` +5. Execute main script +```shell +python main.py +``` + +## Instructions +### Merge feature branch into dev +Now that the converter has no more bugs, we want to merge our branch feature into the dev branch. +We will do a pull request (on your own repo). On GitHub, go to the "Pull requests tab" and click "New pull request". +Select *base* and *compare*. Remember : we want to merge *decimal-binary-converter* into *dev*. +Then, *Create the pull request*. Add some description of the work you have done and publish the Pull Request. + +**Note** : We could have just merge *decimal-binary-converter* into *dev* from the command line. However, when working on a real project, you probably won't have the rights to do so. Remember : dev is a public branch. So all the work going down there should be carefully reviewed and tested. + + +### Publish your work +We now have an awesome binary/decimal two ways converter ! It's time to publish it so the rest of the world can enjoy it ! +We will publish it on PyPI (Python Package Index) which is a public repository of softwares for Python. +1. First, you have to create an account on [Pypi.org](https://pypi.org/) +2. Then, in your repository, you will find a [.github directory](/.github) +3. Inside this directory, you will find .yml files that defines workflows (using GitHub actions) +4. Open the yml files and take time to understand them. Do not hesitate to ask the teacher about them + +#### Hands on ! +5. We want to create a workflow that will, on publish, test our code and if tests succeed, then publish our package on PyPI +6. In GitHub, click on the *Actions* tab, then click on *new workflow* +7. Choose among the suggestions the template that best suits your use-case and click *Configure* +8. You may find some useful informations in the [Python documentation](https://packaging.python.org/en/latest/tutorials/packaging-projects/) +9. When creating a release on GitHub, do not forget to create a tag corresponding to that release + +#### Pull request +10. Once the workflow is setup and tested (you have published your package using it) you can open a pull request to the [original repository](https://github.com/rgt-yncrea/M1-2022-git-workflow) diff --git a/main.py b/main.py index e69de29..991edee 100644 --- a/main.py +++ b/main.py @@ -0,0 +1,5 @@ +def say_hello(): + print("Say Hello !") + +if __name__ == '__main__': + say_hello() \ No newline at end of file diff --git a/test_main.py b/test_main.py new file mode 100644 index 0000000..0792d1e --- /dev/null +++ b/test_main.py @@ -0,0 +1,5 @@ + + +def test_main(): + assert True +