Skip to content

Commit f3e49fd

Browse files
committed
Use GHA as CI
1 parent 9ed2e7c commit f3e49fd

File tree

2 files changed

+237
-37
lines changed

2 files changed

+237
-37
lines changed

.github/workflows/ci.yml

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
---
2+
name: "CI"
3+
on: # yamllint disable-line rule:truthy rule:comments
4+
- "push"
5+
- "pull_request"
6+
7+
env:
8+
IMAGE_NAME: "netcompare"
9+
10+
jobs:
11+
black:
12+
runs-on: "ubuntu-20.04"
13+
env:
14+
INVOKE_LOCAL: "True"
15+
steps:
16+
- name: "Check out repository code"
17+
uses: "actions/checkout@v2"
18+
- name: "Setup environment"
19+
uses: "networktocode/gh-action-setup-poetry-environment@v2"
20+
- name: "Linting: black"
21+
run: "poetry run invoke black"
22+
bandit:
23+
runs-on: "ubuntu-20.04"
24+
env:
25+
INVOKE_LOCAL: "True"
26+
steps:
27+
- name: "Check out repository code"
28+
uses: "actions/checkout@v2"
29+
- name: "Setup environment"
30+
uses: "networktocode/gh-action-setup-poetry-environment@v2"
31+
- name: "Linting: bandit"
32+
run: "poetry run invoke bandit"
33+
needs:
34+
- "black"
35+
pydocstyle:
36+
runs-on: "ubuntu-20.04"
37+
env:
38+
INVOKE_LOCAL: "True"
39+
steps:
40+
- name: "Check out repository code"
41+
uses: "actions/checkout@v2"
42+
- name: "Setup environment"
43+
uses: "networktocode/gh-action-setup-poetry-environment@v2"
44+
- name: "Linting: pydocstyle"
45+
run: "poetry run invoke pydocstyle"
46+
needs:
47+
- "black"
48+
flake8:
49+
runs-on: "ubuntu-20.04"
50+
env:
51+
INVOKE_LOCAL: "True"
52+
steps:
53+
- name: "Check out repository code"
54+
uses: "actions/checkout@v2"
55+
- name: "Setup environment"
56+
uses: "networktocode/gh-action-setup-poetry-environment@v2"
57+
- name: "Linting: flake8"
58+
run: "poetry run invoke flake8"
59+
needs:
60+
- "black"
61+
yamllint:
62+
runs-on: "ubuntu-20.04"
63+
env:
64+
INVOKE_LOCAL: "True"
65+
steps:
66+
- name: "Check out repository code"
67+
uses: "actions/checkout@v2"
68+
- name: "Setup environment"
69+
uses: "networktocode/gh-action-setup-poetry-environment@v2"
70+
- name: "Linting: yamllint"
71+
run: "poetry run invoke yamllint"
72+
needs:
73+
- "black"
74+
build:
75+
strategy:
76+
fail-fast: true
77+
matrix:
78+
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
79+
runs-on: "ubuntu-20.04"
80+
env:
81+
PYTHON_VER: "${{ matrix.python-version }}"
82+
steps:
83+
- name: "Check out repository code"
84+
uses: "actions/checkout@v2"
85+
- name: "Setup environment"
86+
uses: "networktocode/gh-action-setup-poetry-environment@v2"
87+
- name: "Get image version"
88+
run: "echo IMAGE_VER=`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV"
89+
- name: "Set up Docker Buildx"
90+
id: "buildx"
91+
uses: "docker/setup-buildx-action@v1"
92+
- name: "Build"
93+
uses: "docker/build-push-action@v2"
94+
with:
95+
builder: "${{ steps.buildx.outputs.name }}"
96+
context: "./"
97+
push: false
98+
tags: "${{ env.IMAGE_NAME }}:${{ env.IMAGE_VER }}"
99+
file: "./Dockerfile"
100+
cache-from: "type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
101+
cache-to: "type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
102+
build-args: |
103+
PYTHON_VER=${{ env.PYTHON_VER }}
104+
needs:
105+
- "bandit"
106+
- "pydocstyle"
107+
- "flake8"
108+
- "yamllint"
109+
pylint:
110+
runs-on: "ubuntu-20.04"
111+
strategy:
112+
fail-fast: true
113+
matrix:
114+
python-version: ["3.7"]
115+
env:
116+
PYTHON_VER: "${{ matrix.python-version }}"
117+
steps:
118+
- name: "Check out repository code"
119+
uses: "actions/checkout@v2"
120+
- name: "Setup environment"
121+
uses: "networktocode/gh-action-setup-poetry-environment@v2"
122+
- name: "Get image version"
123+
run: "echo IMAGE_VER=`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV"
124+
- name: "Set up Docker Buildx"
125+
id: "buildx"
126+
uses: "docker/setup-buildx-action@v1"
127+
- name: "Load the image from cache"
128+
uses: "docker/build-push-action@v2"
129+
with:
130+
builder: "${{ steps.buildx.outputs.name }}"
131+
context: "./"
132+
push: false
133+
load: true
134+
tags: "${{ env.IMAGE_NAME }}:${{ env.IMAGE_VER }}"
135+
file: "./Dockerfile"
136+
cache-from: "type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
137+
cache-to: "type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
138+
build-args: |
139+
PYTHON_VER=${{ env.PYTHON_VER }}
140+
- name: "Debug: Show docker images"
141+
run: "docker image ls"
142+
- name: "Linting: Pylint"
143+
run: "poetry run invoke pylint"
144+
needs:
145+
- "build"
146+
pytest:
147+
strategy:
148+
fail-fast: true
149+
matrix:
150+
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
151+
runs-on: "ubuntu-20.04"
152+
env:
153+
PYTHON_VER: "${{ matrix.python-version }}"
154+
steps:
155+
- name: "Check out repository code"
156+
uses: "actions/checkout@v2"
157+
- name: "Setup environment"
158+
uses: "networktocode/gh-action-setup-poetry-environment@v2"
159+
- name: "Get image version"
160+
run: "echo IMAGE_VER=`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV"
161+
- name: "Set up Docker Buildx"
162+
id: "buildx"
163+
uses: "docker/setup-buildx-action@v1"
164+
- name: "Load the image from cache"
165+
uses: "docker/build-push-action@v2"
166+
with:
167+
builder: "${{ steps.buildx.outputs.name }}"
168+
context: "./"
169+
push: false
170+
load: true
171+
tags: "${{ env.IMAGE_NAME }}:${{ env.IMAGE_VER }}"
172+
file: "./Dockerfile"
173+
cache-from: "type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
174+
cache-to: "type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
175+
build-args: |
176+
PYTHON_VER=${{ env.PYTHON_VER }}
177+
- name: "Debug: Show docker images"
178+
run: "docker image ls"
179+
- name: "Run Tests"
180+
run: "poetry run invoke pytest"
181+
needs:
182+
- "pylint"
183+
publish_gh:
184+
name: "Publish to GitHub"
185+
runs-on: "ubuntu-20.04"
186+
if: "startsWith(github.ref, 'refs/tags/v')"
187+
steps:
188+
- name: "Check out repository code"
189+
uses: "actions/checkout@v2"
190+
- name: "Set up Python"
191+
uses: "actions/setup-python@v2"
192+
with:
193+
python-version: "3.9"
194+
- name: "Install Python Packages"
195+
run: "pip install poetry"
196+
- name: "Set env"
197+
run: "echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV"
198+
- name: "Run Poetry Version"
199+
run: "poetry version $RELEASE_VERSION"
200+
- name: "Run Poetry Build"
201+
run: "poetry build"
202+
- name: "Upload binaries to release"
203+
uses: "svenstaro/upload-release-action@v2"
204+
with:
205+
repo_token: "${{ secrets.NTC_GITHUB_TOKEN }}"
206+
file: "dist/*"
207+
tag: "${{ github.ref }}"
208+
overwrite: true
209+
file_glob: true
210+
needs:
211+
- "pytest"
212+
publish_pypi:
213+
name: "Push Package to PyPI"
214+
runs-on: "ubuntu-20.04"
215+
if: "startsWith(github.ref, 'refs/tags/v')"
216+
steps:
217+
- name: "Check out repository code"
218+
uses: "actions/checkout@v2"
219+
- name: "Set up Python"
220+
uses: "actions/setup-python@v2"
221+
with:
222+
python-version: "3.9"
223+
- name: "Install Python Packages"
224+
run: "pip install poetry"
225+
- name: "Set env"
226+
run: "echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV"
227+
- name: "Run Poetry Version"
228+
run: "poetry version $RELEASE_VERSION"
229+
- name: "Run Poetry Build"
230+
run: "poetry build"
231+
- name: "Push to PyPI"
232+
uses: "pypa/gh-action-pypi-publish@release/v1"
233+
with:
234+
user: "__token__"
235+
password: "${{ secrets.PYPI_API_TOKEN }}"
236+
needs:
237+
- "pytest"

.travis.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)