Skip to content

Commit

Permalink
Merge pull request #623 from socallinuxexpo/rh/1695824707
Browse files Browse the repository at this point in the history
[READY] - Validate datafiles without docker
  • Loading branch information
kylerisse authored Sep 28, 2023
2 parents 63c7709 + 8f3c67b commit b0705e2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
23 changes: 5 additions & 18 deletions .github/workflows/validate-datafiles.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
---
name: ansible-test
name: validate-datafiles

on:
pull_request:
paths:
- '.github/**'
- 'facts/**'
- 'tests/**'
- 'switch-configuration/config/**'
push: # This is only run when PRs are merged into master
branches:
- master
Expand All @@ -17,16 +12,8 @@ jobs:
validate_datafiles:
name: validate_datafiles
runs-on: ubuntu-latest
defaults:
run:
working-directory: facts/
container:
image: kylerisse/ansible-tester@sha256:f6a9507ec1d7a2dd0570cd88cb19746840c4f97e7618f53158616b9e1f5a3618
steps:
- name: checkout
id: checkout
uses: actions/checkout@v2
- name: lint_python_files
run: pylint *.py
- name: datafile_unittest
run: pytest -vv
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- run: nix build -L .#checks.pytest-facts
5 changes: 2 additions & 3 deletions facts/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ def test_datafile(delimiter, meta):
corresponding column index.
}
'''
fha = open(meta["file"])
lines = fha.readlines()
fha.close()
with open(meta["file"], encoding='utf-8') as fha:
lines = fha.readlines()
for linenum, line in enumerate(lines):
# skip comments
if line[0] == '/' and line[1] == '/':
Expand Down
19 changes: 18 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
common
./nix/machines/core/master.nix
];
specialArgs = {inherit self;};
specialArgs = { inherit self; };
};
coreSlave = nixpkgs.lib.nixosSystem {
inherit system pkgs;
Expand Down Expand Up @@ -92,6 +92,23 @@
{
default = import ./shell.nix { inherit pkgs; };
});

checks =
let
pkgs = nixpkgsFor.x86_64-linux;
in
{
# python tests for the data found in facts
# disabling persistence and cache for py utils to avoid warnings
# since caching is taken care of by nix
pytest-facts = pkgs.runCommand "pytest-facts" { } ''
cp -r ${pkgs.lib.cleanSource self}/* .
cd facts
${pkgs.python3Packages.pylint}/bin/pylint --persistent n *.py
${pkgs.python3Packages.pytest}/bin/pytest -vv -p no:cacheprovider
touch $out
'';
};
};

# Bold green prompt for `nix develop`
Expand Down

0 comments on commit b0705e2

Please sign in to comment.