Skip to content

Commit 446298f

Browse files
committed
Move from Travis CI to GHA
1 parent 499f828 commit 446298f

File tree

3 files changed

+201
-44
lines changed

3 files changed

+201
-44
lines changed

.github/workflows/ci.yml

+200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
---
2+
name: "CI"
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
7+
push:
8+
branches:
9+
- "master"
10+
- "develop"
11+
tags:
12+
- "v*"
13+
pull_request: ~
14+
jobs:
15+
build:
16+
runs-on: "ubuntu-20.04"
17+
env:
18+
PYTHON_VER: "3.7"
19+
NETBOX_VER: "v2.9.11"
20+
steps:
21+
- name: "Check out repository code"
22+
uses: "actions/checkout@v2"
23+
- name: "Setup environment"
24+
uses: "networktocode/gh-action-setup-poetry-environment@v3"
25+
- name: "Build Container"
26+
run: "poetry run invoke build"
27+
black:
28+
runs-on: "ubuntu-20.04"
29+
env:
30+
PYTHON_VER: "3.7"
31+
NETBOX_VER: "v2.9.11"
32+
steps:
33+
- name: "Check out repository code"
34+
uses: "actions/checkout@v3"
35+
- name: "Setup environment"
36+
uses: "networktocode/gh-action-setup-poetry-environment@v3"
37+
- name: "Build Container"
38+
run: "poetry run invoke build"
39+
- name: "Linting: black"
40+
run: "poetry run invoke black"
41+
needs:
42+
- "build"
43+
bandit:
44+
runs-on: "ubuntu-20.04"
45+
env:
46+
PYTHON_VER: "3.7"
47+
NETBOX_VER: "v2.9.11"
48+
steps:
49+
- name: "Check out repository code"
50+
uses: "actions/checkout@v3"
51+
- name: "Setup environment"
52+
uses: "networktocode/gh-action-setup-poetry-environment@v3"
53+
- name: "Build Container"
54+
run: "poetry run invoke build"
55+
- name: "Linting: bandit"
56+
run: "poetry run invoke bandit"
57+
needs:
58+
- "build"
59+
pydocstyle:
60+
runs-on: "ubuntu-20.04"
61+
env:
62+
PYTHON_VER: "3.7"
63+
NETBOX_VER: "v2.9.11"
64+
steps:
65+
- name: "Check out repository code"
66+
uses: "actions/checkout@v3"
67+
- name: "Setup environment"
68+
uses: "networktocode/gh-action-setup-poetry-environment@v3"
69+
- name: "Build Container"
70+
run: "poetry run invoke build"
71+
- name: "Linting: pydocstyle"
72+
run: "poetry run invoke pydocstyle"
73+
needs:
74+
- "build"
75+
pylint:
76+
runs-on: "ubuntu-20.04"
77+
env:
78+
PYTHON_VER: "3.7"
79+
NETBOX_VER: "v2.9.11"
80+
steps:
81+
- name: "Check out repository code"
82+
uses: "actions/checkout@v3"
83+
- name: "Setup environment"
84+
uses: "networktocode/gh-action-setup-poetry-environment@v3"
85+
- name: "Build Container"
86+
run: "poetry run invoke build"
87+
- name: "Linting: Pylint"
88+
run: "poetry run invoke pylint"
89+
needs:
90+
- "black"
91+
- "bandit"
92+
- "pydocstyle"
93+
unittest:
94+
strategy:
95+
fail-fast: true
96+
matrix:
97+
python-version: ["3.6", "3.7", "3.8"]
98+
netbox-version: ["v2.8.9", "v2.9.11", "v2.10.10", "v2.11.10"]
99+
runs-on: "ubuntu-20.04"
100+
env:
101+
PYTHON_VER: "${{ matrix.python-version }}"
102+
NETBOX_VER: "${{ matrix.netbox-version }}"
103+
steps:
104+
- name: "Check out repository code"
105+
uses: "actions/checkout@v3"
106+
- name: "Setup environment"
107+
uses: "networktocode/gh-action-setup-poetry-environment@v3"
108+
- name: "Build Container"
109+
run: "poetry run invoke build"
110+
- name: "Run Tests"
111+
run: "poetry run invoke unittest"
112+
needs:
113+
- "pylint"
114+
publish_gh:
115+
name: "Publish to GitHub"
116+
runs-on: "ubuntu-20.04"
117+
if: "startsWith(github.ref, 'refs/tags/v')"
118+
steps:
119+
- name: "Check out repository code"
120+
uses: "actions/checkout@v3"
121+
- name: "Set up Python"
122+
uses: "actions/setup-python@v4"
123+
with:
124+
python-version: "3.9"
125+
- name: "Install Python Packages"
126+
run: "pip install poetry"
127+
- name: "Set env"
128+
run: "echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV"
129+
- name: "Run Poetry Version"
130+
run: "poetry version $RELEASE_VERSION"
131+
- name: "Upload binaries to release"
132+
uses: "svenstaro/upload-release-action@v2"
133+
with:
134+
repo_token: "${{ secrets.NTC_GITHUB_TOKEN }}"
135+
file: "dist/*"
136+
tag: "${{ github.ref }}"
137+
overwrite: true
138+
file_glob: true
139+
needs:
140+
- "unittest"
141+
publish_pypi:
142+
name: "Push Package to PyPI"
143+
runs-on: "ubuntu-20.04"
144+
if: "startsWith(github.ref, 'refs/tags/v')"
145+
steps:
146+
- name: "Check out repository code"
147+
uses: "actions/checkout@v3"
148+
- name: "Set up Python"
149+
uses: "actions/setup-python@v4"
150+
with:
151+
python-version: "3.9"
152+
- name: "Install Python Packages"
153+
run: "pip install poetry"
154+
- name: "Set env"
155+
run: "echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV"
156+
- name: "Run Poetry Version"
157+
run: "poetry version $RELEASE_VERSION"
158+
- name: "Push to PyPI"
159+
uses: "pypa/gh-action-pypi-publish@release/v1"
160+
with:
161+
user: "__token__"
162+
password: "${{ secrets.PYPI_API_TOKEN }}"
163+
needs:
164+
- "unittest"
165+
slack-notify:
166+
needs:
167+
- "publish_gh"
168+
- "publish_pypi"
169+
name: "Send notification to the Slack"
170+
runs-on: "ubuntu-20.04"
171+
env:
172+
SLACK_WEBHOOK_URL: "${{ secrets.SLACK_WEBHOOK_URL }}"
173+
SLACK_MESSAGE: >-
174+
*NOTIFICATION: NEW-RELEASE-PUBLISHED*\n
175+
Repository: <${{ github.server_url }}/${{ github.repository }}|${{ github.repository }}>\n
176+
Release: <${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ github.ref_name }}|${{ github.ref_name }}>\n
177+
Published by: <${{ github.server_url }}/${{ github.actor }}|${{ github.actor }}>
178+
steps:
179+
- name: "Send a notification to Slack"
180+
# ENVs cannot be used directly in job.if. This is a workaround to check
181+
# if SLACK_WEBHOOK_URL is present.
182+
if: "${{ env.SLACK_WEBHOOK_URL != '' }}"
183+
uses: "slackapi/[email protected]"
184+
with:
185+
payload: |
186+
{
187+
"text": "${{ env.SLACK_MESSAGE }}",
188+
"blocks": [
189+
{
190+
"type": "section",
191+
"text": {
192+
"type": "mrkdwn",
193+
"text": "${{ env.SLACK_MESSAGE }}"
194+
}
195+
}
196+
]
197+
}
198+
env:
199+
SLACK_WEBHOOK_URL: "${{ secrets.SLACK_WEBHOOK_URL }}"
200+
SLACK_WEBHOOK_TYPE: "INCOMING_WEBHOOK"

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ ntc_netbox_plugin_onboarding.egg-info
22
__pycache__
33
*.swp
44
dist
5+
.vscode/

.travis.yml

-44
This file was deleted.

0 commit comments

Comments
 (0)