Skip to content

Commit e8f25e9

Browse files
authored
python-actions: Initial commit (#1)
Create the `setup-python` and `setup-poetry` actions. Providing our own actions for these allows us to: - Single-source the default versions - Cache the Poetry installation - Isolate the Poetry installation/caching from other software on the runner (e.g. apps installed with pipx) - Single-source workarounds for Poetry installation issues (e.g. python-poetry/poetry#10378 ) - In the future, we could update the `setup-poetry` action to pin Poetry's dependencies Fill in the documentation. Create GitHub issue templates and copy the workflow for syncing GitHub issues to AzDO.
1 parent aaa0a6d commit e8f25e9

File tree

9 files changed

+285
-19
lines changed

9 files changed

+285
-19
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Default code owner for \<reponame\>
2-
benmont #replace for \<reponame\>
1+
# Default code owners for ni/python-actions
2+
* @mshafer-NI @bkeryan
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: 'bug,triage'
6+
---
7+
8+
<!---
9+
Thanks for filing an issue! Before you submit, please read the following:
10+
11+
Search open/closed issues before submitting. Someone may have reported the same issue before.
12+
-->
13+
14+
# Bug Report
15+
16+
<!--- Provide a general summary of the issue here -->
17+
18+
## Repro or Code Sample
19+
20+
<!-- Please provide steps to reproduce the issue and/or a code repository, gist, code snippet or sample files -->
21+
22+
## Expected Behavior
23+
24+
<!--- Tell us what should happen -->
25+
26+
## Current Behavior
27+
28+
<!--- Tell us what happens instead of the expected behavior -->
29+
<!--- If you are seeing an error, please include the full error message and stack trace -->
30+
<!--- If applicable, provide screenshots -->
31+
32+
## Possible Solution
33+
34+
<!--- Not obligatory, but suggest a fix/reason for the bug -->
35+
<!--- Please let us know if you'd be willing to contribute the fix; we'd be happy to work with you -->
36+
37+
## Context
38+
39+
<!--- How has this issue affected you? What are you trying to accomplish? -->
40+
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
41+
42+
## Your Environment
43+
44+
<!--- Include as many relevant details as possible about the environment you experienced the bug in -->
45+
46+
* `ni/python-actions` version
47+
* Python version
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: 'enhancement,triage'
6+
---
7+
8+
<!---
9+
Thanks for filing an issue! Before you submit, please read the following:
10+
11+
Search open/closed issues before submitting. Someone may have requested the same feature before.
12+
-->
13+
14+
## Problem to Solve
15+
16+
<!--- Provide a clear and concise description of why this feature is wanted or what problem it solves. -->
17+
18+
## Proposed Solution
19+
20+
<!--- Provide a clear and concise description of the feature you're proposing. -->
21+
22+
<!--- The implementing team may build a list of tasks/sub-issues here:
23+
## Tasks
24+
- [ ] This is a subtask of the feature. (It can be converted to an issue.)
25+
-->
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Sync issue to Azure DevOps work item
2+
3+
on:
4+
issues:
5+
# Omit "labeled" and "unlabeled" to work around https://github.com/danhellem/github-actions-issue-to-work-item/issues/70
6+
types:
7+
[opened, edited, deleted, closed, reopened, assigned]
8+
issue_comment:
9+
types: [created, edited, deleted]
10+
11+
jobs:
12+
alert:
13+
if: ${{ !github.event.issue.pull_request && github.event.issue.title != 'Dependency Dashboard' }}
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Choose work item type
17+
id: choose_work_item_type
18+
run: |
19+
if [ "${{ contains(github.event.issue.labels.*.name, 'enhancement') || contains(github.event.issue.labels.*.name, 'user story') }}" == "true" ]; then
20+
echo "work_item_type=User Story" >> $GITHUB_OUTPUT
21+
elif [ "${{ contains(github.event.issue.labels.*.name, 'tech debt') }}" == "true" ]; then
22+
echo "work_item_type=Technical Debt" >> $GITHUB_OUTPUT
23+
else
24+
echo "work_item_type=Bug" >> $GITHUB_OUTPUT
25+
fi
26+
- uses: danhellem/github-actions-issue-to-work-item@v2.4
27+
env:
28+
ado_token: "${{ secrets.AZDO_WORK_ITEM_TOKEN }}"
29+
github_token: "${{ secrets.GH_REPO_TOKEN }}"
30+
ado_organization: "ni"
31+
ado_project: "DevCentral"
32+
ado_area_path: "DevCentral\\Product RnD\\Platform HW and SW\\SW New Invest and Tech\\ETW\\Python CodeGen"
33+
ado_wit: "${{ steps.choose_work_item_type.outputs.work_item_type }}"
34+
ado_new_state: "New"
35+
ado_active_state: "Active"
36+
ado_close_state: "Closed"
37+
ado_bypassrules: true
38+
log_level: 100

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Contributing to \<reponame\>
1+
# Contributing to `ni/python-actions`
22

3-
Contributions to \<reponame\> are welcome from all!
3+
Contributions to `ni/python-actions` are welcome from all!
44

5-
\<reponame\> is managed via [git](https://git-scm.com), with the canonical upstream
5+
`ni/python-actions` is managed via [git](https://git-scm.com), with the canonical upstream
66
repository hosted on [GitHub](https://github.com/ni/<reponame>/).
77

8-
\<reponame\> follows a pull-request model for development. If you wish to
8+
`ni/python-actions` follows a pull-request model for development. If you wish to
99
contribute, you will need to create a GitHub account, fork this project, push a
1010
branch with your changes to your project, and then submit a pull request.
1111

@@ -58,4 +58,4 @@ See [GitHub's official documentation](https://help.github.com/articles/using-pul
5858
(taken from [developercertificate.org](https://developercertificate.org/))
5959

6060
See [LICENSE](https://github.com/ni/<reponame>/blob/main/LICENSE)
61-
for details about how \<reponame\> is licensed.
61+
for details about how `ni/python-actions` is licensed.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2022, National Instruments Corp.
1+
Copyright (c) 2025, National Instruments Corp.
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

README.md

Lines changed: 90 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,94 @@
1-
# GitHub Repo Template
1+
# `ni/python-actions`
22

3-
GitHub Repo Template is a template for creation of open source projects made
4-
available on GitHub. It includes a permissive open source license, a developer
5-
certificate of origin, and a pull request template. This provides everything
6-
necessary to have a properly licensed open source project.
3+
`ni/python-actions` is a Git repository containing reusable GitHub Actions for NI Python projects.
74

8-
## Using GitHub Repo Template
5+
## `ni/python-actions/setup-python`
96

10-
1. Clone or download this repository.
11-
2. Copy its contents into your project (including the hidden .github directory).
12-
3. Customize each file to suit your project's needs (including the README). Look through the files for "TODO" and \<reponame\>, and replace with content appropriate to your project.
13-
4. (Optional) Check out [GitHub Template Guidelines](https://github.com/cezaraugusto/github-template-guidelines) for ideas about how to customize your project.
7+
The `setup-python` action installs Python and adds it to the PATH.
148

15-
TODO: describe a project in detail, what it does, how to use it, etc.
9+
It is a thin wrapper for https://github.com/actions/setup-python which is intended to
10+
single-source the default Python version for multiple NI Python projects.
11+
12+
By default, this action installs Python 3.11.9.
13+
14+
### Usage
15+
16+
```yaml
17+
steps:
18+
- uses: ni/python-actions/setup-python@v0.1.0
19+
```
20+
21+
### Inputs
22+
23+
#### `python-version`
24+
25+
You can specify the `python-version` input for testing with multiple versions of Python:
26+
```yaml
27+
strategy:
28+
matrix:
29+
python-version: [3.9, '3.10', 3.11, 3.12, 3.13]
30+
steps:
31+
- uses: ni/python-actions/setup-python@v0.1.0
32+
with:
33+
python-version: ${{ matrix.python-version }}
34+
```
35+
36+
### Outputs
37+
38+
#### `python-version`
39+
40+
You can use the `python-version` output to get the actual version of Python, which is useful for caching:
41+
```yaml
42+
steps:
43+
- uses: ni/python-actions/setup-python@v0.1.0
44+
id: setup-python
45+
- uses: actions/cache@v4
46+
with:
47+
path: .venv
48+
key: venv-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}
49+
```
50+
51+
#### `python-path`
52+
53+
`actions/setup-python` sets the `pythonLocation` environment variable to the **directory**
54+
containing the Python installation.
55+
56+
You can also use the `python-path` output to get the path to the Python interpreter:
57+
```yaml
58+
steps:
59+
- uses: ni/python-actions/setup-python@v0.1.0
60+
id: setup-python
61+
- run: pipx install <package> --python ${{ steps.setup-python.outputs.python-version }}
62+
```
63+
64+
## `ni/python-actions/setup-poetry`
65+
66+
The `setup-poetry` action installs Poetry, adds it to the PATH, and caches it to speed up
67+
workflows.
68+
69+
This action installs Poetry using the Python version that was selected by the `setup-python`
70+
action, so you must call `setup-python` first.
71+
72+
By default, this action installs Poetry 1.8.2.
73+
74+
### Usage
75+
76+
```yaml
77+
steps:
78+
- uses: ni/python-actions/setup-python@v0.1.0
79+
- uses: ni/python-actions/setup-poetry@v0.1.0
80+
- run: poetry install -v
81+
```
82+
83+
### Inputs
84+
85+
#### `poetry-version`
86+
87+
```yaml
88+
steps:
89+
- uses: ni/python-actions/setup-python@v0.1.0
90+
- uses: ni/python-actions/setup-poetry@v0.1.0
91+
with:
92+
poetry-version: 2.1.3
93+
- run: poetry install -v
94+
```

setup-poetry/action.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Set up Poetry
2+
description: Install Poetry, add it to the PATH, and cache it to speed up workflows.
3+
inputs:
4+
poetry-version:
5+
default: 1.8.2
6+
runs:
7+
using: composite
8+
steps:
9+
- name: Get Python version
10+
id: get-python-version
11+
run: |
12+
if [ ! -d "$pythonLocation" ]; then
13+
echo "You must use the setup-python action before using this action."
14+
exit 1
15+
fi
16+
"$pythonLocation/python" -c "import platform; print(f'python-version={platform.python_version()}')" >> "$GITHUB_OUTPUT"
17+
shell: bash
18+
- name: Set paths (Linux/Mac)
19+
if: runner.os != 'Windows'
20+
run: |
21+
echo "POETRY_BIN_DIR=$HOME/.local/poetry/bin" >> "$GITHUB_ENV"
22+
echo "POETRY_HOME=$HOME/.local/poetry/home" >> "$GITHUB_ENV"
23+
echo "POETRY_HOME_BIN=$HOME/.local/poetry/home/bin" >> "$GITHUB_ENV"
24+
echo "$HOME/.local/poetry/bin" >> "$GITHUB_PATH"
25+
shell: bash
26+
- name: Set paths (Windows)
27+
if: runner.os == 'Windows'
28+
run: |
29+
Add-Content $env:GITHUB_ENV "POETRY_BIN_DIR=$HOME\.local\poetry\bin"
30+
Add-Content $env:GITHUB_ENV "POETRY_HOME=$HOME\.local\poetry\home"
31+
Add-Content $env:GITHUB_ENV "POETRY_HOME_BIN=$HOME\.local\poetry\home\Scripts"
32+
Add-Content $env:GITHUB_PATH "$HOME\.local\poetry\bin"
33+
shell: pwsh
34+
- name: Copy paths from $GITHUB_ENV to $GITHUB_OUTPUT
35+
id: copy-paths
36+
run: |
37+
echo "poetry-bin-dir=$POETRY_BIN_DIR" >> "$GITHUB_OUTPUT"
38+
echo "poetry-home=$POETRY_HOME" >> "$GITHUB_OUTPUT"
39+
shell: bash
40+
- name: Cache poetry
41+
id: cache-poetry
42+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
43+
with:
44+
# Using ${{ env.POETRY_HOME }} here does not work because it is evaluated before the "set paths" step runs.
45+
path: |
46+
${{ steps.copy-paths.outputs.poetry-bin-dir }}/poetry*
47+
${{ steps.copy-paths.outputs.poetry-home }}
48+
key: poetry${{ inputs.poetry-version }}-${{ runner.os }}-py${{ steps.get-python-version.outputs.python-version }}
49+
- name: Install Poetry
50+
if: steps.cache-poetry.outputs.cache-hit != 'true'
51+
run: |
52+
"$pythonLocation/python" -m venv "$POETRY_HOME"
53+
"$POETRY_HOME_BIN/python" -m pip install poetry==${{ inputs.poetry-version }}
54+
mkdir -p "$POETRY_BIN_DIR"
55+
ln -s "$POETRY_HOME_BIN/poetry"* "$POETRY_BIN_DIR/"
56+
shell: bash
57+
- name: Print Poetry version
58+
run: poetry --version
59+
shell: bash

setup-python/action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Set up Python
2+
description: Install Python with appropriate defaults for NI Python projects.
3+
inputs:
4+
python-version:
5+
default: 3.11.9
6+
outputs:
7+
python-path:
8+
value: ${{ steps.setup-python.outputs.python-path }}
9+
python-version:
10+
value: ${{ steps.setup-python.outputs.python-version }}
11+
runs:
12+
using: composite
13+
steps:
14+
- name: Set up Python
15+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
16+
id: setup-python
17+
with:
18+
python-version: ${{ inputs.python-version }}

0 commit comments

Comments
 (0)