-
Notifications
You must be signed in to change notification settings - Fork 2
132 lines (128 loc) · 4.72 KB
/
on-push.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Linting and testing
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: read
jobs:
lint:
name: Linting with Python 3.12
runs-on: 'ubuntu-24.04'
steps:
- uses: actions/checkout@v4
- name: Pull all PR commits
if: github.event.pull_request
run: |
# Un-shallow refs.
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
# Deepen topic branch; checkout topic branch.
git fetch origin ${{ github.ref }}:${{ github.head_ref }} \
--depth=$(( ${{ github.event.pull_request.commits }} + 1 ))
git checkout ${{ github.event.pull_request.head.ref }}
# Fetch main for common origin.
git fetch origin main:main --depth=100
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
cache: 'pip'
python-version: 3.12
- name: Run pre-commit on pull request
uses: pre-commit/[email protected]
if: github.event.pull_request
with:
extra_args: >
--from-ref "$(git merge-base main HEAD)"
--to-ref "${{ github.head_ref }}"
- name: Run pre-commit on merge
uses: pre-commit/[email protected]
if: '!github.event.pull_request'
test:
name: Run tests with Python 3.12
runs-on: 'ubuntu-24.04'
container:
image: 'ubuntu:24.04'
steps:
- name: Cache system packages
uses: actions/cache@v4
id: cache-apt
env:
cache-name: cache-apt-packages
with:
path: /var/cache/apt
key: ${{ runner.os }}-build-${{ env.cache-name }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}
${{ runner.os }}-build-
${{ runner.os }}
- name: Install Git in container
run: |
rm -rfv /etc/apt/apt.conf.d/docker*
apt update
apt install -y --no-install-recommends \
ca-certificates git sqlite3 wget xz-utils
- name: Install Typst binary
env:
TYPST_RELEASE: https://github.com/typst/typst/releases/download
run: |
mkdir -p /usr/src/typst
cd /usr/src/typst
wget "$TYPST_RELEASE/v0.11.1/typst-x86_64-unknown-linux-musl.tar.xz"
tar xf typst-x86_64-unknown-linux-musl.tar.xz
install -Dm 755 -t /usr/local/bin typst-x86_64-unknown-linux-musl/typst
# NOTE Step order is important for checkout in container: git
# installation in container precedes repo checkout.
# NOTE Values of ${GITHUB_WORKSPACE} and ${{ github.workspace }} differ
# (see https://github.com/actions/checkout/issues/785 for details).
- uses: actions/checkout@v4
- name: Pull all PR commits
if: github.event.pull_request
run: |
# Restore `.git` location.
git config --global --add safe.directory ${GITHUB_WORKSPACE}
git config --list
# Un-shallow refs.
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
# Deepen topic branch; checkout topic branch.
git fetch origin ${{ github.ref }}:${{ github.head_ref }} \
--depth=$(( ${{ github.event.pull_request.commits }} + 1 ))
git checkout ${{ github.event.pull_request.head.ref }}
# Fetch main for common origin.
git fetch origin main:main --depth=100
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.12
# TODO(@daskol): Clean up and prepare `pyproject.toml` for packaging and
# proper dependency resolution. We must reuse dependency list from
# `pyproject.toml`.
- name: Install Python dependencies
run: |
# Mandatory dependencies.
python -m pip install matplotlib 'numpy>=2'
# Testing dependencies.
python -m pip install mypy 'pytest>=8.2' pytest-cov pytest-dirty
- name: Run all tests with PyTest
run: |
export PYTHON_TAG=$(
python -c 'import sys; print(sys.implementation.cache_tag)')
export PYTHONPATH=$PWD:$PYTHONPATH
pytest -vv \
--cov=mpl_typst \
--cov-report=html:coverage/html/${PYTHON_TAG} \
--cov-report=xml:coverage/xml/report.${PYTHON_TAG}.xml \
--junitxml=pytest/report.${PYTHON_TAG}.xml
- name: Upload PyTest report for Python 3.12
uses: actions/upload-artifact@v4
with:
name: pytest-report
path: |
coverage
pytest
# This step never fails but it is useful to monitor status of type
# corectness.
- name: Check typing
run: mypy mpl_typst || true