|
| 1 | +# inspired by https://jacobian.org/til/github-actions-poetry/ |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master, main] |
| 6 | + pull_request: |
| 7 | + |
| 8 | +env: |
| 9 | + POETRY_VERSION: 1.8.2 |
| 10 | + API_KEY: ${{ secrets.API_KEY }} |
| 11 | + API_SECRET: ${{ secrets.API_SECRET }} |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + runs-on: ${{ matrix.os }} |
| 16 | + strategy: |
| 17 | + max-parallel: 1 |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + python-version: ["3.12"] |
| 21 | + os: [ubuntu-latest, macOS-latest] |
| 22 | + env: |
| 23 | + POETRY_VIRTUALENVS_IN_PROJECT: true |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + - uses: actions/setup-python@v5 |
| 27 | + with: |
| 28 | + python-version: ${{ matrix.python-version }} |
| 29 | + |
| 30 | + # Cache the installation of Poetry itself, e.g. the next step. This prevents the workflow |
| 31 | + # from installing Poetry every time, which can be slow. Note the use of the Poetry version |
| 32 | + # number in the cache key, and the "-0" suffix: this allows you to invalidate the cache |
| 33 | + # manually if/when you want to upgrade Poetry, or if something goes wrong. |
| 34 | + - name: cache poetry install |
| 35 | + uses: actions/cache@v4 |
| 36 | + with: |
| 37 | + path: ~/.local |
| 38 | + key: poetry-cache-${{ runner.os }}-${{ matrix.python-version }}-${{ env.POETRY_VERSION }} |
| 39 | + |
| 40 | + # Install Poetry. You could do this manually, or there are several actions that do this. |
| 41 | + # `snok/install-poetry` seems to be minimal yet complete, and really just calls out to |
| 42 | + # Poetry's default install script, which feels correct. I pin the Poetry version here |
| 43 | + # because Poetry does occasionally change APIs between versions and I don't want my |
| 44 | + # actions to break if it does. |
| 45 | + # |
| 46 | + # The key configuration value here is `virtualenvs-in-project: true`: this creates the |
| 47 | + # venv as a `.venv` in your testing directory, which allows the next step to easily |
| 48 | + # cache it. |
| 49 | + - uses: snok/install-poetry@v1 |
| 50 | + with: |
| 51 | + version: 1.8.2 |
| 52 | + virtualenvs-create: true |
| 53 | + virtualenvs-in-project: true |
| 54 | + |
| 55 | + # Cache your dependencies (i.e. all the stuff in your `pyproject.toml`) |
| 56 | + - name: cache venv |
| 57 | + uses: actions/cache@v4 |
| 58 | + with: |
| 59 | + path: .venv |
| 60 | + key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} |
| 61 | + - run: poetry install --no-interaction --no-root |
| 62 | + if: steps.cache-deps.outputs.cache-hit != 'true' |
| 63 | + - run: poetry install --no-interaction |
| 64 | + - run: poetry run flake8 py_alpaca_api/ tests/ |
| 65 | + - run: poetry run pytest |
0 commit comments