Skip to content

Commit

Permalink
Merge pull request #105 from netreplica/package
Browse files Browse the repository at this point in the history
PyPi Package
  • Loading branch information
bortok authored Mar 15, 2024
2 parents 190e87e + 7ac7260 commit ab584b0
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 81 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Publish Python distribution to PyPI and TestPyPI

on:
pull_request:
branches: [ "main" ]
push:
branches: [ "main", "dev" ]
tags: [ "v*" ]

jobs:
build:
name: Build distribution
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: make build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

publish-to-testpypi:
name: Publish to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: devtest
url: https://test.pypi.org/p/nrx

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

publish-to-pypi:
name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest

environment:
name: release
url: https://pypi.org/p/nrx

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ tests/*/d2/*
tests/main.conf
tmp
demo
dist
70 changes: 41 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
lint:
pylint nrx/*.py
pylint src/nrx/*.py

build:
python3 -m build

pubdev:
python3 -m twine upload --repository testpypi dist/*

publish:
python3 -m twine upload dist/*

clean:
rm dist/*

test-local: test-dc1 test-dc2 test-colo test-site1 test-h88
test-local-lrg: test-lrg-nb-2-cyjs-latest
Expand All @@ -24,7 +36,7 @@ test-args-site-and-sites:
@echo "#################################################################"
@echo "# Simulteneous use of site and sites should fail"
@echo "#################################################################"
! ./nrx.py --site dc1 --sites dc1,dc2 -d
! ./nrx --site dc1 --sites dc1,dc2 -d
@echo

test-dc1-nb-2-cyjs-current:
Expand All @@ -33,7 +45,7 @@ test-dc1-nb-2-cyjs-current:
@echo "#################################################################"
mkdir -p tests/dc1/test && cd tests/dc1/test && rm -rf * && \
source ../../.env_current && \
../../../nrx.py -c ../nrx.conf -o cyjs -d && \
../../../nrx -c ../nrx.conf -o cyjs -d && \
diff dc1.cyjs ../data/dc1.cyjs
@echo

Expand All @@ -43,7 +55,7 @@ test-dc1-nb-2-cyjs-latest:
@echo "#################################################################"
mkdir -p tests/dc1/test && cd tests/dc1/test && rm -rf * && \
source ../../.env_latest && \
../../../nrx.py -c ../nrx.conf -o cyjs -d && \
../../../nrx -c ../nrx.conf -o cyjs -d && \
diff dc1.cyjs ../data/dc1.cyjs
@echo

Expand All @@ -53,7 +65,7 @@ test-dc1-nb-2-cyjs-single-site:
@echo "#################################################################"
mkdir -p tests/dc1/test && cd tests/dc1/test && rm -rf * && \
source ../../.env_current && \
../../../nrx.py -c ../nrx-no-site.conf -o cyjs --site dc1 -d && \
../../../nrx -c ../nrx-no-site.conf -o cyjs --site dc1 -d && \
diff dc1.cyjs ../data/dc1.cyjs
@echo

Expand All @@ -63,7 +75,7 @@ test-dc1-nb-2-cyjs-single-sites:
@echo "#################################################################"
mkdir -p tests/dc1/test && cd tests/dc1/test && rm -rf * && \
source ../../.env_current && \
../../../nrx.py -c ../nrx-no-site.conf -o cyjs --sites dc1 -d && \
../../../nrx -c ../nrx-no-site.conf -o cyjs --sites dc1 -d && \
diff dc1.cyjs ../data/dc1.cyjs
@echo

Expand All @@ -73,7 +85,7 @@ test-dc1-dc2-nb-2-cyjs-sites:
@echo "#################################################################"
mkdir -p tests/dc1/test && cd tests/dc1/test && rm -rf * && \
source ../../.env_current && \
../../../nrx.py -c ../nrx-no-site.conf -o cyjs --sites dc1,dc2 -d && \
../../../nrx -c ../nrx-no-site.conf -o cyjs --sites dc1,dc2 -d && \
diff dc1-dc2.cyjs ../data/dc1-dc2.cyjs
@echo

Expand All @@ -82,7 +94,7 @@ test-dc1-cyjs-2-clab:
@echo "# DC1: read from CYJS and export as Containerlab"
@echo "#################################################################"
mkdir -p tests/dc1/test && cd tests/dc1/test && rm -rf * && \
../../../nrx.py -c ../nrx.conf -i cyjs -f ../data/dc1.cyjs -d && \
../../../nrx -c ../nrx.conf -i cyjs -f ../data/dc1.cyjs -d && \
for f in *; do echo Comparing file $$f ...; diff $$f ../data/$$f || exit 1; done
@echo

Expand All @@ -91,7 +103,7 @@ test-dc1-cyjs-2-clab-custom-platform-map:
@echo "# DC1: read from CYJS and export as Containerlab using custom platform map"
@echo "#################################################################"
mkdir -p tests/dc1/test && cd tests/dc1/test && rm -rf * && \
../../../nrx.py -c ../nrx.conf -i cyjs -f ../data/dc1.cyjs -M ../platform_map.yaml -d && \
../../../nrx -c ../nrx.conf -i cyjs -f ../data/dc1.cyjs -M ../platform_map.yaml -d && \
for f in *; do echo Comparing file $$f ...; diff $$f ../custom-clab/$$f || exit 1; done
@echo

Expand All @@ -100,7 +112,7 @@ test-dc1-cyjs-2-graphite:
@echo "# DC1: read from CYJS and export as graphite"
@echo "#################################################################"
mkdir -p tests/dc1/graphite && cd tests/dc1/graphite && rm -rf * && \
../../../nrx.py -c ../nrx.conf -i cyjs -f ../data/dc1.cyjs -o graphite -d && \
../../../nrx -c ../nrx.conf -i cyjs -f ../data/dc1.cyjs -o graphite -d && \
for f in *; do echo Comparing file $$f ...; diff $$f ../data/$$f || exit 1; done
@echo

Expand All @@ -109,7 +121,7 @@ test-dc1-dc2-cyjs-2-graphite:
@echo "# DC1 and DC2: read from CYJS and export as graphite"
@echo "#################################################################"
mkdir -p tests/dc1/graphite && cd tests/dc1/graphite && rm -rf * && \
../../../nrx.py -c ../nrx-no-site.conf -i cyjs -f ../data/dc1-dc2.cyjs -o graphite -d && \
../../../nrx -c ../nrx-no-site.conf -i cyjs -f ../data/dc1-dc2.cyjs -o graphite -d && \
for f in *; do echo Comparing file $$f ...; diff $$f ../data/$$f || exit 1; done
@echo

Expand All @@ -118,7 +130,7 @@ test-dc1-cyjs-2-d2:
@echo "# DC1: read from CYJS and export as d2"
@echo "#################################################################"
mkdir -p tests/dc1/d2 && cd tests/dc1/d2 && rm -rf * && \
../../../nrx.py -c ../nrx.conf -i cyjs -f ../data/dc1.cyjs -o d2 -d && \
../../../nrx -c ../nrx.conf -i cyjs -f ../data/dc1.cyjs -o d2 -d && \
for f in *; do echo Comparing file $$f ...; diff $$f ../data/$$f || exit 1; done
@echo

Expand All @@ -136,7 +148,7 @@ test-dc2-nb-2-cyjs-current:
@echo "#################################################################"
mkdir -p tests/dc2/test && cd tests/dc2/test && rm -rf * && \
source ../../.env_current && \
../../../nrx.py -c ../nrx.conf -o cyjs -d && \
../../../nrx -c ../nrx.conf -o cyjs -d && \
diff dc2.cyjs ../data/dc2.cyjs.current
@echo

Expand All @@ -146,7 +158,7 @@ test-dc2-nb-2-cyjs-latest:
@echo "#################################################################"
mkdir -p tests/dc2/test && cd tests/dc2/test && rm -rf * && \
source ../../.env_latest && \
../../../nrx.py -c ../nrx.conf -o cyjs -d && \
../../../nrx -c ../nrx.conf -o cyjs -d && \
diff dc2.cyjs ../data/dc2.cyjs.latest
@echo

Expand All @@ -155,7 +167,7 @@ test-dc2-cyjs-2-graphite:
@echo "# DC2: read from CYJS and export as graphite"
@echo "#################################################################"
mkdir -p tests/dc2/graphite && cd tests/dc2/graphite && rm -rf * && \
../../../nrx.py -c ../nrx.conf -i cyjs -f ../data/dc2.cyjs -o graphite -d && \
../../../nrx -c ../nrx.conf -i cyjs -f ../data/dc2.cyjs -o graphite -d && \
for f in *; do echo Comparing file $$f ...; diff $$f ../data/$$f || exit 1; done
@echo

Expand All @@ -164,7 +176,7 @@ test-dc2-cyjs-2-cml:
@echo "# DC2: read from CYJS and export as CML"
@echo "#################################################################"
mkdir -p tests/dc2/test && cd tests/dc2/test && rm -rf * && \
../../../nrx.py -c ../nrx.conf -i cyjs -f ../data/dc2.cyjs -d && \
../../../nrx -c ../nrx.conf -i cyjs -f ../data/dc2.cyjs -d && \
for f in *; do echo Comparing file $$f ...; diff $$f ../data/$$f || exit 1; done
@echo

Expand All @@ -182,7 +194,7 @@ test-colo-nb-2-cyjs-current:
@echo "#################################################################"
mkdir -p tests/colo/test && cd tests/colo/test && rm -rf * && \
source ../../.env_current && \
../../../nrx.py -c ../nrx.conf -o cyjs -d && \
../../../nrx -c ../nrx.conf -o cyjs -d && \
diff colo.cyjs ../data/colo.cyjs
@echo

Expand All @@ -192,7 +204,7 @@ test-colo-nb-2-cyjs-latest:
@echo "#################################################################"
mkdir -p tests/colo/test && cd tests/colo/test && rm -rf * && \
source ../../.env_latest && \
../../../nrx.py -c ../nrx.conf -o cyjs -d && \
../../../nrx -c ../nrx.conf -o cyjs -d && \
diff colo.cyjs ../data/colo.cyjs
@echo

Expand All @@ -202,7 +214,7 @@ test-site1-nb-2-cyjs-current:
@echo "#################################################################"
mkdir -p tests/site1/test && cd tests/site1/test && rm -rf * && \
source ../../.env_current && \
../../../nrx.py -c ../nrx.conf -o cyjs -d && \
../../../nrx -c ../nrx.conf -o cyjs -d && \
diff site1.cyjs ../data/site1.cyjs
@echo

Expand All @@ -212,7 +224,7 @@ test-site1-nb-2-cyjs-latest:
@echo "#################################################################"
mkdir -p tests/site1/test && cd tests/site1/test && rm -rf * && \
source ../../.env_latest && \
../../../nrx.py -c ../nrx.conf -o cyjs -d && \
../../../nrx -c ../nrx.conf -o cyjs -d && \
diff site1.cyjs ../data/site1.cyjs
@echo

Expand All @@ -221,7 +233,7 @@ test-site1-cyjs-2-clab:
@echo "# Site1: read from CYJS and export as Containerlab"
@echo "#################################################################"
mkdir -p tests/site1/test && cd tests/site1/test && rm -rf * && \
../../../nrx.py -c ../nrx.conf -i cyjs -f ../data/site1.cyjs -o clab -d && \
../../../nrx -c ../nrx.conf -i cyjs -f ../data/site1.cyjs -o clab -d && \
for f in *; do echo Comparing file $$f ...; diff $$f ../data/$$f || exit 1; done
@echo

Expand All @@ -230,7 +242,7 @@ test-site1-cyjs-2-clab-rename:
@echo "# Site1: read from CYJS and export as Containerlab with a custom name"
@echo "#################################################################"
mkdir -p tests/site1/test && cd tests/site1/test && rm -rf * && \
../../../nrx.py -c ../nrx.conf -i cyjs -f ../data/site1.cyjs -o clab --name ABC -d && \
../../../nrx -c ../nrx.conf -i cyjs -f ../data/site1.cyjs -o clab --name ABC -d && \
for f in *; do echo Comparing file $$f ...; diff $$f ../data/$$f || exit 1; done
@echo

Expand All @@ -240,7 +252,7 @@ test-site1-cyjs-template-2-clab:
@echo "#################################################################"
mkdir -p tests/site1/test && cd tests/site1/test && rm -rf * && \
cat ../data/site1.cyjs.template | envsubst > site1.sonic-vs.cyjs && \
../../../nrx.py -c ../nrx.conf -i cyjs -f site1.sonic-vs.cyjs -o clab -d && \
../../../nrx -c ../nrx.conf -i cyjs -f site1.sonic-vs.cyjs -o clab -d && \
for f in *.yaml; do echo Comparing file $$f ...; diff $$f ../data/$$f || exit 1; done
@echo

Expand All @@ -251,7 +263,7 @@ test-h88-nb-2-cyjs-current:
@echo "#################################################################"
mkdir -p tests/h88/test && cd tests/h88/test && rm -rf * && \
source ../../.env_current && \
../../../nrx.py -c ../nrx.conf -o cyjs -d && \
../../../nrx -c ../nrx.conf -o cyjs -d && \
diff HQ.cyjs ../data/HQ.cyjs.current
@echo

Expand All @@ -261,7 +273,7 @@ test-h88-nb-2-cyjs-latest:
@echo "#################################################################"
mkdir -p tests/h88/test && cd tests/h88/test && rm -rf * && \
source ../../.env_latest && \
../../../nrx.py -c ../nrx.conf -o cyjs -d && \
../../../nrx -c ../nrx.conf -o cyjs -d && \
diff HQ.cyjs ../data/HQ.cyjs.latest
@echo

Expand All @@ -271,7 +283,7 @@ test-h88-nb-2-cyjs-latest-noconfigs:
@echo "#################################################################"
mkdir -p tests/h88/test && cd tests/h88/test && rm -rf * && \
source ../../.env_latest && \
../../../nrx.py -c ../nrx.conf -o cyjs -d --noconfigs && \
../../../nrx -c ../nrx.conf -o cyjs -d --noconfigs && \
diff HQ.cyjs ../data/HQ.cyjs.noconfigs
@echo

Expand All @@ -280,7 +292,7 @@ test-h88-cyjs-2-clab:
@echo "# h88: read from CYJS and export as Containerlab"
@echo "#################################################################"
mkdir -p tests/h88/test && cd tests/h88/test && rm -rf * && \
../../../nrx.py -c ../nrx.conf -i cyjs -f ../data/HQ.cyjs -o clab -d && \
../../../nrx -c ../nrx.conf -i cyjs -f ../data/HQ.cyjs -o clab -d && \
for f in *; do echo Comparing file $$f ...; diff $$f ../data/$$f || exit 1; done
@echo

Expand All @@ -298,7 +310,7 @@ test-lrg-nb-2-cyjs-latest:
@echo "#################################################################"
mkdir -p tests/lrg/test && cd tests/lrg/test && rm -rf * && \
source ../../.env_latest && \
../../../nrx.py -c ../nrx.conf -o cyjs --noconfigs -d && \
../../../nrx -c ../nrx.conf -o cyjs --noconfigs -d && \
diff lrg.cyjs ../data/lrg.cyjs
@echo

Expand All @@ -307,7 +319,7 @@ test-lrg-cyjs-2-graphite:
@echo "# LRG: read from CYJS and export as graphite"
@echo "#################################################################"
mkdir -p tests/lrg/graphite && cd tests/lrg/graphite && rm -rf * && \
../../../nrx.py -c ../nrx.conf -i cyjs -f ../data/lrg.cyjs -o graphite -d && \
../../../nrx -c ../nrx.conf -i cyjs -f ../data/lrg.cyjs -o graphite -d && \
for f in *; do echo Comparing file $$f ...; diff $$f ../data/$$f || exit 1; done
@echo

Loading

0 comments on commit ab584b0

Please sign in to comment.