Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 56 additions & 60 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,47 @@ jobs:
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- name: Install Task
uses: arduino/setup-task@v2
with:
python-version: ${{ matrix.python-version }}
- name: Cache deps install
id: cache-deps
uses: actions/cache@v3
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v5
with:
path: |
${{ env.POETRY_HOME }}
${{ env.POETRY_CACHE }}
key: cachepoetry-${{ hashFiles('poetry.lock', '.github/workflows/**') }}-${{ matrix.python-version }}
- name: Install poetry
if: steps.cache-deps.outputs.cache-hit != 'true'
run: |
python3 -m venv $POETRY_HOME
$POETRY_HOME/bin/pip install poetry==$POETRY_VERSION
- name: Fix github path
run: |
echo "$POETRY_HOME/bin" >> "$GITHUB_PATH"
- name: Configure poetry
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project false
poetry config cache-dir $POETRY_CACHE
poetry config virtualenvs.path $POETRY_CACHE/venv
- name: Install requirements
if: steps.cache-deps.outputs.cache-hit != 'true'
version: "latest"
python-version: ${{ matrix.python-version }}
- name: Install
run: |
poetry install
task install
- name: Run lint
run: |
poetry run make FIX=0 lint
- name: Run tests / coverage
if [ "${{ matrix.python-version }}" = "3.8" ]; then
# As we have mypy issues with 3.8 => let's skip
export LINT_MYPY=0
fi
task lint
env:
FIX: 0
- name: Run tests
run: |
poetry run make test
task test
- name: Run doc
if: matrix.python-version == '3.12'
run: |
poetry run make doc
task doc
- name: Check modified files
if: matrix.python-version == '3.12'
run: |
git diff --exit-code
task no-dirty
- name: Clean
if: matrix.python-version == '3.12'
run: |
task clean
- name: Check modified files (after clean)
if: matrix.python-version == '3.12'
run: |
task no-dirty

publish_pypi:
runs-on: ubuntu-latest
Expand All @@ -77,53 +74,53 @@ jobs:
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v4
- name: Install Task
uses: arduino/setup-task@v2
with:
python-version: 3.8
- name: Install poetry
run: |
python3 -m venv $POETRY_HOME
$POETRY_HOME/bin/pip install poetry==$POETRY_VERSION
- name: Fix github path
run: |
echo "$POETRY_HOME/bin" >> "$GITHUB_PATH"
- name: Install requirements
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v5
with:
version: "latest"
python-version: 3.12
- name: Install
run: |
poetry install
task install
- name: Override BASEURL in README.md
env:
BASEURL: https://github.com/fabien-marty/jinja-tree/blob/main/
run: |
poetry run jinja-tree .
task doc
- name: Publish on Pypi
run: |
poetry config pypi-token.pypi "${{ secrets.PYPI_TOKEN }}"
VERSION=$(echo "${{ github.event.release.tag_name }}" | sed -e 's/^v//')
poetry version "${VERSION}"
poetry build
poetry publish
echo "VERSION: $VERSION"
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version "$VERSION"
task publish
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}

test_docker:
runs-on: ubuntu-latest
needs: lint_and_test
if: github.event_name != 'release'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
permissions:
contents: read
packages: write
#env:
# REGISTRY: ghcr.io
# IMAGE_NAME: ${{ github.repository }}
#permissions:
# contents: read
# packages: write
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Build docker
run: |
make docker
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
push: false

publish_docker:
runs-on: ubuntu-latest
needs: publish_pypi
if: github.event_name == 'release' && github.event.action == 'created'
env:
REGISTRY: ghcr.io
Expand All @@ -148,7 +145,6 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: docker
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.vscode/
.tmp/
1 change: 1 addition & 0 deletions .task/checksum/uv-lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7d5d8728f1c41f9ef46ce7da4b2e06d7
1 change: 1 addition & 0 deletions .task/checksum/uv-sync
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8135260813d08073fd8fc730744e95f7
1 change: 1 addition & 0 deletions .task/checksum/uv-sync-no-dev-no-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8135260813d08073fd8fc730744e95f7
15 changes: 15 additions & 0 deletions .task/taskfiles/Taskfile-misc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'

tasks:

no-dirty:
desc: "Check that the repository is clean"
silent: true
cmds:
- |
if test -n "$(git status --porcelain)"; then
echo "ERROR: the repository is dirty"
git status
git diff
exit 1
fi
164 changes: 164 additions & 0 deletions .task/taskfiles/Taskfile-uv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
version: '3'

vars:
UV_EXTERNAL:
sh: "( uv --version >/dev/null 2>&1 && echo 1 ) || echo 0"
UV_DIR:
sh: "( uv --version >/dev/null 2>&1 && dirname $(which uv) ) || echo {{.ROOT_DIR}}/.tmp/bin"
UV: "{{.UV_DIR}}/uv"
UVX: "{{.UV_DIR}}/uvx"
VENV: "{{.ROOT_DIR}}/.venv"

DEFAULT_UV_SYNC_OPTS: "--frozen"
UV_SYNC_OPTS: "{{.UV_SYNC_OPTS | default .DEFAULT_UV_SYNC_OPTS}}"

# MYPY
DEFAULT_LINT_MYPY: 1
LINT_MYPY: "{{.LINT_MYPY | default .DEFAULT_LINT_MYPY}}"
DEFAULT_MYPY_OPTS: "--check-untyped-defs"
MYPY_OPTS: "{{.MYPY_OPTS | default .DEFAULT_MYPY_OPTS}}"
DEFAULT_MYPY_ARGS: "."
MYPY_ARGS: "{{.MYPY_ARGS | default .DEFAULT_MYPY_ARGS}}"
MYPY: "{{.UV}} run mypy"

# RUFF
DEFAULT_LINT_RUFF: 1
LINT_RUFF: "{{.LINT_RUFF | default .DEFAULT_LINT_RUFF}}"
DEFAULT_FIX: 1
FIX: "{{.FIX | default .DEFAULT_FIX}}"
DEFAULT_RUFF_OPTS: ""
RUFF_OPTS: "{{.RUFF_OPTS | default .DEFAULT_RUFF_OPTS}}"
DEFAULT_RUFF_ARGS: "."
RUFF_ARGS: "{{.RUFF_ARGS | default .DEFAULT_RUFF_ARGS}}"
RUFF: "{{.UV}} run ruff"

# PYTEST
DEFAULT_TEST_PYTEST: 1
TEST_PYTEST: "{{.TEST_PYTEST | default .DEFAULT_TEST_PYTEST}}"
DEFAULT_COVERAGE: 0
COVERAGE: "{{.COVERAGE | default .DEFAULT_COVERAGE}}"
DEFAULT_PYTEST_COVERAGE_OPTS: "--no-cov-on-fail --cov=jinja_tree --cov-report=term --cov-report=html --cov-report=xml"
PYTEST_COVERAGE_OPTS: "{{.PYTEST_COVERAGE_OPTS | default .DEFAULT_PYTEST_COVERAGE_OPTS}}"
DEFAULT_PYTEST_ARGS: "tests"
PYTEST_ARGS: "{{.PYTEST_ARGS | default .DEFAULT_PYTEST_ARGS}}"
PYTEST: "{{.UV}} run pytest"

tasks:

install:
desc: "(advanced) Install uv (if not already installed) in a local temporary directory"
status:
- "test '{{.UV_EXTERNAL}}' = '1'"
env:
UV_NO_MODIFY_PATH: 1
XDG_BIN_HOME: "{{.UV_DIR}}"
silent: true
cmds:
- echo 'INSTALLING UV...'
- echo '{{.UV_DIR}}'
- echo '{{.UV_EXTERNAL}}'
- mkdir -p "{{.UV_DIR}}"
- wget -O install.sh https://astral.sh/uv/install.sh
- chmod +x install.sh
- ./install.sh
- rm -f install.sh
- "echo 'OK: UV INSTALLED'"
lock:
desc: "(advanced) Lock the uv environment"
deps:
- install
cmds:
- "{{.UV}} lock"
sources:
- "{{.ROOT_DIR}}/pyproject.toml"
generates:
- "{{.ROOT_DIR}}/uv.lock"

sync:
desc: "(advanced) Sync the uv environment"
silent: true
status:
- |
if ! [ -f "{{.VENV}}/.uv_sync_opts" ]; then
exit 1
fi
if [ "{{.UV_SYNC_OPTS}}" != "$(cat {{.VENV}}/.uv_sync_opts)" ]; then
exit 1
fi
if ! [ -f "{{.VENV}}/.uv_lock.md5" ]; then
exit 1
fi
if [ "$(md5sum uv.lock)" != "$(cat {{.VENV}}/.uv_lock.md5)" ]; then
exit 1
fi
deps:
- lock
cmds:
- "{{.UV}} sync {{.UV_SYNC_OPTS}}"
- md5sum uv.lock >{{.VENV}}/.uv_lock.md5
- echo "{{.UV_SYNC_OPTS}}" >{{.VENV}}/.uv_sync_opts

lint:
deps:
- sync
internal: true
silent: true
cmds:
- |
if [ "{{.LINT_RUFF}}" = "1" ]; then
if [ "{{.FIX}}" = "1" ]; then
{{.RUFF}} format {{.RUFF_OPTS}} {{.RUFF_ARGS}}
{{.RUFF}} check --fix {{.RUFF_OPTS}} {{.RUFF_ARGS}}
else
{{.RUFF}} format {{.RUFF_OPTS}} --check {{.RUFF_ARGS}}
{{.RUFF}} check {{.RUFF_OPTS}} {{.RUFF_ARGS}}
fi
fi
- |
if [ "{{.LINT_MYPY}}" = "1" ]; then
{{.MYPY}} {{.MYPY_OPTS}} {{.MYPY_ARGS}}
fi
test:
deps:
- sync
internal: true
silent: true
cmds:
- |
if [ "{{.TEST_PYTEST}}" = "1" ]; then
if [ "{{.COVERAGE}}" = "1" ]; then
{{.PYTEST}} {{.PYTEST_OPTS}} {{.PYTEST_COVERAGE_OPTS}} {{.PYTEST_ARGS}}
else
{{.PYTEST}} {{.PYTEST_OPTS}} {{.PYTEST_ARGS}}
fi
fi
build:
internal: true
silent: true
deps:
- sync
cmds:
- "{{.UV}} build"

publish:
internal: true
silent: true
deps:
- build
cmds:
- "{{.UV}} publish"

clean:
internal: true
silent: true
cmds:
- |
if [ "{{.UV_EXTERNAL}}" = "0" ]; then
rm -f "{{.UVX}}"
rm -Rf {{.UV}}
fi
- rm -Rf .*_cache build
- find . -type d -name __pycache__ -exec rm -Rf {} \; 2>/dev/null || true
- "echo 'OK: CLEANED'"
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.12-alpine

ENV TASK=go-task
ENV UV_NO_CACHE=1

RUN apk update && apk upgrade && apk add go-task && rm -rf /var/cache/apk/*
RUN mkdir -p /app
COPY .task /app/.task
COPY Taskfile.yml README.md pyproject.toml uv.lock /app/
RUN cd /app && export UV_SYNC_OPTS="--frozen --no-dev --no-install-project" && $TASK install
COPY jinja_tree /app/jinja_tree/
COPY entrypoint.sh /app/entrypoint.sh
RUN cd /app && export UV_SYNC_OPTS="--frozen --no-dev --verbose" && $TASK install

WORKDIR /code

ENTRYPOINT ["/app/entrypoint.sh"]
Loading