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

Add initial CI #6

Merged
merged 14 commits into from
Nov 17, 2022
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
63 changes: 63 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Check

on:
pull_request:
push:
branches: [master]

jobs:
pre-commit:
runs-on: ubuntu-latest
container: zeekurity/zeek
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]

btest-linux:
strategy:
matrix:
name:
- lts
- feature
- nightly
include:
- name: lts
container: 'zeekurity/zeek:lts'
allow_failure: false
- name: feature
container: 'zeekurity/zeek:latest'
allow_failure: false
- name: nightly
container: 'zeekurity/zeek-dev:latest'
allow_failure: true

name: Run test suite against Zeek (${{ matrix.name }})

runs-on: ubuntu-latest
container: ${{ matrix.container }}
continue-on-error: ${{ matrix.allow_failure }}
steps:
- uses: actions/checkout@v3
with:
# The output of some commands of `zkg` on the template depends on the
# known tags. Fetch them all.
fetch-depth: 0

# The checkout action leaves the repo in a detached HEAD state which is not
# supported by zkg, see zeek/package-manager#145. Work around this under
# the assumption that we are running on a ref.
- name: Prepare repository
run: git switch -c "gh-ci-$$"

- name: Install prerequisites
run: |
apt-get update
apt-get install -y cmake libpcap-dev g++
- name: Run BTest suite
run: |
btest -djc tests/btest.cfg --xml=btest-results.xml
- uses: mikepenz/action-junit-report@v3
if: always() # Always run even if any previous step fails.
with:
report_paths: '**/btest-results.xml'
46 changes: 46 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
exclude: '.*/Baseline'
- id: end-of-file-fixer
exclude: '.*/Baseline'
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/maxwinterstein/shfmt-py
rev: v3.4.3.1
hooks:
- id: shfmt
args: ["-w", "-i", "4", "-ci"]

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.8.0.4
hooks:
- id: shellcheck

- repo: https://github.com/PyCQA/pylint.git
rev: v2.15.3
hooks:
- id: pylint
additional_dependencies:
- 'zkg'

- repo: local
hooks:
- id: stray_baselines
name: Check for stray BTest baselines
entry: ./tests/scripts/stray_baselines.py
language: python
pass_filenames: false
- id: vermin
name: Check minimal required Python version
# Minimal required Python version according to
# https://docs.zeek.org/en/master/install.html#required-dependencies.
# The value should be kept consistent with `py-version` in `.pylintrc`.
entry: vermin -vv --target=3.5- .
language: python
pass_filenames: false
additional_dependencies:
- 'vermin'
32 changes: 32 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[MAIN]

# Naming style matching correct module names.
#
# NOTE: This package has the existing invalid name `package-template` while
# PEP8 suggest snake_case.
module-naming-style=any

# Minimum Python version to use for version dependent checks. Will default to
# the version used to run pylint.
#
# NOTE: Minimal required Python version according to
# https://docs.zeek.org/en/master/install.html#required-dependencies. This
# value should be kept consistent with vermin's target version in
# `.pre-commit-config.yaml`.
py-version=3.5

[FORMAT]
# Maximum number of characters on a single line.
max-line-length=120

[MESSAGES CONTROL]
# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifiers separated by comma (,) or put this
# option multiple times (only on the command line, not in the configuration
# file where it should appear only once). You can also use "--disable=all" to
# disable everything first and then re-enable specific checks. For example, if
# you want to run only the similarities checker, you can use "--disable=all
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=missing-docstring
63 changes: 43 additions & 20 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@

import git

import zeekpkg.template # pylint: disable=import-error
bbannier marked this conversation as resolved.
Show resolved Hide resolved
import zeekpkg.uservar # pylint: disable=import-error

# pylint: disable=missing-docstring,no-self-use
import zeekpkg.template
import zeekpkg.uservar

TEMPLATE_API_VERSION = '1.0.0'

Expand Down Expand Up @@ -158,27 +156,34 @@ def instantiate(self, tmpl):
self.instantiate_file(tmpl, orig_file, path_name, file_name, content)

# Remove any files marked as unneeded.
for p in glob.glob(os.path.join(self._packagedir, "**/*.REMOVE"), recursive=True):
os.unlink(p)
for path in glob.glob(os.path.join(self._packagedir, "**/*.REMOVE"), recursive=True):
os.unlink(path)

def pkg_file(*name):
p = os.path.join(self._packagedir, *name)
assert os.path.exists(p)
return p
path = os.path.join(self._packagedir, *name)
assert os.path.exists(path)
return path

# Manually merge Spicy analyzer-specific changes to `zkg.meta`.
with open(pkg_file('zkg.meta'), 'ab') as f:
with open(pkg_file('zkg.meta'), 'ab') as zkg_meta:
# Add a build command.
#
# NOTE: For backwards compatibility with <zkg-2.8.0 which did not
# inject binary paths of installed packages into `PATH`, we allow
# as a fallback a `spicyz` path inferred from `zkg`'s directory
# structure.
f.write(b'build_command = mkdir -p build && cd build && SPICYZ=$(command -v spicyz || echo %(package_base)s/spicy-plugin/build/bin/spicyz) cmake .. && cmake --build .\n')
zkg_meta.write(
(
b"build_command = mkdir -p build && "
b"cd build && "
b"SPICYZ=$(command -v spicyz || echo %(package_base)s/spicy-plugin/build/bin/spicyz) cmake .. && "
b"cmake --build .\n"
)
)

# Manually merge Spicy analyzer-specific changes to `testing/btest.cfg`.
with open(pkg_file('testing', 'btest.cfg'), 'ab') as f:
f.write(bytes(textwrap.dedent('''\
with open(pkg_file('testing', 'btest.cfg'), 'ab') as btest_cfg:
btest_cfg.write(bytes(textwrap.dedent('''\
DIST=%(testbase)s/..
# Set compilation-related variables to well-defined state.
CC=
Expand Down Expand Up @@ -210,7 +215,7 @@ def validate(self, tmpl):
SpicyAnalyzer.validate(self, tmpl)

protocol = tmpl.lookup_param("protocol_upper")
if protocol != "TCP" and protocol != "UDP":
if protocol not in ("TCP", "UDP"):
raise zeekpkg.template.InputError('protocol must be TCP or UDP')


Expand Down Expand Up @@ -256,23 +261,41 @@ def define_user_vars(self):
zeekpkg.uservar.UserVar(
'namespace', desc='a namespace for the package, e.g. "MyOrg"'),
zeekpkg.uservar.UserVar(
'analyzer', desc='name of the Spicy analyzer, which typically corresponds to the protocol/format being parsed (e.g. "HTTP", "PNG")'),
'analyzer',
desc=(
'name of the Spicy analyzer, which typically corresponds to the '
'protocol/format being parsed (e.g. "HTTP", "PNG")'
),
),
zeekpkg.uservar.UserVar(
'protocol', desc='transport protocol for the analyzer to use: TCP or UDP'),
zeekpkg.uservar.UserVar(
'unit', desc='name of the top-level Spicy parsing unit for the file/packet format (e.g. "File" or "Packet")'),
"unit",
desc='name of the top-level Spicy parsing unit for the file/packet format (e.g. "File" or "Packet")',
),
zeekpkg.uservar.UserVar(
'unit_orig', desc='name of the top-level Spicy parsing unit for the originator side of the connection (e.g. "Request")'),
'unit_orig',
desc=(
'name of the top-level Spicy parsing unit for the originator side '
'of the connection (e.g. "Request")'
),
),
zeekpkg.uservar.UserVar(
'unit_resp', desc='name of the top-level Spicy parsing unit for the responder side of the connection (e.g. "Reply"); may be the same as originator side'),
"unit_resp",
desc=(
'name of the top-level Spicy parsing unit for the responder side of '
'the connection (e.g. "Reply"); may be the same as originator side'
),
),
zeekpkg.uservar.UserVar(
'author', default=author, desc='your name and email address'),
zeekpkg.uservar.UserVar(
'license', desc='one of ' + ', '.join(License().license_keys(self)))
]

def apply_user_vars(self, uvars):
for uvar in uvars:
def apply_user_vars(self, user_vars):
# pylint: disable=too-many-branches
for uvar in user_vars:
if uvar.name() == 'name':
self.define_param('name', uvar.val())
self.define_param('slug', zeekpkg.uservar.slugify(uvar.val()))
Expand Down
Loading