|
1 | | -# Create a JavaScript Action |
| 1 | +# find-python-projects-action |
| 2 | +Github Action for dynamically discovering Python projects in a repository and making available some helpful values from `pyproject.toml`, including CI/CD commands like `test`, for each project it finds. |
2 | 3 |
|
3 | | -<p align="center"> |
4 | | - <a href="https://github.com/actions/javascript-action/actions"><img alt="javscript-action status" src="https://github.com/actions/javascript-action/workflows/units-test/badge.svg"></a> |
5 | | -</p> |
| 4 | +Python projects are identified by the presence of `pyproject.toml`. |
| 5 | +Various pieces of information about each project are parsed from `pyproject.toml` and returned in the action outputs as JSON strings, including shell commands for additional CI type operations like `test` and `package`. |
| 6 | +This is meant to faciliate downstream actions or workflows such as matrix builds for parallel builds of each project. |
6 | 7 |
|
7 | | -Use this template to bootstrap the creation of a JavaScript action.:rocket: |
| 8 | +This action aims to help you eliminate (or at least reduce) the amount of customization needed in your GHA workflows by pushing your project-specific stuff into `pyproject.toml`. |
8 | 9 |
|
9 | | -This template includes tests, linting, a validation workflow, publishing, and versioning guidance. |
10 | 10 |
|
11 | | -If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action) |
| 11 | +## Inputs |
| 12 | +- **root-dir**: Directory root for where to begin recursively searching for projects. |
| 13 | +Python projects contained in this directory or lower will be discovered. Defaults to your repository's root directory. |
12 | 14 |
|
13 | | -## Create an action from this template |
14 | 15 |
|
15 | | -Click the `Use this Template` and provide the new repo details for your action |
| 16 | +## Outputs |
| 17 | +- **paths**: JSON array of found project path strings |
16 | 18 |
|
17 | | -## Code in Main |
| 19 | +- **projects**: JSON array of all found projects ([project object](#project-object-output-shape)) |
18 | 20 |
|
19 | | -Install the dependencies |
| 21 | +- **testable-projects**: JSON array of all found projects ([project object](#project-object-output-shape)) that implement a `test` command in `pyproject.toml` (See [Project Commands](#project-commands)) |
20 | 22 |
|
21 | | -```bash |
22 | | -npm install |
23 | | -``` |
| 23 | +- **packageable-projects**: JSON array of all found projects ([project object](#project-object-output-shape)) that implement a `package` command in `pyproject.toml` (See [Project Commands](#project-commands)) |
24 | 24 |
|
25 | | -Run the tests :heavy_check_mark: |
26 | 25 |
|
27 | | -```bash |
28 | | -$ npm test |
| 26 | +## Project object output shape |
| 27 | +These are the fields for `project` objects in the output: |
29 | 28 |
|
30 | | - PASS ./index.test.js |
31 | | - ✓ throws invalid number (3ms) |
32 | | - ✓ wait 500 ms (504ms) |
33 | | - ✓ test runs (95ms) |
34 | | -... |
35 | | -``` |
| 29 | +- **name**: The name of the project determined by `[project.name]` or `[tool.poetry.name]` |
36 | 30 |
|
37 | | -## Change action.yml |
| 31 | +- **path**: The file path to the `pyproject.toml` file for the project. |
38 | 32 |
|
39 | | -The action.yml defines the inputs and output for your action. |
| 33 | +- **directory**: The directory path where the `pyproject.toml` file resides. |
40 | 34 |
|
41 | | -Update the action.yml with your name, description, inputs and outputs for your action. |
| 35 | +- **buildBackend**: Value of `[build-system.build-backend]` from `pyproject.toml` |
42 | 36 |
|
43 | | -See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions) |
| 37 | +- **pythonVersion**: Value of `[project.requires-python]` or `[tool.poetry.dependencies.python]` from `pyproject.toml` |
44 | 38 |
|
45 | | -## Change the Code |
| 39 | +- **installCommand**: The shell command to run to create and install dependencies into the virtual environment. |
46 | 40 |
|
47 | | -Most toolkit and CI/CD operations involve async operations so the action is run in an async function. |
| 41 | +- **testCommand**: The shell command to run to execute the tests for the project. |
48 | 42 |
|
49 | | -```javascript |
50 | | -const core = require('@actions/core'); |
51 | | -... |
| 43 | +- **packageCommand**: The shell command to run to execute packaging operations for the project. |
52 | 44 |
|
53 | | -async function run() { |
54 | | - try { |
55 | | - ... |
56 | | - } |
57 | | - catch (error) { |
58 | | - core.setFailed(error.message); |
59 | | - } |
60 | | -} |
61 | 45 |
|
62 | | -run() |
63 | | -``` |
| 46 | +## Project Commands |
| 47 | +In the absence of Python standards for expressing internal project CI/CD/Dev operations, this action tries to unify the various known ways in the wild. |
64 | 48 |
|
65 | | -See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages. |
| 49 | +This action recognizes the following typical CI related shell commands: |
66 | 50 |
|
67 | | -## Package for distribution |
| 51 | +- `test` |
| 52 | +- `package` |
68 | 53 |
|
69 | | -GitHub Actions will run the entry point from the action.yml. Packaging assembles the code into one file that can be checked in to Git, enabling fast and reliable execution and preventing the need to check in node_modules. |
| 54 | +In order to make these commands available in the action output, you'll need to define them in `pyproject.toml` using a section appropriate for the particular tools you are using in the project. You can specify all, some, or none, depending on what you need available. |
70 | 55 |
|
71 | | -Actions are run from GitHub repos. Packaging the action will create a packaged action in the dist folder. |
| 56 | +This action will pull the command from the first entry it finds in any of the following sections in `pyproject.toml`: |
| 57 | +- `[tool.tasks]` |
| 58 | +- `[tool.pdm.scripts]` |
| 59 | +- `[tool.poe.tasks]` |
| 60 | +- `[tool.invoke.tasks]` |
72 | 61 |
|
73 | | -Run prepare |
74 | 62 |
|
75 | | -```bash |
76 | | -npm run prepare |
77 | | -``` |
| 63 | +### Where is the support for `[tool.poetry.scripts]`? |
| 64 | +Unfortunately, [Poetry scripts](https://python-poetry.org/docs/pyproject/#scripts) is for specifying commands that are made available to consumers of a package. It isn't meant for CI/CD or developer operations and doesn't meet those needs, primarily because any scripts you define in this section will be added as executable shortcuts to your virtual environment or any virtual environment your package is installed into. |
| 65 | +If you are using Poetry and want to take advantage of this feature from this action, use the catch-all `[tool.tasks]` section. Alternatively, you |
| 66 | +can leverage a task runner tool like [Poe](https://github.com/nat-n/poethepoet) or [Invoke](https://www.pyinvoke.org/) |
78 | 67 |
|
79 | | -Since the packaged index.js is run from the dist folder. |
| 68 | +*If Poetry ever adds support for internal project (CI/CD/Dev) commands separate from published commands, then it will be added to this action.* |
80 | 69 |
|
81 | | -```bash |
82 | | -git add dist |
83 | | -``` |
84 | 70 |
|
85 | | -## Create a release branch |
| 71 | +### Relevant References / Discussions |
| 72 | +https://discuss.python.org/t/a-new-pep-to-specify-dev-scripts-and-or-dev-scripts-providers-in-pyproject-toml/11457 |
86 | 73 |
|
87 | | -Users shouldn't consume the action from master since that would be latest code and actions can break compatibility between major versions. |
| 74 | +https://discuss.python.org/t/proposal-for-tests-entry-point-in-pyproject-toml/2077 |
88 | 75 |
|
89 | | -Checkin to the v1 release branch |
| 76 | +https://stackoverflow.com/questions/70386944/how-should-poetry-scripts-used-in-the-build-process-be-stored-in-the-project |
90 | 77 |
|
91 | | -```bash |
92 | | -git checkout -b v1 |
93 | | -git commit -a -m "v1 release" |
94 | | -``` |
| 78 | +https://github.com/python-poetry/poetry/issues/3386 |
95 | 79 |
|
96 | | -```bash |
97 | | -git push origin v1 |
98 | | -``` |
99 | | - |
100 | | -Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project. |
101 | | - |
102 | | -Your action is now published! :rocket: |
103 | | - |
104 | | -See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) |
105 | | - |
106 | | -## Usage |
107 | | - |
108 | | -You can now consume the action by referencing the v1 branch |
109 | | - |
110 | | -```yaml |
111 | | -uses: actions/javascript-action@v1 |
112 | | -with: |
113 | | - milliseconds: 1000 |
114 | | -``` |
115 | | -
|
116 | | -See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket: |
| 80 | +## Example Workflow |
| 81 | +[.github/workflows/examples/example.yml](.github/workflows/examples/example.yml) |
0 commit comments