Skip to content

Commit

Permalink
[actions] pre-merge and update cache
Browse files Browse the repository at this point in the history
  • Loading branch information
stonier committed Feb 25, 2023
1 parent 0003494 commit be9256e
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 3 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/pre-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: pre-merge

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

on:
pull_request:
workflow_dispatch:

jobs:
pre-merge:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.8", "3.10"]
include:
- python-version: "3.8"
python-py-version: "py38"
- python-version: "3.10"
python-py-version: "py310"
container:
image: ghcr.io/${{ github.repository }}-ci:${{ matrix.python-py-version }}-poetry-gl-bullseye
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
- name: Poetry Venv Dir
run: |
echo "VENV_DIR=$(poetry config virtualenvs.path)" >> $GITHUB_ENV
- name: Restore the Cache
id: cache-deps
uses: actions/cache@v3
with:
path: ${{ env.VENV_DIR }}
# bump the suffix if you need to force-refresh the cache
key: py-trees-ci-cache-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock', '**/tox.ini') }}-1

# Install all deps, sans the project (--no-root)
- name: Poetry - Install Dependencies
run: poetry install --no-interaction --no-root
if: steps.cache-deps.outputs.cache-hit != 'true'

# Project is installed separately to avoid always invalidating the cache
- name: Poetry - Install Project
run: poetry install --no-interaction

- name: Tox - Tests
run: poetry run tox --workdir ${{ env.VENV_DIR }} -e ${{ matrix.python-py-version }}
- name: Tox - Formatters, Linters
run: poetry run tox --workdir ${{ env.VENV_DIR }} -e check
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ jobs:
POETRY_VERSION=${{ env.POETRY_VERSION }}
DEBIAN_VERSION=${{ env.DEBIAN_VERSION }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PYTHON_SECONDARY_TAG }}-poetry-${{ env.DEBIAN_VERSION }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:python${{ env.PYTHON_SECONDARY_VERSION }}-poetry${{ env.POETRY_VERSION }}-${{ env.DEBIAN_VERSION }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PYTHON_SECONDARY_TAG }}-poetry-gl-${{ env.DEBIAN_VERSION }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:python${{ env.PYTHON_SECONDARY_VERSION }}-poetry${{ env.POETRY_VERSION }}-gl-${{ env.DEBIAN_VERSION }}
labels: ${{ steps.meta.outputs.labels }}
58 changes: 58 additions & 0 deletions .github/workflows/update-poetry-cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
################################################################################
# Ensure poetry and tox installed dependencies are in the cache.
#
# All PR's can reuse devel's caches, but a PR's cache cannot be reused from
# one PR to the next. This jobs' sole purpose is to make sure every PR updates
# devel's cache (if changes are needed) on merging.
#
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows
################################################################################
name: update-poetry-cache

on:
push:
branches:
- devel
workflow_dispatch:

jobs:
update-poetry-cache:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.8", "3.10"]
include:
- python-version: "3.8"
python-py-version: "py38"
- python-version: "3.10"
python-py-version: "py310"
container:
image: ghcr.io/${{ github.repository }}-ci:${{ matrix.python-py-version }}-poetry-gl-bullseye
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
- name: Poetry Venv Dir
run: |
echo "VENV_DIR=$(poetry config virtualenvs.path)" >> $GITHUB_ENV
- name: Restore the Cache
id: cache-deps
uses: actions/cache@v3
with:
path: ${{ env.VENV_DIR }}
# bump the suffix if you need to force-refresh the cache
key: py-trees-ci-cache-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock', '**/tox.ini') }}-1

# Install all deps, sans the project (--no-root)
- name: Poetry - Install Dependencies
run: poetry install --no-interaction --no-root
if: steps.cache-deps.outputs.cache-hit != 'true'

- name: Tox - Install Dependencies
run: poetry run tox --workdir ${{ env.VENV_DIR }} --notest -e ${{ matrix.python-py-version }} check
if: steps.cache-deps.outputs.cache-hit != 'true'


2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ source_locations =
tests

[tox]
envlist = py38, format, check
envlist = py38, py310, format, check

################################################################################
# PyTest
Expand Down

0 comments on commit be9256e

Please sign in to comment.