Skip to content

Commit 52415ff

Browse files
authored
Merge pull request #41 from klaernie/ci
improve tests and build CI infrastructure
2 parents 3bea628 + b7973eb commit 52415ff

File tree

6 files changed

+123
-55
lines changed

6 files changed

+123
-55
lines changed

.github/workflows/ci.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
pull_request:
6+
workflow_dispatch:
7+
8+
permissions: read-all
9+
10+
jobs:
11+
test-architectures:
12+
name: test OS/arch combinations
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os:
17+
- 'ubuntu-24.04'
18+
- 'ubuntu-24.04-arm'
19+
- 'macos-13' # the last intel mac
20+
- 'macos-15' # arm64 mac
21+
- 'windows-2025'
22+
runs-on: ${{ matrix.os }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: install local package
27+
run: |
28+
python -m pip install .
29+
30+
- name: test that editorconfig-checker works by letting it output it's version
31+
run: |
32+
ec --version
33+
34+
test-python-versions:
35+
runs-on: ubuntu-24.04
36+
steps:
37+
- uses: actions/checkout@v4
38+
39+
- name: install flake8
40+
run: |
41+
python -m pip install flake8
42+
43+
- name: run testsuite verifying against all python versions
44+
shell: bash
45+
run: |
46+
# Only test the local package, since we assume that we only
47+
# upload to PyPI once we are certain that the local package is fine.
48+
export TEST_LOCAL_PKG=true
49+
export TEST_PYPI_PKG=false
50+
51+
# The same commands are defined in the `Makefile` and used for local development.
52+
# We added them here to simplify the building process of the Docker
53+
# image that points to `python:2.7-slim`.
54+
# For such image, `apt-get` was not working as expected.
55+
flake8 --ignore E501 setup.py
56+
bash run-tests.sh

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Dockerfile is run by `run-tests.sh`
2+
3+
# used to define the python tag
4+
ARG IMAGE=3.13-slim
5+
6+
7+
FROM python:$IMAGE AS pybase
8+
RUN python -m pip install --upgrade pip
9+
10+
# separate the obtaining of the requirements from the actual test, so we can use build caching for the first step
11+
FROM pybase as tester
12+
LABEL maintainer="Marco M. (mmicu) <[email protected]>"
13+
14+
COPY . /app
15+
WORKDIR /app
16+
17+
# used to define which python package is installed with pip:
18+
# - a value of `.` builds the images using the docker build context - aka the revision of the package which is currently checked out
19+
# - using a value of `editorconfig-checker` will instead pull the image from PyPI
20+
ARG PACKAGE=.
21+
22+
RUN pip install --no-cache-dir $PACKAGE

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ help:
55
@echo " - clean : Remove generated files."
66
@echo " - coding-style : Run coding style tools."
77
@echo " - publish : Publish package to PyPI."
8+
@echo " - quick-test : Run coding style tools and only the test for the latest python and the current git revision."
89
@echo " - test : Run coding style tools and tests."
910

1011
.PHONY: all
1112
all: help
1213

1314
.PHONY: clean
1415
clean:
15-
@rm -rf build dist editorconfig_checker.egg-info editorconfig_checker/bin tests/Dockerfile-*
16+
@rm -rf build dist editorconfig_checker.egg-info editorconfig_checker/bin
1617

1718
.PHONY: coding-style
1819
coding-style:
@@ -23,6 +24,11 @@ publish: clean test
2324
@python3 setup.py sdist
2425
@twine upload dist/*
2526

27+
.PHONY: quick-test
28+
quick-test: coding-style
29+
docker build -t ec-quick-test .
30+
docker run ec-quick-test ec -version
31+
2632
.PHONY: test
2733
test: coding-style
2834
@bash run-tests.sh

run-tests.sh

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,58 @@
22

33
set -e
44

5-
DOCKERFILE_TEMPLATE="tests/Dockerfile.template"
6-
7-
PY_DOCKER_IMAGES=()
8-
PY_DOCKER_IMAGES+=("2.7.16-slim")
9-
PY_DOCKER_IMAGES+=("3.7.4-slim")
10-
PY_DOCKER_IMAGES+=("3.8-slim")
11-
PY_DOCKER_IMAGES+=("3.9-slim")
12-
PY_DOCKER_IMAGES+=("3.10-slim")
13-
PY_DOCKER_IMAGES+=("3.11-slim")
14-
15-
create_docker_file() {
16-
local package="$1"
17-
18-
# Generate a valid Dockerfile from a template file
19-
local dockerfile="tests/Dockerfile-$py_docker_image-$package"
20-
cp "$DOCKERFILE_TEMPLATE" "$dockerfile"
21-
22-
# Replace docker image
23-
sed -i '' "s/\$IMAGE/$py_docker_image/g" "$dockerfile"
24-
25-
# Replace package name
26-
if [[ "$package" == "local" ]]; then
27-
package="."
28-
fi
29-
sed -i '' "s/\$PACKAGE/$package/g" "$dockerfile"
30-
31-
echo "$dockerfile"
32-
}
33-
345
build_docker_image_and_run() {
356
local py_docker_image="$1"
367
local package="$2"
37-
local dockerfile="$3"
388

39-
# Build
409
local docker_image="editorconfig-checker-$py_docker_image-$package:latest"
41-
docker build -t "$docker_image" -f "$dockerfile" --no-cache --quiet .
4210

43-
# Run `editorconfig-checker`
11+
docker_package="$package"
12+
if [[ "$package" == "local" ]]; then
13+
docker_package="."
14+
fi
15+
16+
docker build \
17+
-t "$docker_image" \
18+
-f "Dockerfile" \
19+
--no-cache-filter tester \
20+
--quiet \
21+
--build-arg "IMAGE=$py_docker_image" \
22+
--build-arg "PACKAGE=$docker_package" \
23+
.
24+
4425
docker run --rm "$docker_image" ec -version
4526
}
4627

4728
main() {
4829
echo -e "Running tests...\n\n"
4930

50-
for py_docker_image in "${PY_DOCKER_IMAGES[@]}"; do
51-
for package in local editorconfig-checker; do
52-
local dockerfile=$(create_docker_file "$package")
53-
echo "Dockerfile created at \"$dockerfile\" (\"$py_docker_image\" image and \"$package\" package)"
54-
55-
echo "Building docker image. It could take some time..."
56-
build_docker_image_and_run "$py_docker_image" "$package" "$dockerfile"
31+
local py_versions=()
32+
if [ -n "$TEST_PY_VERSION" ]; then
33+
py_versions+=("$TEST_PY_VERSION")
34+
else
35+
py_versions+=("2.7")
36+
py_versions+=("3.7")
37+
py_versions+=("3.8")
38+
py_versions+=("3.9")
39+
py_versions+=("3.10")
40+
py_versions+=("3.11")
41+
py_versions+=("3.12")
42+
py_versions+=("3.13")
43+
fi
5744

58-
# docker image rm "$docker_image" &> /dev/null
45+
local py_packages=()
46+
if [ -z "$TEST_LOCAL_PKG" ] || [ "$TEST_LOCAL_PKG" = "true" ]; then
47+
py_packages+=("local")
48+
fi
49+
if [ -z "$TEST_PYPI_PKG" ] || [ "$TEST_PYPI_PKG" = "true" ]; then
50+
py_packages+=("editorconfig-checker")
51+
fi
5952

53+
for py_version in "${py_versions[@]}"; do
54+
for package in "${py_packages[@]}"; do
55+
echo "Building docker image with Python version $py_version and $package package. It could take some time..."
56+
build_docker_image_and_run "$py_version-slim" "$package"
6057
echo -e "\n"
6158
done
6259
done

tests/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/Dockerfile.template

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)