mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-24 20:09:01 +00:00
Rely on WORKDIR
env var to avoid ugly ternary operators in workflows. (#9456)
Ternary operators in GitHub Actions syntax are pretty ugly and hard to read: `inputs.working-directory == '' && '.' || inputs.working-directory` means "if the condition is true, use `'.'` and otherwise use the expression after the `||`". This PR performs the ternary as few times as possible, assigning its outcome to an env var we can then reuse as needed.
This commit is contained in:
18
.github/actions/poetry_setup/action.yml
vendored
18
.github/actions/poetry_setup/action.yml
vendored
@@ -62,30 +62,18 @@ runs:
|
||||
run: |
|
||||
poetry lock --check
|
||||
|
||||
- name: Set proper Poetry.lock file
|
||||
shell: bash
|
||||
env:
|
||||
WORKDIR: ${{ inputs.working-directory == '' && '.' || inputs.working-directory }}
|
||||
run: |
|
||||
if [ -f "$WORKDIR/poetry.lock" ]; then
|
||||
echo 'Using working directory poetry.lock in cache key'
|
||||
cp "$WORKDIR/poetry.lock" poetry-lock.cache-key
|
||||
else
|
||||
echo 'Using the top-level poetry.lock in cache key'
|
||||
cp poetry.lock poetry-lock.cache-key
|
||||
fi
|
||||
|
||||
- uses: actions/cache@v3
|
||||
id: cache-poetry
|
||||
env:
|
||||
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "15"
|
||||
WORKDIR: ${{ inputs.working-directory == '' && '.' || inputs.working-directory }}
|
||||
with:
|
||||
path: |
|
||||
~/.cache/pypoetry/virtualenvs
|
||||
~/.cache/pypoetry/cache
|
||||
~/.cache/pypoetry/artifacts
|
||||
${{ inputs.working-directory == '' && '.' || inputs.working-directory }}/.venv
|
||||
key: poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}-${{ inputs.cache-key }}-${{ hashFiles('poetry-lock.cache-key') }}
|
||||
${{ env.WORKDIR }}/.venv
|
||||
key: poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}-${{ inputs.cache-key }}-${{ hashFiles(format('{0}/poetry.lock', env.WORKDIR)) }}
|
||||
|
||||
- run: ${{ inputs.install-command }}
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
|
Reference in New Issue
Block a user