| 1 |
--- |
| 2 |
name: Python package |
| 3 |
|
| 4 |
on: |
| 5 |
push: |
| 6 |
branches: [ master ] |
| 7 |
pull_request: |
| 8 |
branches: [ master ] |
| 9 |
|
| 10 |
jobs: |
| 11 |
build: |
| 12 |
timeout-minutes: 20 |
| 13 |
strategy: |
| 14 |
fail-fast: true |
| 15 |
matrix: |
| 16 |
python-version: [3.6, 3.7, 3.8, 3.9] |
| 17 |
include: |
| 18 |
- os-version: ubuntu-latest |
| 19 |
- python-version: 3.6 |
| 20 |
os-version: ubuntu-20.04 |
| 21 |
runs-on: ${{ matrix.os-version }} |
| 22 |
|
| 23 |
|
| 24 |
steps: |
| 25 |
- name: Checkout branch with changes |
| 26 |
uses: actions/checkout@v2 |
| 27 |
with: |
| 28 |
path: current |
| 29 |
- name: Checkout master branch |
| 30 |
uses: actions/checkout@v2 |
| 31 |
with: |
| 32 |
path: master |
| 33 |
ref: master |
| 34 |
- name: Set up Node.js |
| 35 |
uses: actions/setup-node@v2 |
| 36 |
with: |
| 37 |
node-version: '14' |
| 38 |
- name: Set up Python ${{ matrix.python-version }} |
| 39 |
uses: actions/setup-python@v2 |
| 40 |
with: |
| 41 |
python-version: ${{ matrix.python-version }} |
| 42 |
- name: Setup environment variables |
| 43 |
run: | |
| 44 |
mkdir -p artifacts |
| 45 |
echo "wfdt=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_ENV |
| 46 |
- name: Install dependencies |
| 47 |
run: | |
| 48 |
sudo apt update |
| 49 |
sudo apt install unzip zip |
| 50 |
python -m pip install --upgrade pip |
| 51 |
python -m pip install setuptools wheel |
| 52 |
python -m pip install flake8 pytest |
| 53 |
cd current |
| 54 |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi |
| 55 |
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi |
| 56 |
- name: Lint with flake8 |
| 57 |
run: | |
| 58 |
cd current |
| 59 |
flake8 . --count --select=W291,W293,W391 --statistic |
| 60 |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
| 61 |
flake8 . --count --exit-zero --max-complexity=10 \ |
| 62 |
--max-line-length=127 --statistics |
| 63 |
- name: Test with pytest |
| 64 |
run: | |
| 65 |
cd current |
| 66 |
pytest |
| 67 |
- name: Perform end-to-end testing with current branch or pull request |
| 68 |
run: | |
| 69 |
cd current |
| 70 |
git status |
| 71 |
python setup.py sdist bdist_wheel |
| 72 |
python3 -m pip -v install dist/capirca*py3*.whl |
| 73 |
aclgen --output_directory ./output --logtostderr |
| 74 |
cd ./output/ && \ |
| 75 |
zip -r ../../artifacts/capirca_output_${{ env.wfdt }}.zip . |
| 76 |
cd .. |
| 77 |
python3 -m pip -v uninstall -y capirca |
| 78 |
- name: Perform end-to-end testing with master branch |
| 79 |
run: | |
| 80 |
cd master |
| 81 |
git status |
| 82 |
python setup.py sdist bdist_wheel |
| 83 |
python3 -m pip -v install dist/capirca*py3*.whl |
| 84 |
aclgen --output_directory ./output --logtostderr |
| 85 |
python3 -m pip -v uninstall -y capirca |
| 86 |
- name: Compare output files between the branches |
| 87 |
run: | |
| 88 |
mkdir -p artifacts-diff |
| 89 |
sudo npm install -g diff2html diff2html-cli |
| 90 |
diff2html --version |
| 91 |
diff -qr current/output master/output > \ |
| 92 |
./artifacts-diff/policy_output.diff | true |
| 93 |
cat ./artifacts-diff/policy_output.diff | grep Files | grep differ \ |
| 94 |
| cut -d" " -f2 | cut -d "/" -f3 > ./artifacts-diff/files.list |
| 95 |
while read p; do diff -u master/output/$p current/output/$p | \ |
| 96 |
diff2html -i stdin --file ./artifacts-diff/$p.html | \ |
| 97 |
true; done < ./artifacts-diff/files.list |
| 98 |
sed -i '/Diff to HTML by/d' ./artifacts-diff/* |
| 99 |
- name: Upload generated policies |
| 100 |
uses: actions/upload-artifact@v2 |
| 101 |
with: |
| 102 |
name: capirca_output_${{ matrix.python-version }}_${{ env.wfdt }} |
| 103 |
path: ./artifacts/capirca_output_${{ env.wfdt }}.zip |
| 104 |
- name: Upload policy differences |
| 105 |
uses: actions/upload-artifact@v2 |
| 106 |
with: |
| 107 |
name: capirca_output_policy_diff |
| 108 |
path: ./artifacts-diff |