Skip to content

Commit 3a1e718

Browse files
[WING-136] Prepare initial release (#22)
* Lint * package.json and action.yml cleanup/prep * Update check-dist * Test coverage and meta files cleanup * Test coverage for setFailed * Lint * Use test-fixtures/multi-project for workflow test * README adds * More README, example workflow. * Lint and package
1 parent fbec943 commit 3a1e718

20 files changed

Lines changed: 558 additions & 390 deletions

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"SharedArrayBuffer": "readonly"
1212
},
1313
"parserOptions": {
14-
"ecmaVersion": 2018
14+
"ecmaVersion": 2020
1515
},
1616
"rules": {
1717
}

.github/workflows/check-dist.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ jobs:
2323
steps:
2424
- uses: actions/checkout@v4
2525

26-
- name: Set Node.js 16.x
26+
- name: Setup Node.js
2727
uses: actions/setup-node@v4.0.1
2828
with:
29-
node-version: 16.x
29+
node-version-file: package.json
30+
cache: npm
3031

3132
- name: Install dependencies
3233
run: npm ci
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Example Workflow
2+
on:
3+
pull_request
4+
jobs:
5+
discover-python-projects:
6+
name: Discover projects
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Check out code
10+
uses: actions/checkout@v4
11+
12+
- name: Discover Projects
13+
id: discover
14+
uses: BrandonLWhite/find-python-projects-action@main
15+
16+
- name: Print Paths
17+
run: echo ${{steps.discover.outputs.paths }}
18+
19+
outputs:
20+
testable-projects: ${{ steps.discover.outputs.testable-projects }}
21+
packageable-projects: ${{ steps.discover.outputs.packageable-projects }}
22+
23+
build-python-projects:
24+
name: "Test: ${{ matrix.project.name }}"
25+
runs-on: ubuntu-latest
26+
needs: discover-python-projects
27+
strategy:
28+
matrix:
29+
project: ${{ fromJson(needs.discover-python-projects.outputs.testable-projects) }}
30+
31+
defaults:
32+
run:
33+
shell: bash
34+
working-directory: ${{ matrix.project.directory }}
35+
36+
steps:
37+
- name: Check out code
38+
uses: actions/checkout@v4
39+
40+
- name: Dump project object
41+
run: |
42+
echo '${{ toJson(matrix.project) }}'
43+
44+
- name: Setup Python
45+
uses: actions/setup-python@v5
46+
with:
47+
python-version-file: ${{ matrix.project.path }}
48+
49+
- name: Install project
50+
if: matrix.project.installCommand
51+
run: ${{ matrix.project.installCommand }}
52+
53+
- name: Test project
54+
run: ${{ matrix.project.testCommand }}
55+
56+
- name: Package project
57+
if: matrix.project.packageCommand
58+
run: ${{ matrix.project.packageCommand }}

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ jobs:
2222
- uses: actions/checkout@v4
2323
- uses: ./
2424
with:
25-
milliseconds: 1000
25+
root-dir: ./test-fixtures/multi-project

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @actions/actions-runtime
1+
# Repository CODEOWNERS

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 GitHub Actions
3+
Copyright (c) 2024 Brandon L White
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 47 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,81 @@
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.
23

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.
67

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`.
89

9-
This template includes tests, linting, a validation workflow, publishing, and versioning guidance.
1010

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.
1214

13-
## Create an action from this template
1415

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
1618

17-
## Code in Main
19+
- **projects**: JSON array of all found projects ([project object](#project-object-output-shape))
1820

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))
2022

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))
2424

25-
Run the tests :heavy_check_mark:
2625

27-
```bash
28-
$ npm test
26+
## Project object output shape
27+
These are the fields for `project` objects in the output:
2928

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]`
3630

37-
## Change action.yml
31+
- **path**: The file path to the `pyproject.toml` file for the project.
3832

39-
The action.yml defines the inputs and output for your action.
33+
- **directory**: The directory path where the `pyproject.toml` file resides.
4034

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`
4236

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`
4438

45-
## Change the Code
39+
- **installCommand**: The shell command to run to create and install dependencies into the virtual environment.
4640

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.
4842

49-
```javascript
50-
const core = require('@actions/core');
51-
...
43+
- **packageCommand**: The shell command to run to execute packaging operations for the project.
5244

53-
async function run() {
54-
try {
55-
...
56-
}
57-
catch (error) {
58-
core.setFailed(error.message);
59-
}
60-
}
6145

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.
6448

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:
6650

67-
## Package for distribution
51+
- `test`
52+
- `package`
6853

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.
7055

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]`
7261

73-
Run prepare
7462

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/)
7867

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.*
8069

81-
```bash
82-
git add dist
83-
```
8470

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
8673

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
8875

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
9077

91-
```bash
92-
git checkout -b v1
93-
git commit -a -m "v1 release"
94-
```
78+
https://github.com/python-poetry/poetry/issues/3386
9579

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)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`find-python-projects finds projects 1`] = `
4+
{
5+
"packageable-projects": [
6+
{
7+
"buildBackend": "poetry.core.masonry.api",
8+
"directory": "test-fixtures/multi-project/project-2",
9+
"installCommand": "poetry install",
10+
"name": "sub-project-2",
11+
"packageCommand": "poetry bundle venv",
12+
"path": "test-fixtures/multi-project/project-2/pyproject.toml",
13+
"pythonVersion": "^3.9",
14+
"testCommand": "poetry run pytest",
15+
},
16+
],
17+
"paths": [
18+
"test-fixtures/multi-project/project-1/pyproject.toml",
19+
"test-fixtures/multi-project/project-2/pyproject.toml",
20+
"test-fixtures/multi-project/project-4/pyproject.toml",
21+
],
22+
"projects": [
23+
{
24+
"buildBackend": "poetry.core.masonry.api",
25+
"directory": "test-fixtures/multi-project/project-1",
26+
"installCommand": "poetry install",
27+
"name": "sub-project-1",
28+
"packageCommand": null,
29+
"path": "test-fixtures/multi-project/project-1/pyproject.toml",
30+
"pythonVersion": "^3.9",
31+
"testCommand": null,
32+
},
33+
{
34+
"buildBackend": "poetry.core.masonry.api",
35+
"directory": "test-fixtures/multi-project/project-2",
36+
"installCommand": "poetry install",
37+
"name": "sub-project-2",
38+
"packageCommand": "poetry bundle venv",
39+
"path": "test-fixtures/multi-project/project-2/pyproject.toml",
40+
"pythonVersion": "^3.9",
41+
"testCommand": "poetry run pytest",
42+
},
43+
{
44+
"directory": "test-fixtures/multi-project/project-4",
45+
"name": "sub-project-4",
46+
"packageCommand": null,
47+
"path": "test-fixtures/multi-project/project-4/pyproject.toml",
48+
"pythonVersion": "^3.9",
49+
"testCommand": null,
50+
},
51+
],
52+
"testable-projects": [
53+
{
54+
"buildBackend": "poetry.core.masonry.api",
55+
"directory": "test-fixtures/multi-project/project-2",
56+
"installCommand": "poetry install",
57+
"name": "sub-project-2",
58+
"packageCommand": "poetry bundle venv",
59+
"path": "test-fixtures/multi-project/project-2/pyproject.toml",
60+
"pythonVersion": "^3.9",
61+
"testCommand": "poetry run pytest",
62+
},
63+
],
64+
}
65+
`;

action.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
name: 'Find Python Projects'
2-
description: 'TODO Description'
1+
name: Find Python Projects
2+
description: Discovers Python sub-projects in a monorepo workspace project
33

44
inputs:
5-
root-path:
6-
description: 'TODO Description'
5+
root-dir:
6+
description: Directory root for where to begin recursively searching for projects. Python projects contained in this directory or lower will be discovered.
77
required: false
88
default: '.'
99

1010
outputs:
11-
projects:
12-
description: 'TODO'
13-
1411
paths:
15-
description: 'TODO: JSON array of projects paths'
12+
description: JSON array of found project path strings
13+
14+
projects:
15+
description: JSON array of all found projects (`project` object)
1616

1717
testable-projects:
18-
description: 'TODO'
18+
description: JSON array of all found projects (`project` object) that implement a `test` command
1919

2020
packageable-projects:
21-
description: 'TODO'
21+
description: JSON array of all found projects (`project` object) that implement a `package` command
2222

2323
runs:
24-
using: 'node16'
24+
using: 'node20'
2525
main: 'dist/index.js'

0 commit comments

Comments
 (0)