Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actions cache #85

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
148 changes: 47 additions & 101 deletions .github/workflows/builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,37 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
py-ver: [py310, py311]
container:
image: ghcr.io/jmlopez-rod/m-devcontainer-${{ matrix.py-ver }}:latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
py-ver: ['3.10.11', '3.11.3']
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install
run: |
python3 -m venv /opt/venv/m
poetry install

- name: Cache venv
uses: actions/cache@v3
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py-ver }}
- uses: jmlopez-rod/m/actions/ensure-poetry@actions-cache
with:
path: /opt/venv/m
key: venv-${{ matrix.py-ver }}-${{ hashFiles('**/poetry.lock') }}
cache-key: ${{ matrix.py-ver }}
- run: poetry install

tests:
needs: setup
runs-on: ubuntu-22.04
strategy:
matrix:
py-ver: [py310, py311]
container:
image: ghcr.io/jmlopez-rod/m-devcontainer-${{ matrix.py-ver }}:latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
py-ver: ['3.10.11', '3.11.3']
# py-ver: [py310, py311]
# container:
# image: ghcr.io/jmlopez-rod/m-devcontainer-${{ matrix.py-ver }}:latest
# credentials:
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache venv
uses: actions/cache@v3
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
path: /opt/venv/m
key: venv-${{ matrix.py-ver }}-${{ hashFiles('**/poetry.lock') }}

python-version: ${{ matrix.py-ver }}
- uses: jmlopez-rod/m/actions/ensure-poetry@actions-cache
with:
cache-key: ${{ matrix.py-ver }}
- name: run tests
run: ./packages/python/tests/run.sh

Expand All @@ -72,20 +61,16 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache venv
uses: actions/cache@v3
- uses: actions/checkout@v3
- uses: jmlopez-rod/m/actions/ensure-poetry@actions-cache
with:
path: /opt/venv/m
key: venv-py311-${{ hashFiles('**/poetry.lock') }}

cache-key: '3.11.3'
- name: env
run: env
- name: lint src
shell: bash
run: |
m ci celt -t flake8 -c @allowed_errors.json < <(flake8 packages/python/m)

- name: lint tests
shell: bash
run: |
Expand All @@ -100,22 +85,12 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache venv
uses: actions/cache@v3
- uses: actions/checkout@v3
- uses: jmlopez-rod/m/actions/ensure-poetry@actions-cache
with:
path: /opt/venv/m
key: venv-py311-${{ hashFiles('**/poetry.lock') }}

- name: src
run: |
mypy ./packages/python/m

- name: tests
run: |
mypy ./packages/python/tests
cache-key: '3.11.3'
- run: mypy ./packages/python/m
- run: mypy ./packages/python/tests

pylint:
needs: setup
Expand All @@ -126,44 +101,28 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache venv
uses: actions/cache@v3
- uses: actions/checkout@v3
- uses: jmlopez-rod/m/actions/ensure-poetry@actions-cache
with:
path: /opt/venv/m
key: venv-py311-${{ hashFiles('**/poetry.lock') }}

cache-key: '3.11.3'
- name: src
shell: bash
run: |
m ci celt -t pylint -m 10 -c @allowed_errors.json < <(pylint ./packages/python/m --rcfile=.pylintrc -f json)

- name: tests
shell: bash
run: |
m ci celt -t pylint -m 10 -c @allowed_errors_tests.json < <(pylint ./packages/python/tests --rcfile=packages/python/tests/.pylintrc -f json)

prettier:
runs-on: ubuntu-22.04
container:
image: ghcr.io/jmlopez-rod/m-devcontainer-py311:latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: pnpm install
run: |
pnpm install

- name: prettier
shell: bash
run: |
pnpm exec prettier -c .
- uses: actions/checkout@v3
- uses: jmlopez-rod/m/actions/ensure-pnpm@actions-cache
with:
pnpm-version: 7.15.0
- run: pnpm install
- run: pnpm exec prettier -c .

build:
needs: setup
Expand All @@ -177,20 +136,13 @@ jobs:
m-is-release: ${{ steps.build.outputs.m-is-release }}
m-tag: ${{ steps.build.outputs.m-tag }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache venv
uses: actions/cache@v3
- uses: actions/checkout@v3
- uses: jmlopez-rod/m/actions/ensure-poetry@actions-cache
with:
path: /opt/venv/m
key: venv-py311-${{ hashFiles('**/poetry.lock') }}

cache-key: '3.11.3'
- name: Build
id: build
run: |
./m/scripts/build.sh

run: ./m/scripts/build.sh
- name: Save build
uses: actions/cache/save@v3
with:
Expand All @@ -211,21 +163,15 @@ jobs:
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
M_TAG: ${{ needs.build.outputs.m-tag }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache venv
uses: actions/cache@v3
- uses: actions/checkout@v3
- uses: jmlopez-rod/m/actions/ensure-poetry@actions-cache
with:
path: /opt/venv/m
key: venv-py311-${{ hashFiles('**/poetry.lock') }}

cache-key: '3.11.3'
- name: Restore build
uses: actions/cache/restore@v3
with:
path: ./.stage-pypi
key: build-${{ github.sha }}

- name: Release
run: |
./m/scripts/publish.sh
4 changes: 4 additions & 0 deletions actions/ensure-pnpm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# m ensure-pnpm action

This action ensures that pnpm is installed and caches the pnpm store for the
given hash of all the pnpm-lock files in the project.
21 changes: 21 additions & 0 deletions actions/ensure-pnpm/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'm ensure-pnpm'
description: 'ensure that pnpm is installed and cache the store'
inputs:
pnpm-version:
description: pnpm version to install
default: latest
required: false
runs:
using: 'composite'
steps:
- name: ensure pnpm
id: pnpm-cache
shell: bash
run: ${GITHUB_ACTION_PATH}/ensure-pnpm.sh ${{ inputs.pnpm-version }}

- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.store-path }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-store-
16 changes: 16 additions & 0 deletions actions/ensure-pnpm/ensure-pnpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

pnpmVersion="${1:-latest}"

set -exuo pipefail

pnpmPath=$(which pnpm || echo '')
if [ "$pnpmPath" == '' ]; then
if [ "$pnpmVersion" == 'latest' ]; then
npm install -g pnpm
else
npm install -g "pnpm@$pnpmVersion"
fi
fi

echo "store-path=$(pnpm store path)" >> $GITHUB_OUTPUT
35 changes: 35 additions & 0 deletions actions/ensure-poetry/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'm ensure-poetry'
description: 'ensure that poetry is installed and cache the venv'
inputs:
poetry-version:
description: poetry version to install
default: latest
required: false
venv-base-path:
description: basepath for the venv
default: /opt/venv
required: false
venv-name:
description: name of the venv
default: workspace
required: false
cache-key:
description: key to use for the cache
default: ''
required: false
runs:
using: 'composite'
steps:
- name: Setup venv cache
uses: actions/cache@v3
with:
path: /opt/venv
# prettier-ignore
key: ${{ runner.os }}-venv-${{ inputs.cache-key }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: ${{ runner.os }}-venv-${{ inputs.cache-key }}-

- name: ensure poetry
id: venv-cache
shell: bash
run: |
${GITHUB_ACTION_PATH}/ensure-poetry.sh ${{ inputs.poetry-version }} ${{ inputs.venv-base-path }} ${{ inputs.venv-name }}
27 changes: 27 additions & 0 deletions actions/ensure-poetry/ensure-poetry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

poetryVersion="${1:-latest}"
venvBasePath="${2:-/opt/venv}"
venvName="${3:-workspace}"

set -exuo pipefail

python -m venv "$venvBasePath/$venvName"
. "$venvBasePath/$venvName/bin/activate"

poetryPath=$(which poetry || echo '')
if [ "$poetryPath" == '' ]; then
if [ "$poetryVersion" == 'latest' ]; then
pip install poetry
else
pip install "poetry==$poetryVersion"
fi
fi

{
echo "POETRY_HOME=$venvBasePath/poetry"
echo "POETRY_CACHE_DIR=$venvBasePath/.cache/pypoetry"
echo "VIRTUAL_ENV=$venvBasePath/$venvName"
} >> "$GITHUB_ENV"

echo "$venvBasePath/$venvName/bin" >> $GITHUB_PATH