forked from NASA-AMMOS/anms-adms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |