From ac376ce91357e0991c5cce50ea8b4d9f5ef641e1 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 12 May 2025 12:25:32 -0500 Subject: [PATCH] python-actions: Initial commit --- .github/CODEOWNERS | 4 +- .github/ISSUE_TEMPLATE/bug_report.md | 47 ++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 25 +++++ .../workflows/sync_github_issues_to_azdo.yml | 38 +++++++ CONTRIBUTING.md | 10 +- LICENSE | 2 +- README.md | 101 ++++++++++++++++-- setup-poetry/action.yml | 59 ++++++++++ setup-python/action.yml | 18 ++++ 9 files changed, 285 insertions(+), 19 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/workflows/sync_github_issues_to_azdo.yml create mode 100644 setup-poetry/action.yml create mode 100644 setup-python/action.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 349c952..b79df9a 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,2 @@ -# Default code owner for \ -benmont #replace for \ +# Default code owners for ni/python-actions +* @mshafer-NI @bkeryan diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..38ac4c7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,47 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: 'bug,triage' +--- + + + +# Bug Report + + + +## Repro or Code Sample + + + +## Expected Behavior + + + +## Current Behavior + + + + + +## Possible Solution + + + + +## Context + + + + +## Your Environment + + + +* `ni/python-actions` version +* Python version \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..cfd4bfc --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,25 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: 'enhancement,triage' +--- + + + +## Problem to Solve + + + +## Proposed Solution + + + + diff --git a/.github/workflows/sync_github_issues_to_azdo.yml b/.github/workflows/sync_github_issues_to_azdo.yml new file mode 100644 index 0000000..a07d155 --- /dev/null +++ b/.github/workflows/sync_github_issues_to_azdo.yml @@ -0,0 +1,38 @@ +name: Sync issue to Azure DevOps work item + +on: + issues: + # Omit "labeled" and "unlabeled" to work around https://github.com/danhellem/github-actions-issue-to-work-item/issues/70 + types: + [opened, edited, deleted, closed, reopened, assigned] + issue_comment: + types: [created, edited, deleted] + +jobs: + alert: + if: ${{ !github.event.issue.pull_request && github.event.issue.title != 'Dependency Dashboard' }} + runs-on: ubuntu-latest + steps: + - name: Choose work item type + id: choose_work_item_type + run: | + if [ "${{ contains(github.event.issue.labels.*.name, 'enhancement') || contains(github.event.issue.labels.*.name, 'user story') }}" == "true" ]; then + echo "work_item_type=User Story" >> $GITHUB_OUTPUT + elif [ "${{ contains(github.event.issue.labels.*.name, 'tech debt') }}" == "true" ]; then + echo "work_item_type=Technical Debt" >> $GITHUB_OUTPUT + else + echo "work_item_type=Bug" >> $GITHUB_OUTPUT + fi + - uses: danhellem/github-actions-issue-to-work-item@v2.4 + env: + ado_token: "${{ secrets.AZDO_WORK_ITEM_TOKEN }}" + github_token: "${{ secrets.GH_REPO_TOKEN }}" + ado_organization: "ni" + ado_project: "DevCentral" + ado_area_path: "DevCentral\\Product RnD\\Platform HW and SW\\SW New Invest and Tech\\ETW\\Python CodeGen" + ado_wit: "${{ steps.choose_work_item_type.outputs.work_item_type }}" + ado_new_state: "New" + ado_active_state: "Active" + ado_close_state: "Closed" + ado_bypassrules: true + log_level: 100 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 688cf22..094361e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,11 +1,11 @@ -# Contributing to \ +# Contributing to `ni/python-actions` -Contributions to \ are welcome from all! +Contributions to `ni/python-actions` are welcome from all! -\ is managed via [git](https://git-scm.com), with the canonical upstream +`ni/python-actions` is managed via [git](https://git-scm.com), with the canonical upstream repository hosted on [GitHub](https://github.com/ni//). -\ follows a pull-request model for development. If you wish to +`ni/python-actions` follows a pull-request model for development. If you wish to contribute, you will need to create a GitHub account, fork this project, push a branch with your changes to your project, and then submit a pull request. @@ -58,4 +58,4 @@ See [GitHub's official documentation](https://help.github.com/articles/using-pul (taken from [developercertificate.org](https://developercertificate.org/)) See [LICENSE](https://github.com/ni//blob/main/LICENSE) -for details about how \ is licensed. +for details about how `ni/python-actions` is licensed. diff --git a/LICENSE b/LICENSE index c99724b..9dbb135 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2022, National Instruments Corp. +Copyright (c) 2025, National Instruments Corp. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index 91656cb..707ccec 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,94 @@ -# GitHub Repo Template +# `ni/python-actions` -GitHub Repo Template is a template for creation of open source projects made -available on GitHub. It includes a permissive open source license, a developer -certificate of origin, and a pull request template. This provides everything -necessary to have a properly licensed open source project. +`ni/python-actions` is a Git repository containing reusable GitHub Actions for NI Python projects. -## Using GitHub Repo Template +## `ni/python-actions/setup-python` -1. Clone or download this repository. -2. Copy its contents into your project (including the hidden .github directory). -3. Customize each file to suit your project's needs (including the README). Look through the files for "TODO" and \, and replace with content appropriate to your project. -4. (Optional) Check out [GitHub Template Guidelines](https://github.com/cezaraugusto/github-template-guidelines) for ideas about how to customize your project. +The `setup-python` action installs Python and adds it to the PATH. -TODO: describe a project in detail, what it does, how to use it, etc. +It is a thin wrapper for https://github.com/actions/setup-python which is intended to +single-source the default Python version for multiple NI Python projects. + +By default, this action installs Python 3.11.9. + +### Usage + +```yaml +steps: +- uses: ni/python-actions/setup-python@v0.1.0 +``` + +### Inputs + +#### `python-version` + +You can specify the `python-version` input for testing with multiple versions of Python: +```yaml +strategy: + matrix: + python-version: [3.9, '3.10', 3.11, 3.12, 3.13] +steps: +- uses: ni/python-actions/setup-python@v0.1.0 + with: + python-version: ${{ matrix.python-version }} +``` + +### Outputs + +#### `python-version` + +You can use the `python-version` output to get the actual version of Python, which is useful for caching: +```yaml +steps: +- uses: ni/python-actions/setup-python@v0.1.0 + id: setup-python +- uses: actions/cache@v4 + with: + path: .venv + key: venv-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }} +``` + +#### `python-path` + +`actions/setup-python` sets the `pythonLocation` environment variable to the **directory** +containing the Python installation. + +You can also use the `python-path` output to get the path to the Python interpreter: +```yaml +steps: +- uses: ni/python-actions/setup-python@v0.1.0 + id: setup-python +- run: pipx install --python ${{ steps.setup-python.outputs.python-version }} +``` + +## `ni/python-actions/setup-poetry` + +The `setup-poetry` action installs Poetry, adds it to the PATH, and caches it to speed up +workflows. + +This action installs Poetry using the Python version that was selected by the `setup-python` +action, so you must call `setup-python` first. + +By default, this action installs Poetry 1.8.2. + +### Usage + +```yaml +steps: +- uses: ni/python-actions/setup-python@v0.1.0 +- uses: ni/python-actions/setup-poetry@v0.1.0 +- run: poetry install -v +``` + +### Inputs + +#### `poetry-version` + +```yaml +steps: +- uses: ni/python-actions/setup-python@v0.1.0 +- uses: ni/python-actions/setup-poetry@v0.1.0 + with: + poetry-version: 2.1.3 +- run: poetry install -v +``` \ No newline at end of file diff --git a/setup-poetry/action.yml b/setup-poetry/action.yml new file mode 100644 index 0000000..783e852 --- /dev/null +++ b/setup-poetry/action.yml @@ -0,0 +1,59 @@ +name: Set up Poetry +description: Install Poetry, add it to the PATH, and cache it to speed up workflows. +inputs: + poetry-version: + default: 1.8.2 +runs: + using: composite + steps: + - name: Get Python version + id: get-python-version + run: | + if [ ! -d "$pythonLocation" ]; then + echo "You must use the setup-python action before using this action." + exit 1 + fi + "$pythonLocation/python" -c "import platform; print(f'python-version={platform.python_version()}')" >> "$GITHUB_OUTPUT" + shell: bash + - name: Set paths (Linux/Mac) + if: runner.os != 'Windows' + run: | + echo "POETRY_BIN_DIR=$HOME/.local/poetry/bin" >> "$GITHUB_ENV" + echo "POETRY_HOME=$HOME/.local/poetry/home" >> "$GITHUB_ENV" + echo "POETRY_HOME_BIN=$HOME/.local/poetry/home/bin" >> "$GITHUB_ENV" + echo "$HOME/.local/poetry/bin" >> "$GITHUB_PATH" + shell: bash + - name: Set paths (Windows) + if: runner.os == 'Windows' + run: | + Add-Content $env:GITHUB_ENV "POETRY_BIN_DIR=$HOME\.local\poetry\bin" + Add-Content $env:GITHUB_ENV "POETRY_HOME=$HOME\.local\poetry\home" + Add-Content $env:GITHUB_ENV "POETRY_HOME_BIN=$HOME\.local\poetry\home\Scripts" + Add-Content $env:GITHUB_PATH "$HOME\.local\poetry\bin" + shell: pwsh + - name: Copy paths from $GITHUB_ENV to $GITHUB_OUTPUT + id: copy-paths + run: | + echo "poetry-bin-dir=$POETRY_BIN_DIR" >> "$GITHUB_OUTPUT" + echo "poetry-home=$POETRY_HOME" >> "$GITHUB_OUTPUT" + shell: bash + - name: Cache poetry + id: cache-poetry + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 + with: + # Using ${{ env.POETRY_HOME }} here does not work because it is evaluated before the "set paths" step runs. + path: | + ${{ steps.copy-paths.outputs.poetry-bin-dir }}/poetry* + ${{ steps.copy-paths.outputs.poetry-home }} + key: poetry${{ inputs.poetry-version }}-${{ runner.os }}-py${{ steps.get-python-version.outputs.python-version }} + - name: Install Poetry + if: steps.cache-poetry.outputs.cache-hit != 'true' + run: | + "$pythonLocation/python" -m venv "$POETRY_HOME" + "$POETRY_HOME_BIN/python" -m pip install poetry==${{ inputs.poetry-version }} + mkdir -p "$POETRY_BIN_DIR" + ln -s "$POETRY_HOME_BIN/poetry"* "$POETRY_BIN_DIR/" + shell: bash + - name: Print Poetry version + run: poetry --version + shell: bash \ No newline at end of file diff --git a/setup-python/action.yml b/setup-python/action.yml new file mode 100644 index 0000000..bda922d --- /dev/null +++ b/setup-python/action.yml @@ -0,0 +1,18 @@ +name: Set up Python +description: Install Python with appropriate defaults for NI Python projects. +inputs: + python-version: + default: 3.11.9 +outputs: + python-path: + value: ${{ steps.setup-python.outputs.python-path }} + python-version: + value: ${{ steps.setup-python.outputs.python-version }} +runs: + using: composite + steps: + - name: Set up Python + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 + id: setup-python + with: + python-version: ${{ inputs.python-version }}