Skip to content

Commit

Permalink
Add ADM validation CI job (#2)
Browse files Browse the repository at this point in the history
* Checkpoint for ADMs in YANG syntax
  • Loading branch information
BrianSipos authored Sep 3, 2024
1 parent 5a77a1a commit ea17dae
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Validate ADM modules with ACE
on:
push:
paths:
- .github/workflows/validate.yaml
- validate.sh
- "*.yang"
pull_request:
branches:
- main

env:
ACE_REPO: "git+https://github.com/JHUAPL-DTNMA/dtnma-ace.git@apl-fy24"

jobs:
validate:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Prep
run: |
pip3 install --upgrade pip
pip3 install ${ACE_REPO}
- name: Validate
run: ./validate.sh ietf-*.yang iana-*.yang
39 changes: 39 additions & 0 deletions validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -e

USAGE="Usage: $0 [filename] {... filename}"
if [ "$#" -eq "0" ]; then
echo "$USAGE"
exit 1
fi

SELFDIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}"))
LINTOPTS="--ietf --lint-ensure-hyphenated-names"
VALIDATE="ace_adm --path=${SELFDIR} ${LINTOPTS}"

# Validate a single ADM module file
# Arguments:
# 1: The file path to normalize
#
function validate {
FILEPATH=$1
shift

if [ ! -f "${FILEPATH}" ]; then
echo "File is missing: ${FILEPATH}"
exit 1
fi

echo "Validating ${FILEPATH}"
${VALIDATE} "${FILEPATH}"
}

ERRCOUNT=0
for FILEPATH in "$@"
do
if ! validate "${FILEPATH}"
then
ERRCOUNT=$(($ERRCOUNT + 1))
fi
done
exit ${ERRCOUNT}
53 changes: 53 additions & 0 deletions yang-normalize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
set -e

USAGE="Usage: $0 [filename] {... filename}"
if [ "$#" -eq "0" ]; then
echo "$USAGE"
exit 1
fi

SELFDIR=$(readlink -f $(dirname "${BASH_SOURCE[0]}"))
LINTOPTS="--ietf --lint-ensure-hyphenated-names"
OUTOPTS="-f yang --yang-canonical"
NORMALIZE="ace_adm --path=${SELFDIR} ${LINTOPTS} ${OUTOPTS}"

# Normalize a single YANG file
# Arguments:
# 1: The file path to normalize
#
function normalize {
FILEPATH=$1
shift

if [ ! -f "${FILEPATH}" ]; then
echo "File is missing: ${FILEPATH}"
exit 1
fi

# Canonicalize and normalize into ".out" file
EXT="${FILEPATH##*.}"
if [ "${EXT}" == "yang" ]; then
${NORMALIZE} "${FILEPATH}" >"${FILEPATH}.out"
else
echo "Cannot handle file with extension: ${EXT}"
exit 1
fi

if ! diff -q "${FILEPATH}.out" "${FILEPATH}" >/dev/null; then
mv "${FILEPATH}.out" "${FILEPATH}"
echo "Normalized ${FILEPATH}"
else
rm "${FILEPATH}.out"
fi
}

ERRCOUNT=0
for FILEPATH in "$@"
do
if ! normalize "${FILEPATH}"
then
ERRCOUNT=$(($ERRCOUNT + 1))
fi
done
exit ${ERRCOUNT}

0 comments on commit ea17dae

Please sign in to comment.