Skip to content

Commit 15346af

Browse files
Migrated from TravisCI to Github Actions (#384)
1 parent eaa067f commit 15346af

File tree

4 files changed

+1004
-0
lines changed

4 files changed

+1004
-0
lines changed

.github/workflows/main.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: All CI related tasks
2+
3+
# Run this workflow every time a new commit pushed to your repository
4+
on: [push, pull_request]
5+
6+
jobs:
7+
linting_unit_testing:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
python-version: [3.6, 3.7]
13+
steps:
14+
- name: Checkout repo
15+
uses: actions/checkout@v2
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
- name: Install and configure Poetry
21+
uses: snok/install-poetry@v1.1.1
22+
with:
23+
virtualenvs-create: false
24+
- name: Install Python packages
25+
run: poetry install
26+
- name: Build and install collection
27+
run: |
28+
ansible-galaxy collection build .
29+
ansible-galaxy collection install netbox*.tar.gz -p /home/runner/.ansible/collections
30+
- name: Run Black
31+
run: black . --check --diff
32+
- name: Run Ansible Sanity tests
33+
run: ansible-test sanity -v --requirements --python ${{ matrix.python-version }} --skip-test pep8 plugins/
34+
working-directory: /home/runner/.ansible/collections/ansible_collections/netbox/netbox
35+
- name: Run Ansible Unit tests
36+
run: ansible-test units -v --coverage --python ${{ matrix.python-version }}
37+
working-directory: /home/runner/.ansible/collections/ansible_collections/netbox/netbox
38+
- name: Run Ansible Coverage
39+
run: ansible-test coverage report --all --omit "tests/*,hacking/*,docs/*" --show-missing
40+
working-directory: /home/runner/.ansible/collections/ansible_collections/netbox/netbox
41+
integration:
42+
runs-on: ubuntu-latest
43+
needs: linting_unit_testing
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
include:
48+
- python-version: 3.6
49+
VERSION: "v2.8"
50+
INTEGRATION_TESTS: "v2.8"
51+
- python-version: 3.6
52+
VERSION: "v2.9"
53+
INTEGRATION_TESTS: "latest"
54+
steps:
55+
- name: Checkout repo
56+
uses: actions/checkout@v2
57+
- name: Set up Python ${{ matrix.python-version }}
58+
uses: actions/setup-python@v2
59+
with:
60+
python-version: ${{ matrix.python-version }}
61+
- name: Clone & Start netbox-docker containers
62+
if: matrix.VERSION != 'v2.8'
63+
run: |
64+
cd ..
65+
git clone https://github.com/netbox-community/netbox-docker.git
66+
cd netbox-docker
67+
docker-compose up -d --quiet-pull
68+
docker container ls
69+
cd ..
70+
- name: Clone & Start netbox-docker containers - NetBox v2.8
71+
if: matrix.VERSION == 'v2.8'
72+
run: |
73+
cd ..
74+
git clone https://github.com/netbox-community/netbox-docker.git
75+
cd netbox-docker
76+
git checkout 0.24.1
77+
sed -i 's/SKIP_STARTUP_SCRIPTS=false/SKIP_STARTUP_SCRIPTS=true/' env/netbox.env
78+
export VERSION=${{ matrix.VERSION }}
79+
docker-compose up -d --quiet-pull
80+
docker container ls
81+
cd ..
82+
- name: Build and install collection
83+
run: |
84+
ansible-galaxy collection build .
85+
ansible-galaxy collection install netbox*.tar.gz -p /home/runner/.ansible/collections
86+
- name: Wait for NetBox to be available
87+
run: |
88+
docker container ls
89+
docker logs netbox-docker_netbox_1
90+
timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:32768)" != "200" ]]; do echo "waiting for Netbox"; sleep 5; done' || false
91+
working-directory: /home/runner/.ansible/collections/ansible_collections/netbox/netbox
92+
- name: Install and configure Poetry
93+
uses: snok/install-poetry@v1.1.1
94+
with:
95+
virtualenvs-create: false
96+
- name: Install Python packages
97+
run: poetry install
98+
- name: Pre-populate NetBox
99+
run: ./tests/integration/netbox-deploy.py
100+
working-directory: /home/runner/.ansible/collections/ansible_collections/netbox/netbox
101+
- name: Allow scripts to be executed
102+
# Set runme.sh execute permissions stripped by ansible-galaxy. Should be fixed in Ansible 2.10
103+
# https://github.com/ansible/ansible/issues/68415
104+
# Run render_config.sh to pass environment variables to integration tests
105+
# https://www.ansible.com/blog/adding-integration-tests-to-ansible-content-collections
106+
run: |
107+
chmod +x tests/integration/targets/inventory-${{ matrix.INTEGRATION_TESTS }}/runme.sh
108+
chmod +x tests/integration/targets/inventory-${{ matrix.INTEGRATION_TESTS }}/compare_inventory_json.py
109+
chmod +x tests/integration/render_config.sh
110+
tests/integration/render_config.sh tests/integration/targets/inventory/runme_config.template > tests/integration/targets/inventory-${{ matrix.INTEGRATION_TESTS }}/runme_config
111+
working-directory: /home/runner/.ansible/collections/ansible_collections/netbox/netbox
112+
- name: Run integration tests
113+
# Run regression and integration tests
114+
# Run the inventory test first, in case any of the other tests modify the data.
115+
run: |
116+
ansible-test integration -v --coverage --python ${{ matrix.python-version }} inventory-${{ matrix.INTEGRATION_TESTS }}
117+
ansible-test integration -v --coverage --python ${{ matrix.python-version }} regression-${{ matrix.INTEGRATION_TESTS }}
118+
ansible-test integration -v --coverage --python ${{ matrix.python-version }} ${{ matrix.INTEGRATION_TESTS }}
119+
ansible-test coverage report --all --omit "tests/*,hacking/*,docs/*" --show-missing
120+
working-directory: /home/runner/.ansible/collections/ansible_collections/netbox/netbox

.github/workflows/release.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Deploy collection to Ansible Galaxy
2+
on:
3+
create:
4+
tags:
5+
- "v*"
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout repo
11+
uses: actions/checkout@v2
12+
- name: Set up Python 3.6
13+
uses: actions/setup-python@v2
14+
with:
15+
python-version: 3.6
16+
- name: Install ansible-base to deploy collection
17+
run: pip install ansible-base
18+
- name: Build and Deploy Collection
19+
uses: artis3n/ansible_galaxy_collection@v2
20+
with:
21+
api_key: "${{ secrets.GALAXY_API_KEY }}"

0 commit comments

Comments
 (0)