Skip to content

Commit 2c946e7

Browse files
authored
Add check-project-version and update-project-version actions (#5)
* Add update-project-version action * update-project-version: Get script working * update-project-version: Add a link to the workflow log. * update-project-version: Fix handling of Boolean inputs * update-project-version: Remove newlines from changed-files * update-project-version: Reformat changed-files as a Markdown list * update-project-version: Fix quoting * update-project-version: Fix quoting, take 2 * update-project-version: Fix log URL * update-project-version: Fix log URL, take 2 * update-project-version: Fix log URL, take 3 * README.md: Update version tags to v0.2 * Add check-project-version action * check-project-version: Fix here-document indentation * check-project-version: Here-doc take 2 * check-project-version: Remove the `exit 1` because I think it's getting in the way of the `::error` annotation * check-project-version: Here-doc take 4 * check-project-version: Add debug echos * check-project-version: Here-doc take 5 * check-project-version: Here-doc take 6 * check-project-version: Remove debug notices and restore `exit 1` * update-project-version: Try to make release events use the right branch name * update-project-version: Specify the base branch for create-pull-request * update-project-version: Set commit message to the same thing as the PR title * github: Add PR/CI workflows to test the actions * check-project-version: Use the project-directory input * github: Use outcome, not conclusion, to check whether a continue-on-error step failed
1 parent 4ecf035 commit 2c946e7

File tree

7 files changed

+465
-9
lines changed

7 files changed

+465
-9
lines changed

.github/workflows/CI.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- 'releases/**'
8+
workflow_call:
9+
workflow_dispatch:
10+
11+
jobs:
12+
test_actions:
13+
name: Test actions
14+
uses: ./.github/workflows/test_actions.yml

.github/workflows/PR.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: PR
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- 'releases/**'
8+
workflow_call:
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
run_ci:
17+
name: Run CI
18+
uses: ./.github/workflows/CI.yml

.github/workflows/test_actions.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Test actions
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
jobs:
8+
test_check_project_version:
9+
name: Test check-project-version
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check out repo
13+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
14+
- name: Set up Python
15+
uses: ./setup-python
16+
- name: Set up Poetry
17+
uses: ./setup-poetry
18+
- name: Create project with version 1.0.0
19+
run: |
20+
poetry new test-project
21+
poetry version 1.0.0 -C test-project
22+
- name: Check version == 1.0.0
23+
uses: ./check-project-version
24+
with:
25+
project-directory: test-project
26+
expected-version: 1.0.0
27+
- name: Create a notice about the expected failure
28+
run: echo "::notice title=Notice::The next step is expected to fail."
29+
- name: Check version == 1.0.1 (expected to fail)
30+
id: expected-failure
31+
continue-on-error: true
32+
uses: ./check-project-version
33+
with:
34+
project-directory: test-project
35+
expected-version: 1.0.1
36+
- name: Error if the previous step didn't fail
37+
if: steps.expected-failure.outcome != 'failure'
38+
run: |
39+
echo "::error title=Test Failure::The previous step did not fail as expected."
40+
exit 1
41+
test_update_project_version:
42+
name: Test update-project-version
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Check out repo
46+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
47+
- name: Set up Python
48+
uses: ./setup-python
49+
- name: Set up Poetry
50+
uses: ./setup-poetry
51+
- name: Create project with version 1.0.0
52+
run: |
53+
poetry new test-project
54+
poetry version 1.0.0 -C test-project
55+
- name: Update version to 1.0.1
56+
uses: ./update-project-version
57+
with:
58+
project-directory: test-project
59+
create-pull-request: false
60+
version-rule: patch
61+
use-dev-suffix: false
62+
- name: Check version == 1.0.1
63+
uses: ./check-project-version
64+
with:
65+
project-directory: test-project
66+
expected-version: 1.0.1
67+
- name: Update version to 1.0.2.dev0
68+
uses: ./update-project-version
69+
with:
70+
project-directory: test-project
71+
create-pull-request: false
72+
- name: Check version == 1.0.2.dev0
73+
uses: ./check-project-version
74+
with:
75+
project-directory: test-project
76+
expected-version: 1.0.2.dev0
77+
- name: Update version to 1.0.2.dev1
78+
uses: ./update-project-version
79+
with:
80+
project-directory: test-project
81+
create-pull-request: false
82+
- name: Check version == 1.0.2.dev1
83+
uses: ./check-project-version
84+
with:
85+
project-directory: test-project
86+
expected-version: 1.0.2.dev1

README.md

Lines changed: 169 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33
`ni/python-actions` is a Git repository containing reusable GitHub Actions for NI Python projects.
44

5+
## Table of Contents
6+
7+
- [`ni/python-actions`](#nipython-actions)
8+
- [Table of Contents](#table-of-contents)
9+
- [`ni/python-actions/setup-python`](#nipython-actionssetup-python)
10+
- [Usage](#usage)
11+
- [Inputs](#inputs)
12+
- [`python-version`](#python-version)
13+
- [Outputs](#outputs)
14+
- [`python-version`](#python-version-1)
15+
- [`python-path`](#python-path)
16+
- [`ni/python-actions/setup-poetry`](#nipython-actionssetup-poetry)
17+
- [Usage](#usage-1)
18+
- [Inputs](#inputs-1)
19+
- [`poetry-version`](#poetry-version)
20+
- [`ni/python-actions/check-project-version`](#nipython-actionscheck-project-version)
21+
- [Usage](#usage-2)
22+
- [Inputs](#inputs-2)
23+
- [`project-directory`](#project-directory)
24+
- [`expected-version`](#expected-version)
25+
- [`ni/python-actions/update-project-version`](#nipython-actionsupdate-project-version)
26+
- [Usage](#usage-3)
27+
- [Inputs](#inputs-3)
28+
- [`project-directory`](#project-directory-1)
29+
- [`branch-prefix`](#branch-prefix)
30+
- [`create-pull-request`](#create-pull-request)
31+
- [`version-rule` and `use-dev-suffix`](#version-rule-and-use-dev-suffix)
32+
533
## `ni/python-actions/setup-python`
634

735
The `setup-python` action installs Python and adds it to the PATH.
@@ -15,20 +43,21 @@ By default, this action installs Python 3.11.9.
1543

1644
```yaml
1745
steps:
18-
- uses: ni/python-actions/setup-python@v0.1.0
46+
- uses: ni/python-actions/setup-python@v0.2
1947
```
2048
2149
### Inputs
2250
2351
#### `python-version`
2452

2553
You can specify the `python-version` input for testing with multiple versions of Python:
54+
2655
```yaml
2756
strategy:
2857
matrix:
2958
python-version: [3.9, '3.10', 3.11, 3.12, 3.13]
3059
steps:
31-
- uses: ni/python-actions/setup-python@v0.1.0
60+
- uses: ni/python-actions/setup-python@v0.2
3261
with:
3362
python-version: ${{ matrix.python-version }}
3463
```
@@ -38,9 +67,10 @@ steps:
3867
#### `python-version`
3968

4069
You can use the `python-version` output to get the actual version of Python, which is useful for caching:
70+
4171
```yaml
4272
steps:
43-
- uses: ni/python-actions/setup-python@v0.1.0
73+
- uses: ni/python-actions/setup-python@v0.2
4474
id: setup-python
4575
- uses: actions/cache@v4
4676
with:
@@ -54,9 +84,10 @@ steps:
5484
containing the Python installation.
5585

5686
You can also use the `python-path` output to get the path to the Python interpreter:
87+
5788
```yaml
5889
steps:
59-
- uses: ni/python-actions/setup-python@v0.1.0
90+
- uses: ni/python-actions/setup-python@v0.2
6091
id: setup-python
6192
- run: pipx install <package> --python ${{ steps.setup-python.outputs.python-version }}
6293
```
@@ -75,8 +106,8 @@ By default, this action installs Poetry 1.8.2.
75106

76107
```yaml
77108
steps:
78-
- uses: ni/python-actions/setup-python@v0.1.0
79-
- uses: ni/python-actions/setup-poetry@v0.1.0
109+
- uses: ni/python-actions/setup-python@v0.2
110+
- uses: ni/python-actions/setup-poetry@v0.2
80111
- run: poetry install -v
81112
```
82113

@@ -86,9 +117,138 @@ steps:
86117

87118
```yaml
88119
steps:
89-
- uses: ni/python-actions/setup-python@v0.1.0
90-
- uses: ni/python-actions/setup-poetry@v0.1.0
120+
- uses: ni/python-actions/setup-python@v0.2
121+
- uses: ni/python-actions/setup-poetry@v0.2
91122
with:
92123
poetry-version: 2.1.3
93124
- run: poetry install -v
94-
```
125+
```
126+
127+
## `ni/python-actions/check-project-version`
128+
129+
The `check-project-version` action uses Poetry to get the version of a Python project and checks
130+
that it matches an expected version. By default, this action checks against `github.ref_name`, which
131+
is the GitHub release tag for GitHub release events.
132+
133+
This action requires Poetry, so you must call `setup-python` and `setup-poetry` first.
134+
135+
### Usage
136+
137+
```yaml
138+
steps:
139+
- uses: ni/python-actions/[email protected]
140+
- uses: ni/python-actions/[email protected]
141+
- uses: ni/python-actions/[email protected]
142+
if: github.event_name == 'release'
143+
```
144+
145+
### Inputs
146+
147+
#### `project-directory`
148+
149+
You can specify `project-directory` to check a project located in a subdirectory.
150+
151+
```yaml
152+
- uses: ni/python-actions/[email protected]
153+
with:
154+
project-directory: packages/foo
155+
```
156+
157+
#### `expected-version`
158+
159+
You can specify `expected-version` to check against something other than `github.ref_name`.
160+
161+
```yaml
162+
- uses: ni/python-actions/[email protected]
163+
with:
164+
expected-version: ${{ steps.get-expected-version.outputs.version }}
165+
```
166+
167+
## `ni/python-actions/update-project-version`
168+
169+
The `update-project-version` action uses Poetry to update the version of a Python project and
170+
creates a pull request to modify its `pyproject.toml` file.
171+
172+
This action requires Poetry, so you must call `setup-python` and `setup-poetry` first.
173+
174+
Creating a pull request requires the workflow or job to have the following `GITHUB_TOKEN`
175+
permissions:
176+
177+
```yaml
178+
permissions:
179+
contents: write
180+
pull-requests: write
181+
````
182+
183+
### Usage
184+
185+
```yaml
186+
steps:
187+
- uses: ni/python-actions/[email protected]
188+
- uses: ni/python-actions/[email protected]
189+
- uses: ni/python-actions/[email protected]
190+
```
191+
192+
### Inputs
193+
194+
#### `project-directory`
195+
196+
You can specify `project-directory` to update a project located in a subdirectory.
197+
198+
```yaml
199+
- uses: ni/python-actions/[email protected]
200+
with:
201+
project-directory: packages/foo
202+
```
203+
204+
#### `branch-prefix`
205+
206+
You can specify `branch-prefix` to customize the pull request branch names. The default value of
207+
`users/build/` generates pull requests with names like `users/build/update-project-version-main` and
208+
`users/build/update-project-version-releases-1.1`.
209+
210+
```yaml
211+
- uses: ni/python-actions/[email protected]
212+
with:
213+
branch-prefix: users/python-build/
214+
```
215+
216+
#### `create-pull-request`
217+
218+
You can use `create-pull-request` and `project-directory` to update multiple projects with a single
219+
pull request.
220+
221+
```yaml
222+
- uses: ni/python-actions/[email protected]
223+
with:
224+
project-directory: packages/foo
225+
create-pull-request: false
226+
- uses: ni/python-actions/[email protected]
227+
with:
228+
project-directory: packages/bar
229+
create-pull-request: false
230+
- uses: ni/python-actions/[email protected]
231+
with:
232+
project-directory: packages/baz
233+
create-pull-request: true
234+
```
235+
236+
#### `version-rule` and `use-dev-suffix`
237+
238+
You can specify `version-rule` and `use-dev-suffix` to customize the versioning scheme.
239+
240+
- `version-rule` specifies the rule for updating the version number. For example, `major` will
241+
update 1.0.0 -> 2.0.0, while `patch` will update 1.0.0 -> 1.0.1. See [the docs for `poetry
242+
version`](https://python-poetry.org/docs/cli/#version) for the list of rules and their behavior.
243+
- `use-dev-suffix` specifies whether to use development versions like `1.0.0.dev0`.
244+
245+
The defaults are `version-rule=patch` and `use-dev-suffix=true`, which have the following behavior:
246+
247+
| Old Version | New Version |
248+
| ----------- | ----------- |
249+
| 1.0.0 | 1.0.1.dev0 |
250+
| 1.0.1.dev0 | 1.0.1.dev1 |
251+
| 1.0.1.dev1 | 1.0.1.dev2 |
252+
253+
When you are ready to exit the "dev" phase, you should manually update the version number to the
254+
desired release version before creating a release in GitHub.

0 commit comments

Comments
 (0)