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

Test gh actions #6

Open
wants to merge 15 commits into
base: gh_workflow_skip_build_#690
Choose a base branch
from
Open
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
82 changes: 17 additions & 65 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,83 +9,35 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
env:
RM_TS_DIR: "/tmp/rmlint-unit-testdir"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: "Prepare build environment"
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
scons python3-sphinx gettext python3-setuptools \
libblkid-dev libelf-dev libglib2.0-dev libjson-glib-dev \
clang python3-pip python3-cffi python3-dev libffi-dev
pip3 install -r tests/requirements.txt

- name: "Build"
# Todo: eventually run tests with valgrind (RM_TS_USE_VALGRIND)
# Todo enable slow tests in pytest
run: |
scons config
scons VERBOSE=1 DEBUG=1 O=release

- name: "Check need for testing"
# TODO also include skipping build but allow docs to be processed

- name: "Check changes"
# TODO also include skippin
shell: bash
run: |
if git diff --exit-code --name-only origin/$GITHUB_BASE_REF HEAD ':!.gitignore' ':!docs' ':!*.md' ':!*.txt'; then
echo "RUN_TEST=false" >> "$GITHUB_ENV"
echo "BASE: $GITHUB_BASE_REF"
echo "REF: $GITHUB_REF"
echo "MERGECOMMIT: $GITHUB_SHA"
echo "HEAD_REF: ${{ GITHUB.HEAD_REF }}"
if git diff --exit-code --name-only origin/$GITHUB_BASE_REF...$GITHUB_SHA ':!.gitignore' ':!docs' ':!*.md' ':!*.txt' ':!*.yml'; then
echo "RUN_TEST=false" >> $GITHUB_ENV
echo "RUN_TEST = false"
else
echo "RUN_TEST=true" >> "$GITHUB_ENV"
echo "RUN_TEST=true" >> $GITHUB_ENV
echo "RUN_TEST = true"
fi

- name: "Prepare test environment"
# TODO Ignore linter warning. See https://github.com/github/vscode-github-actions/issues/222
if: ${{ env.RUN_TEST == 'true' }}
# The test suite is seriously disk-intensive. Given that linux
# instances hosted in GitHub have 16G of RAM available we will
# use it to speed up the run.
run: |
sudo mkdir "${RM_TS_DIR}"
sudo mount -o size=12G,nr_inodes=0 -t tmpfs tmpfs "${RM_TS_DIR}"
- name: "Should we test"
run:
echo "the answer is $RUN_TEST"

- name: "Test it"
if: ${{ env.RUN_TEST == 'true' }}
run: |
RM_TS_PRINT_CMD=1 RM_TS_PEDANTIC=0 python -m pytest -s -v

- name: CoW tests
if: ${{ env.RUN_TEST == 'true' }}
shell: bash
run: |
sudo umount "${RM_TS_DIR}"
sudo modprobe brd rd_nr=1 rd_size=12582912
sudo mkfs.btrfs -f /dev/ram0
sudo mount /dev/ram0 "${RM_TS_DIR}"
sudo chmod 0777 "${RM_TS_DIR}"
cat <<'EOF' >> tests/conftest.py

def pytest_collection_modifyitems(items, config):
selected_items = []
deselected_items = []

for item in items:
if "needs_reflink_fs" in getattr(item, "fixturenames", ()):
selected_items.append(item)
else:
deselected_items.append(item)
config.hook.pytest_deselected(items=deselected_items)
items[:] = selected_items
EOF
RM_TS_PRINT_CMD=1 RM_TS_PEDANTIC=0 python -m pytest -s -v

- name: "Cleanup"
if: ${{ env.RUN_TEST == 'true' }}
if: ! ${{ env.RUN_TEST == 'true' }}
run: |
sudo umount "${RM_TS_DIR}"
sudo rmdir "${RM_TS_DIR}"
echo "RUNNING IT... "
1 change: 1 addition & 0 deletions tests/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.16
4 changes: 2 additions & 2 deletions tests/test_formatters/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def csv_string_to_data(csv_dump):
data = list(csv.reader(csv_dump.splitlines()))
return data[1:]


def test_simple(usual_setup_usual_teardown):
@pytest.mark.usefixtures('usual_setup_usual_teardown')
def test_simple():
create_file('1234', 'a')
create_file('1234', 'b')
create_file('1234', 'stupid\'file,name')
Expand Down
3 changes: 2 additions & 1 deletion tests/test_formatters/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from tests.utils import *


def test_simple(usual_setup_usual_teardown):
@pytest.mark.usefixtures('usual_setup_usual_teardown')
def test_simple():
full_path_a = create_file('x', '\t\r\"\b\f\\')
full_path_b = create_file('x', '\"\t\n2134124')
head, *data, footer = run_rmlint('-S a')
Expand Down
3 changes: 2 additions & 1 deletion tests/test_formatters/test_others.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from tests.utils import *


def test_just_call_it(usual_setup_usual_teardown):
@pytest.mark.usefixtures('usual_setup_usual_teardown')
def test_just_call_it():
create_file('1234', 'a')
create_file('1234', 'b')

Expand Down
3 changes: 2 additions & 1 deletion tests/test_formatters/test_sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def filter_part_of_directory(data):
return [e for e in data if e['type'] != 'part_of_directory']


def test_basic(usual_setup_usual_teardown, shell):
@pytest.mark.usefixtures('usual_setup_usual_teardown')
def test_basic(shell):
create_file('xxx', 'a')
create_file('xxx', 'b')

Expand Down