diff --git a/.github/actions/setup-poetry/action.yml b/.github/actions/setup-poetry/action.yml new file mode 100644 index 00000000..41953c78 --- /dev/null +++ b/.github/actions/setup-poetry/action.yml @@ -0,0 +1,58 @@ +name: Set up Poetry +description: Install Poetry and cache its installation. +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: + 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/.github/actions/setup-python/action.yml b/.github/actions/setup-python/action.yml new file mode 100644 index 00000000..217f857f --- /dev/null +++ b/.github/actions/setup-python/action.yml @@ -0,0 +1,18 @@ +name: Set up Python +description: Set up Python, using an NI-chosen default version. +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 }} diff --git a/.github/workflows/check_docs.yml b/.github/workflows/check_docs.yml index 2b7ca182..936b7288 100644 --- a/.github/workflows/check_docs.yml +++ b/.github/workflows/check_docs.yml @@ -4,10 +4,6 @@ on: workflow_call: workflow_dispatch: -env: - POETRY_VERSION: 1.8.2 - PYTHON_VERSION: 3.11.9 - jobs: check_docs: name: Check docs @@ -16,14 +12,10 @@ jobs: - name: Check out repo uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v5 id: setup-python - with: - python-version: ${{ env.PYTHON_VERSION }} + uses: ./.github/actions/setup-python - name: Set up Poetry - uses: Gr1N/setup-poetry@v9 - with: - poetry-version: ${{ env.POETRY_VERSION }} + uses: ./.github/actions/setup-poetry - name: Check for lock changes run: poetry check --lock - name: Cache virtualenv (with docs) diff --git a/.github/workflows/check_nitypes.yml b/.github/workflows/check_nitypes.yml index 38373d35..4be6db76 100644 --- a/.github/workflows/check_nitypes.yml +++ b/.github/workflows/check_nitypes.yml @@ -4,10 +4,6 @@ on: workflow_call: workflow_dispatch: -env: - POETRY_VERSION: 1.8.2 - PYTHON_VERSION: 3.11.9 - jobs: check_nitypes: name: Check nitypes @@ -16,14 +12,10 @@ jobs: - name: Check out repo uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v5 id: setup-python - with: - python-version: ${{ env.PYTHON_VERSION }} + uses: ./.github/actions/setup-python - name: Set up Poetry - uses: Gr1N/setup-poetry@v9 - with: - poetry-version: ${{ env.POETRY_VERSION }} + uses: ./.github/actions/setup-poetry - name: Check for lock changes run: poetry check --lock - name: Cache virtualenv diff --git a/.github/workflows/run_unit_tests.yml b/.github/workflows/run_unit_tests.yml index e165cbf2..cce9fac8 100644 --- a/.github/workflows/run_unit_tests.yml +++ b/.github/workflows/run_unit_tests.yml @@ -4,9 +4,6 @@ on: workflow_call: workflow_dispatch: -env: - POETRY_VERSION: 1.8.2 - jobs: run_unit_tests: name: Run unit tests @@ -22,14 +19,12 @@ jobs: - name: Check out repo uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v5 id: setup-python + uses: ./.github/actions/setup-python with: python-version: ${{ matrix.python-version }} - name: Set up Poetry - uses: Gr1N/setup-poetry@v9 - with: - poetry-version: ${{ env.POETRY_VERSION }} + uses: ./.github/actions/setup-poetry - name: Cache virtualenv uses: actions/cache@v4 with: