11---
22name : " CI"
3- on : # yamllint disable-line rule:truthy
4- - " push"
5- - " pull_request"
3+ concurrency : # Cancel any existing runs of this workflow for this same PR
4+ group : " ${{ github.workflow }}-${{ github.ref }}"
5+ cancel-in-progress : true
6+ on : # yamllint disable-line rule:truthy rule:comments
7+ push :
8+ branches :
9+ - " main"
10+ - " develop"
11+ tags :
12+ - " v*"
13+ pull_request : ~
614
715env :
8- IMAGE_NAME : " netutils"
16+ INVOKE_NETUTILS_IMAGE_NAME : " netutils"
17+ INVOKE_NETUTILS_IMAGE_VER : " latest"
918
1019jobs :
11- black :
20+ ruff-format :
1221 runs-on : " ubuntu-24.04"
1322 env :
14- INVOKE_LOCAL : " True"
23+ INVOKE_NETUTILS_LOCAL : " True"
1524 steps :
1625 - name : " Check out repository code"
1726 uses : " actions/checkout@v4"
1827 - name : " Setup environment"
1928 uses : " networktocode/gh-action-setup-poetry-environment@v6"
2029 with :
21- python -version : " 3.13 "
22- - name : " Linting: black "
23- run : " poetry run invoke black "
24- bandit :
30+ poetry -version : " 1.8.5 "
31+ - name : " Linting: ruff format "
32+ run : " poetry run invoke ruff --action format "
33+ ruff-lint :
2534 runs-on : " ubuntu-24.04"
2635 env :
27- INVOKE_LOCAL : " True"
36+ INVOKE_NETUTILS_LOCAL : " True"
2837 steps :
2938 - name : " Check out repository code"
3039 uses : " actions/checkout@v4"
3140 - name : " Setup environment"
3241 uses : " networktocode/gh-action-setup-poetry-environment@v6"
3342 with :
34- python-version : " 3.13"
35- - name : " Linting: bandit"
36- run : " poetry run invoke bandit"
37- needs :
38- - " black"
43+ poetry-version : " 1.8.5"
44+ - name : " Linting: ruff"
45+ run : " poetry run invoke ruff --action lint"
3946 mypy :
4047 runs-on : " ubuntu-24.04"
4148 env :
42- INVOKE_LOCAL : " True"
49+ INVOKE_NETUTILS_LOCAL : " True"
4350 steps :
4451 - name : " Check out repository code"
4552 uses : " actions/checkout@v4"
@@ -50,94 +57,62 @@ jobs:
5057 - name : " Type-Hints: mypy"
5158 run : " poetry run invoke mypy"
5259 needs :
53- - " black "
54- pydocstyle :
55- runs-on : " ubuntu-24.04 "
56- env :
57- INVOKE_LOCAL : " True "
58- steps :
59- - name : " Check out repository code "
60- uses : " actions/checkout@v4 "
61- - name : " Setup environment "
62- uses : " networktocode/gh-action-setup-poetry-environment@v6 "
63- with :
64- python-version : " 3.13 "
65- - name : " Linting: pydocstyle "
66- run : " poetry run invoke pydocstyle "
67- needs :
68- - " black "
69- flake8 :
60+ - " ruff-format "
61+ - " ruff-lint "
62+ # Temporarily disabled due to issues with the docs build and needing best practices for NTC python builds.
63+ # check-docs-build :
64+ # runs-on : "ubuntu-24.04 "
65+ # env :
66+ # INVOKE_NETUTILS_LOCAL : "True "
67+ # steps:
68+ # - name: "Check out repository code "
69+ # uses: "actions/checkout@v4 "
70+ # - name: "Setup environment"
71+ # uses : "networktocode/gh-action-setup-poetry-environment@v6 "
72+ # with:
73+ # poetry-version: "1.8.5 "
74+ # - name: "Check Docs Build"
75+ # run: "poetry run invoke build-and-check-docs "
76+ poetry :
7077 runs-on : " ubuntu-24.04"
7178 env :
72- INVOKE_LOCAL : " True"
79+ INVOKE_NETUTILS_LOCAL : " True"
7380 steps :
7481 - name : " Check out repository code"
7582 uses : " actions/checkout@v4"
7683 - name : " Setup environment"
7784 uses : " networktocode/gh-action-setup-poetry-environment@v6"
7885 with :
79- python -version : " 3.13 "
80- - name : " Linting: flake8 "
81- run : " poetry run invoke flake8 "
86+ poetry -version : " 1.8.5 "
87+ - name : " Checking: poetry lock file "
88+ run : " poetry lock --check "
8289 needs :
83- - " black"
90+ - " ruff-format"
91+ - " ruff-lint"
92+ - " mypy"
93+ - " yamllint"
8494 yamllint :
8595 runs-on : " ubuntu-24.04"
8696 env :
87- INVOKE_LOCAL : " True"
97+ INVOKE_NETUTILS_LOCAL : " True"
8898 steps :
8999 - name : " Check out repository code"
90100 uses : " actions/checkout@v4"
91101 - name : " Setup environment"
92102 uses : " networktocode/gh-action-setup-poetry-environment@v6"
93103 with :
94- python -version : " 3.13 "
104+ poetry -version : " 1.8.5 "
95105 - name : " Linting: yamllint"
96106 run : " poetry run invoke yamllint"
97107 needs :
98- - " black"
99- build :
100- strategy :
101- fail-fast : true
102- matrix :
103- python-version : ["3.9", "3.10", "3.11", "3.12", "3.13"]
104- runs-on : " ubuntu-24.04"
105- env :
106- PYTHON_VER : " ${{ matrix.python-version }}"
107- steps :
108- - name : " Check out repository code"
109- uses : " actions/checkout@v4"
110- - name : " Setup environment"
111- uses : " networktocode/gh-action-setup-poetry-environment@v6"
112- - name : " Get image version"
113- run : " echo IMAGE_VER=`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV"
114- - name : " Set up Docker Buildx"
115- id : " buildx"
116- uses : " docker/setup-buildx-action@v1"
117- - name : " Build"
118- uses : " docker/build-push-action@v2"
119- with :
120- builder : " ${{ steps.buildx.outputs.name }}"
121- context : " ./"
122- push : false
123- tags : " ${{ env.IMAGE_NAME }}:${{ env.IMAGE_VER }}"
124- file : " ./Dockerfile"
125- cache-from : " type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
126- cache-to : " type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
127- build-args : |
128- PYTHON_VER=${{ env.PYTHON_VER }}
129- needs :
130- - " bandit"
131- - " mypy"
132- - " pydocstyle"
133- - " flake8"
134- - " yamllint"
108+ - " ruff-format"
109+ - " ruff-lint"
135110 pylint :
136111 runs-on : " ubuntu-24.04"
137112 strategy :
138113 fail-fast : true
139114 matrix :
140- python-version : ["3.13"]
115+ python-version : ["3.9", "3.10", "3.11", "3.12", "3. 13"]
141116 env :
142117 PYTHON_VER : " ${{ matrix.python-version }}"
143118 steps :
@@ -146,29 +121,29 @@ jobs:
146121 - name : " Setup environment"
147122 uses : " networktocode/gh-action-setup-poetry-environment@v6"
148123 - name : " Get image version"
149- run : " echo IMAGE_VER =`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV"
124+ run : " echo INVOKE_NETUTILS_IMAGE_VER =`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV"
150125 - name : " Set up Docker Buildx"
151126 id : " buildx"
152- uses : " docker/setup-buildx-action@v1 "
153- - name : " Load the image from cache "
154- uses : " docker/build-push-action@v2 "
127+ uses : " docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 " # v3.10.0
128+ - name : " Build "
129+ uses : " docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 " # v5.4.0
155130 with :
156131 builder : " ${{ steps.buildx.outputs.name }}"
157132 context : " ./"
158133 push : false
159134 load : true
160- tags : " ${{ env.IMAGE_NAME }}:${{ env.IMAGE_VER }}"
135+ tags : " ${{ env.INVOKE_NETUTILS_IMAGE_NAME }}:${{ env.INVOKE_NETUTILS_IMAGE_VER }}"
161136 file : " ./Dockerfile"
162- cache-from : " type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
163- cache-to : " type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
137+ cache-from : " type=gha,scope=${{ env.INVOKE_NETUTILS_IMAGE_NAME }}-${{ env.INVOKE_NETUTILS_IMAGE_VER }}-py${{ matrix.python-version }}"
138+ cache-to : " type=gha,scope=${{ env.INVOKE_NETUTILS_IMAGE_NAME }}-${{ env.INVOKE_NETUTILS_IMAGE_VER }}-py${{ matrix.python-version }}"
164139 build-args : |
165140 PYTHON_VER=${{ env.PYTHON_VER }}
166141 - name : " Debug: Show docker images"
167142 run : " docker image ls"
168143 - name : " Linting: Pylint"
169144 run : " poetry run invoke pylint"
170145 needs :
171- - " build "
146+ - " poetry "
172147 pytest :
173148 strategy :
174149 fail-fast : true
@@ -183,31 +158,27 @@ jobs:
183158 - name : " Setup environment"
184159 uses : " networktocode/gh-action-setup-poetry-environment@v6"
185160 - name : " Get image version"
186- run : " echo IMAGE_VER =`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV"
161+ run : " echo INVOKE_NETUTILS_IMAGE_VER =`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV"
187162 - name : " Set up Docker Buildx"
188163 id : " buildx"
189- uses : " docker/setup-buildx-action@v1 "
190- - name : " Load the image from cache "
191- uses : " docker/build-push-action@v2 "
164+ uses : " docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 " # v3.10.0
165+ - name : " Build "
166+ uses : " docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 " # v5.4.0
192167 with :
193168 builder : " ${{ steps.buildx.outputs.name }}"
194169 context : " ./"
195170 push : false
196171 load : true
197- tags : " ${{ env.IMAGE_NAME }}:${{ env.IMAGE_VER }}"
172+ tags : " ${{ env.INVOKE_NETUTILS_IMAGE_NAME }}:${{ env.INVOKE_NETUTILS_IMAGE_VER }}"
198173 file : " ./Dockerfile"
199- cache-from : " type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
200- cache-to : " type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
174+ cache-from : " type=gha,scope=${{ env.INVOKE_NETUTILS_IMAGE_NAME }}-${{ env.INVOKE_NETUTILS_IMAGE_VER }}-py${{ matrix.python-version }}"
175+ cache-to : " type=gha,scope=${{ env.INVOKE_NETUTILS_IMAGE_NAME }}-${{ env.INVOKE_NETUTILS_IMAGE_VER }}-py${{ matrix.python-version }}"
201176 build-args : |
202177 PYTHON_VER=${{ env.PYTHON_VER }}
203178 - name : " Debug: Show docker images"
204179 run : " docker image ls"
205180 - name : " Run Tests"
206181 run : " poetry run invoke pytest"
207- - name : " Install Optional Dependencies"
208- run : " poetry run poetry install --extras optionals"
209- - name : " Run Optional Tests"
210- run : " poetry run pytest tests/unit/test_lib_helpers_optionals.py tests/unit/test_acl.py"
211182 needs :
212183 - " pylint"
213184 publish_gh :
@@ -265,3 +236,38 @@ jobs:
265236 password : " ${{ secrets.PYPI_API_TOKEN }}"
266237 needs :
267238 - " pytest"
239+ slack-notify :
240+ needs :
241+ - " publish_gh"
242+ - " publish_pypi"
243+ runs-on : " ubuntu-24.04"
244+ env :
245+ SLACK_WEBHOOK_URL : " ${{ secrets.SLACK_WEBHOOK_URL }}"
246+ SLACK_MESSAGE : >-
247+ *NOTIFICATION: NEW-RELEASE-PUBLISHED*\n
248+ Repository: <${{ github.server_url }}/${{ github.repository }}|${{ github.repository }}>\n
249+ Release: <${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ github.ref_name }}|${{ github.ref_name }}>\n
250+ Published by: <${{ github.server_url }}/${{ github.actor }}|${{ github.actor }}>
251+ steps :
252+ - name : " Send a notification to Slack"
253+ # ENVs cannot be used directly in job.if. This is a workaround to check
254+ # if SLACK_WEBHOOK_URL is present.
255+ if : " env.SLACK_WEBHOOK_URL != ''"
256+ uses : " slackapi/slack-github-action@fcfb566f8b0aab22203f066d80ca1d7e4b5d05b3" # v1.27.1
257+ with :
258+ payload : |
259+ {
260+ "text": "${{ env.SLACK_MESSAGE }}",
261+ "blocks": [
262+ {
263+ "type": "section",
264+ "text": {
265+ "type": "mrkdwn",
266+ "text": "${{ env.SLACK_MESSAGE }}"
267+ }
268+ }
269+ ]
270+ }
271+ env :
272+ SLACK_WEBHOOK_URL : " ${{ secrets.SLACK_WEBHOOK_URL }}"
273+ SLACK_WEBHOOK_TYPE : " INCOMING_WEBHOOK"
0 commit comments