Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Refactor Project Structure and Makefile Targets #357

Merged
merged 5 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
File renamed without changes.
5 changes: 3 additions & 2 deletions .ansible-lint → .config/ansible-lint.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
skip_list:
- yaml
- role-name
Expand Down Expand Up @@ -25,7 +26,7 @@ skip_list:
- var-naming[no-role-prefix]

exclude_paths:
- roles/consul/ # TODO - https://github.com/ansible-community/ansible-consul/pull/520
- .venv
- ../roles/consul/ # TODO - https://github.com/ansible-community/ansible-consul/pull/520
- ../.venv
# https://ansible-lint.readthedocs.io/configuring/
# https://ansible-lint.readthedocs.io/rules/
7 changes: 6 additions & 1 deletion .config/make/docker.mak
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ docker-build: ## Run docker build image in local

.PHONY: docker-lint
docker-lint: ## Run hadolint command to lint Dokerfile
docker run --rm -i hadolint/hadolint < .config/gitpod/Dockerfile
docker run --rm -i hadolint/hadolint < .config/gitpod/Dockerfile

.PHONY: docker-tests
docker-tests: ## Run tests for docker
$(MAKE) docker-build
$(MAKE) docker-lint
4 changes: 2 additions & 2 deletions .config/make/linters.mak
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ACTIVATE_VENV = source .venv/bin/activate

# Configuration files
YAMLLINT_CONFIG = .yamllint
YAMLLINT_CONFIG = .config/.yamllint
FLAKE8_CONFIG = .config/.flake8

.PHONY: linter-yamllint
Expand All @@ -17,7 +17,7 @@ linter-yamllint: ## Lint YAML files using yamllint
linter-ansible-lint: ## Lint Ansible files using ansible-lint
echo "ansible-lint #########################################################"
$(ACTIVATE_VENV) && \
ansible-lint --force-color --offline --parseable
ansible-lint --force-color --parseable

.PHONY: linter-flake8
linter-flake8: ## Lint Python files using flake8
Expand Down
2 changes: 1 addition & 1 deletion .config/make/python.mak
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Python default launcher
python_launcher ?= python3.10
python_requirements_file ?= requirements.txt
python_requirements_dev_file ?= .config/requirements.dev.txt
python_requirements_dev_file ?= .config/python/dev/requirements.txt

## —— Python —————————————————————————————————————————————————————————————————————————————————————
.PHONY: python-bootstrap
Expand Down
File renamed without changes.
18 changes: 12 additions & 6 deletions .github/workflows/ansible-lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Ansible-lint
name: "Ansible-lint"

on:
push:
Expand All @@ -17,10 +17,16 @@ jobs:
- name: Set TERM environment variable
run: echo "TERM=xterm" >> $GITHUB_ENV

- name: Git clone repo postgresql_cluster
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3

- name: Lint Ansible Playbook
uses: ansible/ansible-lint-action@v6
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
path: "roles/"
python-version: "3.10"

- name: Install dependencies
run: make bootstrap-dev

- name: Run Ansible-lint
run: make linter-ansible-lint
32 changes: 32 additions & 0 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: "Flake8"

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Set TERM environment variable
run: echo "TERM=xterm" >> $GITHUB_ENV

- name: Checkout
uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap-dev

- name: Run Flake8
run: make linter-flake8
2 changes: 1 addition & 1 deletion .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/molecule_pgpro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests for PostgresPro
run: make molecule-test-scenario
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_almalinux8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_almalinux9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_centos8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_centosstream8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_centosstream9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_debian10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_debian11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_oracle_linux8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_oracle_linux9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_rockylinux8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_rockylinux9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_ubuntu1804.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_ubuntu2004.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schedule_pg_ubuntu2204.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
python-version: "3.10"

- name: Install dependencies
run: make bootstrap
run: make bootstrap-dev

- name: Run Molecule tests
run: make molecule-test
Expand Down
25 changes: 12 additions & 13 deletions .github/workflows/yamllint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---

name: 'Yamllint'
name: "Yamllint"

on:
push:
Expand All @@ -17,17 +16,17 @@ jobs:
steps:
- name: Set TERM environment variable
run: echo "TERM=xterm" >> $GITHUB_ENV

- name: 'Checkout'
uses: actions/checkout@v2

- name: 'Run yamllint'
uses: karancode/yamllint-github-action@master
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
yamllint_file_or_dir: '.'
yamllint_strict: true
yamllint_comment: true
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
python-version: "3.10"

- name: Install dependencies
run: make bootstrap-dev

...
- name: Run Yamllint
run: make linter-yamllint
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ image:
file: .config/gitpod/Dockerfile

tasks:
- init: make bootstrap
- init: make bootstrap-dev
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Use Gitpod for a cloud-based development environment:
3. Open your fork in Gitpod: `https://gitpod.io/#https://github.com/username/postgresql_cluster`
4. Create a new branch: `git checkout -b my-feature-branch`
5. Make your changes and commit: `git add .` and `git commit -m "Description of changes"`
6. Test with Molecule: `make molecule-test` or `make molecule-converge`
7. Test with linters(otpional): `make lint`
6. Test with Molecule: `make tests` or `make tests-fast`
7. Test with linters: `make lint`
8. Push your changes: `git push origin my-feature-branch`
9. Create a pull request on GitHub
10. Wait for a review
Expand All @@ -48,7 +48,7 @@ Keep your Gitpod workspace synced with the main repository.

Install [make](https://www.gnu.org/software/make/), [Python3.10](https://www.python.org/), [venv](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/), and [docker](https://docs.docker.com/engine/install/ubuntu/).

Run `make` for Makefile help. Initialize virtualenv and install dependencies with `make reinitialization` or `make bootstrap`. Test your changes with `make molecule-test` or `make molecule-converge`.
Run `make` for Makefile help. Initialize virtualenv and install dependencies with `make reinitialization-dev` or `make bootstrap-dev`. Test your changes with `make tests` or `make molecule-converge`.

To test a specific distribution, set `distro`, `tag`, and `namespace`:

Expand Down
29 changes: 25 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all test SHELL
.PHONY: all SHELL

# Makefile global config
.DEFAULT_GOAL:=help
Expand Down Expand Up @@ -38,23 +38,44 @@ python_launcher := python$(shell cat .config/python_version.config | cut -d '='

-include $(addsuffix /*.mak, $(shell find .config/make -type d))

## —— Tests collection ———————————————————————————————————————————————————————————————————————
.PHONY: tests
tests: ## tests Ansible collection
$(MAKE) docker-tests
$(MAKE) lint
$(MAKE) molecule-test-all

.PHONY: tests-fast
tests-fast: ## tests Ansible collection quickly
$(MAKE) lint
$(MAKE) molecule-converge

## —— Bootstrap collection ———————————————————————————————————————————————————————————————————————
.PHONY: bootstrap
bootstrap: ## Bootstrap Ansible collection
$(MAKE) python-bootstrap

.PHONY: bootstrap-dev
bootstrap-dev: ## Bootstrap Ansible collection for development
$(MAKE) bootstrap
$(MAKE) python-bootstrap-dev

## —— Virtualenv ————————————————————————————————————————————————————————————————————————————————
.PHONY: reinitialization
reinitialization: ## Return to an initial state of Bootstrap Ansible collection
rm -rf .venv/
rm -rf vendor/
rm -f *.mak
$(MAKE) clean
$(MAKE) bootstrap

.PHONY: reinitialization-dev
reinitialization-dev: ## Return to an initial state of Bootstrap Ansible collection for development
$(MAKE) reinitialization
$(MAKE) bootstrap-dev

.PHONY: clean
clean: ## Clean collection
rm -rf .venv/
rm -rf vendor/
rm -f *.mak
rm -rf .pytest_cache/
rm -rf scripts/.pytest_cache/
rm -rf scripts/tests/__pycache__/
Expand Down