|
| 1 | +# Generate Release Notes Action—for Developers |
| 2 | + |
| 3 | +- [Get Started](#get-started) |
| 4 | +- [Run Static Code Analysis](#running-static-code-analysis) |
| 5 | +- [Run Black Tool Locally](#run-black-tool-locally) |
| 6 | +- [Run mypy Tool Locally](#run-mypy-tool-locally) |
| 7 | +- [Run Unit Test](#running-unit-test) |
| 8 | +- [Run Action Locally](#run-action-locally) |
| 9 | + |
| 10 | +## Get Started |
| 11 | + |
| 12 | +Clone the repository and navigate to the project directory: |
| 13 | + |
| 14 | +```shell |
| 15 | +git clone https://github.com/AbsaOSS/generate-release-notes.git |
| 16 | +cd generate-release-notes |
| 17 | +``` |
| 18 | + |
| 19 | +Install the dependencies: |
| 20 | + |
| 21 | +```shell |
| 22 | +pip install -r requirements.txt |
| 23 | +export PYTHONPATH=<your path>/generate-release-notes/src |
| 24 | +``` |
| 25 | + |
| 26 | +## Running Static Code Analysis |
| 27 | + |
| 28 | +This project uses the Pylint tool for static code analysis. Pylint analyzes your code without actually running it. It checks for errors, enforces coding standards, looks for code smells, etc. |
| 29 | + |
| 30 | +Pylint displays a global evaluation score for the code, rated out of a maximum score of 10.0. We aim to keep our code quality above 9.5. |
| 31 | + |
| 32 | +### Set Up Python Environment |
| 33 | +```shell |
| 34 | +python3 -m venv venv |
| 35 | +source venv/bin/activate |
| 36 | +pip install -r requirements.txt |
| 37 | +``` |
| 38 | + |
| 39 | +This command will also install a Pylint tool, since it is listed in the project requirements. |
| 40 | + |
| 41 | +### Run Pylint |
| 42 | +Run Pylint on all files currently tracked by Git in the project. |
| 43 | +```shell |
| 44 | +pylint $(git ls-files '*.py') |
| 45 | +``` |
| 46 | + |
| 47 | +To run Pylint on a specific file, follow the pattern `pylint <path_to_file>/<name_of_file>.py`. |
| 48 | + |
| 49 | +Example: |
| 50 | +```shell |
| 51 | +pylint release-notes-generator/generator.py |
| 52 | +``` |
| 53 | + |
| 54 | +## Run Black Tool Locally |
| 55 | +This project uses the [Black](https://github.com/psf/black) tool for code formatting. |
| 56 | +Black aims for consistency, generality, readability, and reducing git diffs. |
| 57 | +The coding style used can be viewed as a strict subset of PEP 8. |
| 58 | + |
| 59 | +The project root file `pyproject.toml` defines the Black tool configuration. |
| 60 | +In this project, we are accepting a line length of 120 characters. |
| 61 | + |
| 62 | +Follow these steps to format your code with Black locally: |
| 63 | + |
| 64 | +### Set Up Python Environment |
| 65 | +From the terminal in the root of the project, run the following command: |
| 66 | + |
| 67 | +```shell |
| 68 | +python3 -m venv venv |
| 69 | +source venv/bin/activate |
| 70 | +pip install -r requirements.txt |
| 71 | +``` |
| 72 | + |
| 73 | +This command will also install a Black tool, since it is listed in the project requirements. |
| 74 | + |
| 75 | +### Run Black |
| 76 | +Run Black on all files currently tracked by Git in the project. |
| 77 | +```shell |
| 78 | +black $(git ls-files '*.py') |
| 79 | +``` |
| 80 | + |
| 81 | +To run Black on a specific file, follow the pattern `black <path_to_file>/<name_of_file>.py`. |
| 82 | + |
| 83 | +Example: |
| 84 | +```shell |
| 85 | +black release_notes_generator/generator.py |
| 86 | +``` |
| 87 | + |
| 88 | +### Expected Output |
| 89 | +This is the console's expected output example after running the tool: |
| 90 | +``` |
| 91 | +All done! ✨ 🍰 ✨ |
| 92 | +1 file reformatted. |
| 93 | +``` |
| 94 | + |
| 95 | + |
| 96 | +## Run mypy Tool Locally |
| 97 | + |
| 98 | +This project uses the [my[py]](https://mypy.readthedocs.io/en/stable/) tool, a static type checker for Python. |
| 99 | + |
| 100 | +> Type checkers help ensure that you correctly use variables and functions in your code. |
| 101 | +> With mypy, add type hints (PEP 484) to your Python programs, |
| 102 | +> and mypy will warn you when you use those types incorrectly. |
| 103 | +my[py] configuration is in `pyproject.toml` file. |
| 104 | + |
| 105 | +Follow these steps to format your code with my[py] locally: |
| 106 | + |
| 107 | +### Run my[py] |
| 108 | + |
| 109 | +Run my[py] on all files in the project. |
| 110 | +```shell |
| 111 | + mypy . |
| 112 | +``` |
| 113 | + |
| 114 | +To run my[py] check on a specific file, follow the pattern `mypy <path_to_file>/<name_of_file>.py --check-untyped-defs`. |
| 115 | + |
| 116 | +Example: |
| 117 | +```shell |
| 118 | + mypy living_documentation_regime/living_documentation_generator.py |
| 119 | +``` |
| 120 | + |
| 121 | + |
| 122 | +## Running Unit Test |
| 123 | + |
| 124 | +Unit tests are written using pytest. To run the tests, use the following command: |
| 125 | + |
| 126 | +```shell |
| 127 | +pytest tests/ |
| 128 | +``` |
| 129 | + |
| 130 | +This will execute all tests located in the tests directory. |
| 131 | + |
| 132 | +## Code Coverage |
| 133 | + |
| 134 | +Code coverage is collected using the pytest-cov coverage tool. To run the tests and collect coverage information, use the following command: |
| 135 | + |
| 136 | +```shell |
| 137 | +pytest --cov=. -v tests/ --cov-fail-under=80 |
| 138 | +``` |
| 139 | + |
| 140 | +This will execute all tests in the tests directory and generate a code coverage report. |
| 141 | + |
| 142 | +See the coverage report on the path: |
| 143 | + |
| 144 | +```shell |
| 145 | +open htmlcov/index.html |
| 146 | +``` |
| 147 | + |
| 148 | +## Run Action Locally |
| 149 | +Create *.sh file and place it in the project root. |
| 150 | + |
| 151 | +```bash |
| 152 | +#!/bin/bash |
| 153 | + |
| 154 | +# Set environment variables based on the action inputs |
| 155 | +export INPUT_TAG_NAME="v0.2.0" |
| 156 | + |
| 157 | +export INPUT_CHAPTERS='[ |
| 158 | +{ title: No entry 🚫, label: duplicate }, |
| 159 | +{ title: Breaking Changes 💥, label: breaking-change }, |
| 160 | +{ title: New Features 🎉, label: enhancement }, |
| 161 | +{ title: New Features 🎉, label: feature }, |
| 162 | +{ title: Bugfixes 🛠, label: bug }, |
| 163 | +{ title: Infrastructure ⚙️, label: infrastructure }, |
| 164 | +{ title: Silent-live 🤫, label: silent-live }, |
| 165 | +{ title: Documentation 📜, label: documentation } |
| 166 | +]' |
| 167 | +export INPUT_WARNINGS="true" |
| 168 | +export INPUT_PUBLISHED_AT="true" |
| 169 | +export INPUT_SKIP_RELEASE_NOTES_LABELS="ignore-in-release" |
| 170 | +export INPUT_PRINT_EMPTY_CHAPTERS="true" |
| 171 | +export INPUT_VERBOSE="true" |
| 172 | + |
| 173 | +# CI in-built variables |
| 174 | +export GITHUB_REPOSITORY="< owner >/< repo-name >" |
| 175 | +export INPUT_GITHUB_TOKEN=$(printenv <your-env-token-var>) |
| 176 | + |
| 177 | +# Run the Python script |
| 178 | +python3 ./<path-to-action-project-root>/main.py |
| 179 | +``` |
0 commit comments