Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: refactored ci file, updates to pyproject #8

Merged
merged 2 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
# https://ansible-lint.readthedocs.io/en/latest/configuring/

skip_list: []

exclude_paths:
- ./contrib
- ./.venv
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.{yml,yaml,toml}]
[*.{yml,yaml,toml,py}]
indent_size = 2
142 changes: 54 additions & 88 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,11 @@ jobs:
- name: Check out the codebase
uses: actions/checkout@v3

- name: Setup python3
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install poetry into system
uses: gi0baro/setup-poetry-bin@v1

- name: Install dependencies
run: make install-deps

- name: Run linting tasks
run: make lint

integration-macos-native:
name: Integration on macOS (native)
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["macos-12"]
steps:
- name: Check out the codebase
uses: actions/checkout@v3

# Uncomment for debugging over SSH
# - name: Setup upterm.dev session for SSH debugging
# uses: lhotari/action-upterm@v1

- name: Update built-in macOS pip
run: make update-pip

- name: Install poetry into system
uses: gi0baro/setup-poetry-bin@v1
with:
Expand All @@ -65,49 +39,46 @@ jobs:
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies (cached)
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
env:
PY_COLORS: '1'
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('**/requirements.yml') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: make install-deps

- name: Test the playbook
run: make test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Idempotence check
run: |
IDEMPOTENCE=$(mktemp)
cd tests && poetry run ansible-playbook test.yml | tee -a ${IDEMPOTENCE}
tail ${IDEMPOTENCE} \
| grep -q 'changed=0.*failed=0' \
&& (echo 'Idempotence test: pass' && exit 0) \
|| (echo 'Idempotence test: fail' && exit 1)
env:
PY_COLORS: '1'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run linting tasks
run: make lint

integration-macos-molecule:
name: Integration check on macOS (molecule)
integration-linux-molecule:
name: Integration on Linux
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 4
matrix:
os: ["macos-12"]
os: ["ubuntu-latest"]
python-version: ["3.9"]
scenario: ["default-macos-on-localhost"]
scenario: ["default"]

steps:
- name: Check out the codebase
uses: actions/checkout@v3
with:
submodules: true

- name: Check out the actions/cache source
uses: actions/checkout@v3
with:
repository: actions/cache
ref: v3
path: .tmp/actions/cache

- name: Update built-in macOS pip
run: make update-pip
- name: Check out fix - make actions/cache@v3 run always, not only when job succeeds
run: |
sed -i -e '/ post-if: /d' .tmp/actions/cache/action.yml

- name: Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry into system
uses: gi0baro/setup-poetry-bin@v1
Expand All @@ -116,45 +87,47 @@ jobs:

- name: Load cached .venv
id: cached-poetry-dependencies
uses: actions/cache@v3
uses: ./.tmp/actions/cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies (cached)
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
env:
PY_COLORS: '1'
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('**/requirements.yml') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: make install-deps

- name: Run molecule tests
run: poetry run molecule test --scenario-name "${SCENARIO}" -- -v
- name: Test the playbook with molecule
run: poetry run molecule test --scenario-name "${SCENARIO}" -- -vvv --become
env:
SCENARIO: ${{ matrix.scenario }}
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

integration-linux-molecule:
name: Integration on Linux
integration-macos-molecule:
name: Integration on macOS
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 4
matrix:
os: ["ubuntu-latest"]
python-version: ["3.9"]
scenario: ["default"]
os: ["macos-12"]
scenario: ["default-macos-on-localhost"]

steps:
- name: Check out the codebase
uses: actions/checkout@v3
with:
submodules: true

- name: Setup python3
uses: actions/setup-python@v4
- name: Check out the actions/cache source
uses: actions/checkout@v3
with:
python-version: ${{ matrix.python-version }}
repository: actions/cache
ref: v3
path: .tmp/actions/cache

- name: Check out fix - make actions/cache@v3 run always, not only when job succeeds
run: |
sed -i -e '/ post-if: /d' .tmp/actions/cache/action.yml

- name: Install poetry into system
uses: gi0baro/setup-poetry-bin@v1
Expand All @@ -163,35 +136,28 @@ jobs:

- name: Load cached .venv
id: cached-poetry-dependencies
uses: actions/cache@v3
uses: ./.tmp/actions/cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies (cached)
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
env:
PY_COLORS: '1'
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('**/requirements.yml') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: make install-deps

- name: Run molecule tests
run: poetry run molecule test --scenario-name "${SCENARIO}" -- -v
- name: Test the playbook with molecule
run: poetry run molecule test --scenario-name "${SCENARIO}" -- -vvv --become
env:
SCENARIO: ${{ matrix.scenario }}
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish:
if: github.event.inputs.shouldPublish == 'yes' || github.ref == 'refs/heads/master'
needs:
- lint
- integration-macos-native
- integration-macos-molecule
- integration-linux-molecule
- integration-macos-molecule
runs-on: ubuntu-latest
steps:
- name: Publish to Ansible Galaxy
Expand Down
6 changes: 5 additions & 1 deletion .later.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ ansible:
# Global settings for all defined rules
rules:
# List of files to exclude
exclude_files: []
exclude_files:
- ./contrib
- ./.venv

version: "1.0"

...
1 change: 1 addition & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extends: default

ignore: |
contrib
.venv

# Overwrite above default rules
rules:
Expand Down
54 changes: 7 additions & 47 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
###

export ANSIBLE_FORCE_COLOR = 1
export ANSIBLE_JINJA2_NATIVE = true

export PY_COLORS = 1
export PYTHONIOENCODING = UTF-8
export LC_CTYPE = en_US.UTF-8
Expand All @@ -14,10 +12,7 @@ export LANG = en_US.UTF-8
# https://stackoverflow.com/questions/50009505/ansible-stdout-formatting
export ANSIBLE_STDOUT_CALLBACK = unixy

TASK_TAGS ?= "tpl-install tpl-update"
PLAYBOOK ?= test.yml
WORKDIR ?= ./tests
INVENTORY ?= inventory.yml
TASK_TAGS ?= "tpl-install,tpl-update"
REQS ?= requirements.yml
INSTALL_POETRY ?= true
POETRY_BIN ?= poetry
Expand All @@ -32,44 +27,23 @@ PY_PATH ?= $(shell which python3)
# -vvv - enable connection debugging
DEBUG_VERBOSITY ?= -vvv

TEST_PLAYBOOK = $(POETRY_RUNNER) ansible-playbook $(PLAYBOOK) -i $(INVENTORY) $(DEBUG_VERBOSITY)
TEST_IDEMPOTENT = $(TEST_PLAYBOOK) | tee /dev/tty | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1)

### Lint yaml files
lint: check-syntax
lint: later
$(POETRY_RUNNER) yamllint .
cd $(WORKDIR) && $(POETRY_RUNNER) ansible-lint $(PLAYBOOK) -c ../.ansible-lint
$(POETRY_RUNNER) ansible-lint . --force-color
.PHONY: lint

### Run tests
test:
cd $(WORKDIR) && $(TEST_PLAYBOOK)
.PHONY: test

test-idempotent:
cd $(WORKDIR) && $(TEST_IDEMPOTENT)
.PHONY: test-idempotent

test-install: TASK_TAGS="tpl-install"
test-install: test-tag

test-update: TASK_TAGS="tpl-update"
test-update: test-tag

test-tag:
cd $(WORKDIR) && $(TEST_PLAYBOOK) --tags $(TASK_TAGS)
.PHONY: test-tag

m-local:
$(POETRY_RUNNER) molecule test --scenario-name default-macos-on-localhost -- -vvv --tags $(TASK_TAGS)
$(POETRY_RUNNER) molecule test --scenario-name default-macos-on-localhost -- $(DEBUG_VERBOSITY) --tags $(TASK_TAGS)
.PHONY: m-local

m-remote:
$(POETRY_RUNNER) molecule test --scenario-name default-macos-over-ssh -- -vvv --tags $(TASK_TAGS)
$(POETRY_RUNNER) molecule test --scenario-name default-macos-over-ssh -- $(DEBUG_VERBOSITY) --tags $(TASK_TAGS)
.PHONY: m-remote

m-linux:
$(POETRY_RUNNER) molecule test --scenario-name default -- -vvv --tags $(TASK_TAGS)
$(POETRY_RUNNER) run molecule test --scenario-name default -- $(DEBUG_VERBOSITY) --tags $(TASK_TAGS)
.PHONY: m-linux

login-mac:
Expand All @@ -88,20 +62,6 @@ debug-version:
$(POETRY_RUNNER) ansible --version
.PHONY: debug-version

check:
cd $(WORKDIR) && $(TEST_PLAYBOOK) --check
.PHONY: check

### List all hostnames
ls-host:
cd $(WORKDIR) && $(POETRY_RUNNER) ansible all -i $(INVENTORY) -m shell -a "hostname;"
.PHONY: ls-host

### Check playbook syntax
check-syntax:
cd $(WORKDIR) && $(TEST_PLAYBOOK) --syntax-check
.PHONY: check-syntax

later:
$(POETRY_RUNNER) $(ANSIBLE_LATER_BIN) **/*.yml
.PHONY: later
Expand Down Expand Up @@ -138,4 +98,4 @@ endif
hooks:
$(POETRY_RUNNER) pre-commit install
$(POETRY_RUNNER) pre-commit autoupdate
.PHONY: hooks
.PHONY: install-hooks
Loading