| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5d08a4c commit 87fa39d
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,83 @@ | |||
| 1 | + --- | ||
| 2 | + name: Setup Environment | ||
| 3 | + description: Install requested pipx dependencies, configure the system python, and install poetry and the package dependencies | ||
| 4 | + | ||
| 5 | + inputs: | ||
| 6 | + poetry-install-options: | ||
| 7 | + default: "" | ||
| 8 | + poetry-version: | ||
| 9 | + default: 1.8.2 | ||
| 10 | + python-version: | ||
| 11 | + required: true | ||
| 12 | + cache-pre-commit: | ||
| 13 | + default: false | ||
| 14 | + | ||
| 15 | + runs: | ||
| 16 | + using: composite | ||
| 17 | + steps: | ||
| 18 | + - uses: "actions/setup-python@v5" | ||
| 19 | + id: setup-python | ||
| 20 | + with: | ||
| 21 | + python-version: "${{ inputs.python-version }}" | ||
| 22 | + | ||
| 23 | + - name: Setup pipx environment Variables | ||
| 24 | + id: pipx-env-setup | ||
| 25 | + # pipx default home and bin dir are not writable by the cache action | ||
| 26 | + # so override them here and add the bin dir to PATH for later steps. | ||
| 27 | + # This also ensures the pipx cache only contains poetry | ||
| 28 | + run: | | ||
| 29 | + SEP="${{ !startsWith(runner.os, 'windows') && '/' || '\\' }}" | ||
| 30 | + PIPX_CACHE="${{ github.workspace }}${SEP}pipx_cache" | ||
| 31 | + echo "pipx-cache-path=${PIPX_CACHE}" >> $GITHUB_OUTPUT | ||
| 32 | + echo "pipx-version=$(pipx --version)" >> $GITHUB_OUTPUT | ||
| 33 | + echo "PIPX_HOME=${PIPX_CACHE}${SEP}home" >> $GITHUB_ENV | ||
| 34 | + echo "PIPX_BIN_DIR=${PIPX_CACHE}${SEP}bin" >> $GITHUB_ENV | ||
| 35 | + echo "PIPX_MAN_DIR=${PIPX_CACHE}${SEP}man" >> $GITHUB_ENV | ||
| 36 | + echo "${PIPX_CACHE}${SEP}bin" >> $GITHUB_PATH | ||
| 37 | + shell: bash | ||
| 38 | + | ||
| 39 | + - name: Pipx cache | ||
| 40 | + id: pipx-cache | ||
| 41 | + uses: actions/cache@v4 | ||
| 42 | + with: | ||
| 43 | + path: ${{ steps.pipx-env-setup.outputs.pipx-cache-path }} | ||
| 44 | + key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipx-${{ steps.pipx-env-setup.outputs.pipx-version }}-poetry-${{ inputs.poetry-version }} | ||
| 45 | + | ||
| 46 | + - name: Install poetry | ||
| 47 | + if: steps.pipx-cache.outputs.cache-hit != 'true' | ||
| 48 | + id: install-poetry | ||
| 49 | + shell: bash | ||
| 50 | + run: |- | ||
| 51 | + pipx install poetry==${{ inputs.poetry-version }} --python "${{ steps.setup-python.outputs.python-path }}" | ||
| 52 | + | ||
| 53 | + - name: Read poetry cache location | ||
| 54 | + id: poetry-cache-location | ||
| 55 | + shell: bash | ||
| 56 | + run: |- | ||
| 57 | + echo "poetry-venv-location=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT | ||
| 58 | + | ||
| 59 | + - uses: actions/cache@v4 | ||
| 60 | + name: Poetry cache | ||
| 61 | + with: | ||
| 62 | + path: | | ||
| 63 | + ${{ steps.poetry-cache-location.outputs.poetry-venv-location }} | ||
| 64 | + key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}-options-${{ inputs.poetry-install-options }} | ||
| 65 | + | ||
| 66 | + - name: "Poetry install" | ||
| 67 | + shell: bash | ||
| 68 | + run: | | ||
| 69 | + poetry install ${{ inputs.poetry-install-options }} | ||
| 70 | + | ||
| 71 | + - name: Read pre-commit version | ||
| 72 | + if: inputs.cache-pre-commit == 'true' | ||
| 73 | + id: pre-commit-version | ||
| 74 | + shell: bash | ||
| 75 | + run: >- | ||
| 76 | + echo "pre-commit-version=$(poetry run pre-commit -V | awk '{print $2}')" >> $GITHUB_OUTPUT | ||
| 77 | + | ||
| 78 | + - uses: actions/cache@v4 | ||
| 79 | + if: inputs.cache-pre-commit == 'true' | ||
| 80 | + name: Pre-commit cache | ||
| 81 | + with: | ||
| 82 | + path: ~/.cache/pre-commit/ | ||
| 83 | + key: ${{ runner.os }}-pre-commit-${{ steps.pre-commit-version.outputs.pre-commit-version }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }} | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,8 @@ on: | |||
| 7 | 7 | branches: ["master"] | |
| 8 | 8 | workflow_dispatch: # to allow manual re-runs | |
| 9 | 9 | ||
| 10 | + env: | ||
| 11 | + POETRY_VERSION: 1.8.2 | ||
| 10 | 12 | ||
| 11 | 13 | jobs: | |
| 12 | 14 | linting: | |
@@ -19,35 +21,12 @@ jobs: | |||
| 19 | 21 | ||
| 20 | 22 | steps: | |
| 21 | 23 | - uses: "actions/checkout@v4" | |
| 22 | - - uses: "actions/setup-python@v5" | ||
| 23 | - id: setup-python | ||
| 24 | + - name: Setup environment | ||
| 25 | + uses: ./.github/actions/setup | ||
| 24 | 26 | with: | |
| 25 | - python-version: "${{ matrix.python-version }}" | ||
| 26 | - - name: Install poetry | ||
| 27 | - run: pipx install poetry --python "${{ steps.setup-python.outputs.python-path }}" | ||
| 28 | - - name: Read poetry cache location | ||
| 29 | - id: poetry-cache-location | ||
| 30 | - shell: bash | ||
| 31 | - run: | | ||
| 32 | - echo "POETRY_VENV_LOCATION=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT | ||
| 33 | - - uses: actions/cache@v3 | ||
| 34 | - name: Poetry cache | ||
| 35 | - with: | ||
| 36 | - path: | | ||
| 37 | - ${{ steps.poetry-cache-location.outputs.POETRY_VENV_LOCATION }} | ||
| 38 | - key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}-extras-false | ||
| 39 | - - name: "Install dependencies" | ||
| 40 | - run: | | ||
| 41 | - poetry install | ||
| 42 | - - name: Read pre-commit version | ||
| 43 | - id: pre-commit-version | ||
| 44 | - run: >- | ||
| 45 | - echo "PRE_COMMIT_VERSION=$(poetry run pre-commit -V | awk '{print $2}')" >> $GITHUB_OUTPUT | ||
| 46 | - - uses: actions/cache@v3 | ||
| 47 | - name: Pre-commit cache | ||
| 48 | - with: | ||
| 49 | - path: ~/.cache/pre-commit/ | ||
| 50 | - key: ${{ runner.os }}-pre-commit-${{ steps.pre-commit-version.outputs.PRE_COMMIT_VERSION }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }} | ||
| 27 | + python-version: ${{ matrix.python-version }} | ||
| 28 | + cache-pre-commit: true | ||
| 29 | + poetry-version: ${{ env.POETRY_VERSION }} | ||
| 51 | 30 | - name: "Check supported device md files are up to date" | |
| 52 | 31 | run: | | |
| 53 | 32 | poetry run pre-commit run generate-supported --all-files | |
@@ -108,31 +87,12 @@ jobs: | |||
| 108 | 87 | ||
| 109 | 88 | steps: | |
| 110 | 89 | - uses: "actions/checkout@v4" | |
| 111 | - - uses: "actions/setup-python@v5" | ||
| 112 | - id: setup-python | ||
| 90 | + - name: Setup environment | ||
| 91 | + uses: ./.github/actions/setup | ||
| 113 | 92 | with: | |
| 114 | - python-version: "${{ matrix.python-version }}" | ||
| 115 | - - name: Install poetry | ||
| 116 | - run: pipx install poetry --python "${{ steps.setup-python.outputs.python-path }}" | ||
| 117 | - - name: Read poetry cache location | ||
| 118 | - id: poetry-cache-location | ||
| 119 | - shell: bash | ||
| 120 | - run: | | ||
| 121 | - echo "POETRY_VENV_LOCATION=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT | ||
| 122 | - - uses: actions/cache@v3 | ||
| 123 | - name: Poetry cache | ||
| 124 | - with: | ||
| 125 | - path: | | ||
| 126 | - ${{ steps.poetry-cache-location.outputs.POETRY_VENV_LOCATION }} | ||
| 127 | - key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}-extras-${{ matrix.extras }} | ||
| 128 | - - name: "Install dependencies (no extras)" | ||
| 129 | - if: matrix.extras == false | ||
| 130 | - run: | | ||
| 131 | - poetry install | ||
| 132 | - - name: "Install dependencies (with extras)" | ||
| 133 | - if: matrix.extras == true | ||
| 134 | - run: | | ||
| 135 | - poetry install --all-extras | ||
| 93 | + python-version: ${{ matrix.python-version }} | ||
| 94 | + poetry-version: ${{ env.POETRY_VERSION }} | ||
| 95 | + poetry-install-options: ${{ matrix.extras == true && '--all-extras' || '' }} | ||
| 136 | 96 | - name: "Run tests (no coverage)" | |
| 137 | 97 | if: ${{ startsWith(matrix.python-version, 'pypy') }} | |
| 138 | 98 | run: | | |
| Back | FazBrowse Home | New Git URL |
0 commit comments