Skip to content

Commit 9b5fa75

Browse files
ssbarneaphilpep
andauthored
Migrate from travis to github (#581)
* Migrate from travis to github - removes travis config - adds github pipelines - refactors tox environment names to make them more generic, which will allow to easily extend them (new linters, extra packaging testing). * Fix somes tests with github actions Seems we can't send icmp ping from CI servers. Seems github uses hyperv as docker engine. Co-authored-by: Philippe Pepiot <[email protected]>
1 parent a6eebf5 commit 9b5fa75

File tree

4 files changed

+153
-36
lines changed

4 files changed

+153
-36
lines changed

.github/workflows/tox.yml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: tox
2+
3+
on:
4+
create: # is used for publishing to TestPyPI
5+
tags: # any tag regardless of its name, no branches
6+
- "**"
7+
push: # only publishes pushes to the main branch to TestPyPI
8+
branches: # any integration branch but not tag
9+
- "master"
10+
pull_request:
11+
release:
12+
types:
13+
- published # It seems that you can publish directly without creating
14+
schedule:
15+
- cron: 1 0 * * * # Run daily at 0:01 UTC
16+
17+
jobs:
18+
build:
19+
name: ${{ matrix.tox_env }}
20+
runs-on: ubuntu-latest
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
include:
25+
- tox_env: lint
26+
- tox_env: docs
27+
- tox_env: py36
28+
- tox_env: py37
29+
- tox_env: py38
30+
- tox_env: packaging
31+
32+
steps:
33+
- uses: actions/checkout@v1
34+
# Login needed to increase rate-limits
35+
- name: Login to DockerHub
36+
uses: docker/login-action@v1
37+
with:
38+
username: ${{ secrets.DOCKERHUB_USERNAME }}
39+
password: ${{ secrets.DOCKERHUB_TOKEN }}
40+
- name: Find python version
41+
id: py_ver
42+
shell: python
43+
if: ${{ contains(matrix.tox_env, 'py') }}
44+
run: |
45+
v = '${{ matrix.tox_env }}'.split('-')[0].lstrip('py')
46+
print('::set-output name=version::{0}.{1}'.format(v[0],v[1:]))
47+
# Even our lint and other envs need access to tox
48+
- name: Install a default Python
49+
uses: actions/setup-python@v2
50+
if: ${{ ! contains(matrix.tox_env, 'py') }}
51+
# Be sure to install the version of python needed by a specific test, if necessary
52+
- name: Set up Python version
53+
uses: actions/setup-python@v2
54+
if: ${{ contains(matrix.tox_env, 'py') }}
55+
with:
56+
python-version: ${{ steps.py_ver.outputs.version }}
57+
- name: Install dependencies
58+
run: |
59+
docker version
60+
docker info
61+
python -m pip install -U pip
62+
pip install tox
63+
- name: Run tox -e ${{ matrix.tox_env }}
64+
run: |
65+
echo "${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }}"
66+
${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }}
67+
68+
publish:
69+
name: Publish to PyPI registry
70+
needs:
71+
- build
72+
runs-on: ubuntu-latest
73+
74+
env:
75+
PY_COLORS: 1
76+
TOXENV: packaging
77+
78+
steps:
79+
- name: Switch to using Python 3.6 by default
80+
uses: actions/setup-python@v2
81+
with:
82+
python-version: 3.6
83+
- name: Install tox
84+
run: python -m pip install --user tox
85+
- name: Check out src from Git
86+
uses: actions/checkout@v2
87+
with:
88+
# Get shallow Git history (default) for release events
89+
# but have a complete clone for any other workflows.
90+
# Both options fetch tags but since we're going to remove
91+
# one from HEAD in non-create-tag workflows, we need full
92+
# history for them.
93+
fetch-depth: >-
94+
${{
95+
(
96+
(
97+
github.event_name == 'create' &&
98+
github.event.ref_type == 'tag'
99+
) ||
100+
github.event_name == 'release'
101+
) &&
102+
1 || 0
103+
}}
104+
- name: Drop Git tags from HEAD for non-tag-create and non-release events
105+
if: >-
106+
(
107+
github.event_name != 'create' ||
108+
github.event.ref_type != 'tag'
109+
) &&
110+
github.event_name != 'release'
111+
run: >-
112+
git tag --points-at HEAD
113+
|
114+
xargs git tag --delete
115+
- name: Build dists
116+
run: python -m tox
117+
- name: Publish to test.pypi.org
118+
if: >-
119+
(
120+
github.event_name == 'push' &&
121+
github.ref == format(
122+
'refs/heads/{0}', github.event.repository.default_branch
123+
)
124+
) ||
125+
(
126+
github.event_name == 'create' &&
127+
github.event.ref_type == 'tag'
128+
)
129+
uses: pypa/gh-action-pypi-publish@master
130+
with:
131+
password: ${{ secrets.testpypi_password }}
132+
repository_url: https://test.pypi.org/legacy/
133+
- name: Publish to pypi.org
134+
if: >- # "create" workflows run separately from "push" & "pull_request"
135+
github.event_name == 'release'
136+
uses: pypa/gh-action-pypi-publish@master
137+
with:
138+
password: ${{ secrets.pypi_password }}

.travis.yml

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

test/test_modules.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ def test_puppet_resource(host):
163163

164164
def test_facter(host):
165165
assert host.facter()["os"]["distro"]["codename"] == "buster"
166-
assert host.facter("virtual") == {"virtual": "docker"}
166+
assert host.facter("virtual") in (
167+
{"virtual": "docker"},
168+
{'virtual': 'hyperv'}, # github action uses hyperv
169+
)
167170

168171

169172
def test_sysctl(host):
@@ -572,13 +575,11 @@ def test_addr(host):
572575
google_dns = host.addr('8.8.8.8')
573576
assert google_dns.is_resolvable
574577
assert google_dns.ipv4_addresses == ['8.8.8.8']
575-
assert google_dns.is_reachable
576578
assert google_dns.port(53).is_reachable
577579
assert not google_dns.port(666).is_reachable
578580

579581
google_addr = host.addr('google.com')
580582
assert google_addr.is_resolvable
581-
assert google_addr.is_reachable
582583
assert google_addr.port(443).is_reachable
583584
assert not google_addr.port(666).is_reachable
584585

tox.ini

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
[tox]
2-
envlist=py3,flake8,sphinxdoc,check-manifest
2+
envlist=
3+
lint
4+
py{35,36,37,38,39}
5+
doc
6+
packaging
37

48
[testenv]
9+
description = Runs unittests
510
deps=
611
-rtest-requirements.txt
712
commands=
813
{envpython} -m pytest {posargs:-v -n 4 --cov testinfra --cov-report xml --cov-report term test}
914
usedevelop=True
1015
passenv=HOME TRAVIS DOCKER_CERT_PATH DOCKER_HOST DOCKER_TLS_VERIFY
1116

12-
[testenv:flake8]
17+
[testenv:lint]
18+
description = Performs linting tasks
1319
deps=hacking
1420
commands=flake8 {posargs}
1521

16-
[testenv:sphinxdoc]
22+
[testenv:docs]
1723
deps=-rdev-requirements.txt
1824
commands=sphinx-build -W -b html doc/source doc/build
1925

20-
[testenv:check-manifest]
26+
[testenv:packaging]
27+
description = Validate project packaging
2128
skip_install = true
2229
deps=
2330
check-manifest

0 commit comments

Comments
 (0)