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

Add a CONTRIBUTING.md file and Makefile to guide new contributors #305

Merged
merged 21 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
560ed21
🆕 chore(Makefile): add Makefile with global configuration and help me…
ThomasSanson Apr 21, 2023
b422bd0
🆕 feat(Makefile): add help command
ThomasSanson Apr 21, 2023
45d5649
🔧 chore(Makefile): update python_launcher to version 3.10
ThomasSanson Apr 21, 2023
b9f109b
🆕 feat(makefile): add yaml makefile
ThomasSanson Apr 21, 2023
163447f
🎉 feat(molecule.mak): add molecule make targets
ThomasSanson Apr 21, 2023
722b6c1
🔥 chore(Makefile): add clean and reinitialization targets
ThomasSanson Apr 21, 2023
85ba8a0
🔥 chore(.gitignore): add .venv to ignore list
ThomasSanson Apr 21, 2023
d5254da
🔧 chore(Makefile): remove yaml.mak and molecule-bootstrap target
ThomasSanson Apr 21, 2023
5051a2e
🎉 feat(CONTRIBUTING.md): add CONTRIBUTING.md file
ThomasSanson Apr 22, 2023
ecb4e58
📝 docs(CONTRIBUTING.md): fix typos and improve readability
ThomasSanson Apr 22, 2023
760cdda
📝 docs(CONTRIBUTING.md): update link to pull request documentation
ThomasSanson Apr 22, 2023
a29b98d
🔀 merge(python): update python requirements files
ThomasSanson Apr 23, 2023
4834783
Merge branch 'vitabaks:master' into master
ThomasSanson Apr 23, 2023
9c08ec1
🐛 fix(CONTRIBUTING.md): add sudo to apt update command
ThomasSanson Apr 23, 2023
230fa1b
📝 docs(CONTRIBUTING.md): add instructions for contributing with Gitpod
ThomasSanson Apr 23, 2023
6ebc44d
📝 docs(CONTRIBUTING.md): update sponsor links
ThomasSanson Apr 23, 2023
236a6c1
📝 docs(CONTRIBUTING.md): add instructions to test changes with Molecule
ThomasSanson Apr 24, 2023
851a78f
🎉 feat(docker.mak): add docker-build and docker-lint targets
ThomasSanson Apr 24, 2023
6b6d98c
🐛 fix(.gitpod.yml): correct typo in bootstrap task name
ThomasSanson Apr 24, 2023
866e603
Merge branch 'master' into master
ThomasSanson Apr 24, 2023
a14a145
📝 docs(CONTRIBUTING.md): update contributing guide
ThomasSanson Apr 25, 2023
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
5 changes: 5 additions & 0 deletions .config/make/help.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## —— Help ———————————————————————————————————————————————————————————————————————————————————————
.PHONY: help
help: ## Help command
echo -e "$$HEADER"
grep -E '(^[a-zA-Z0-9_-]+:.*?## .*$$)|(^## )' $(MAKEFILE_LIST) | sed 's/^[^:]*://g' | awk 'BEGIN {FS = ":.*?## | #"} ; {printf "${cyan}%-30s${reset} ${white}%s${reset} ${green}%s${reset}\n", $$1, $$2, $$3}' | sed -e 's/\[36m##/\n[32m##/'
61 changes: 61 additions & 0 deletions .config/make/molecule.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## —— Molecule ———————————————————————————————————————————————————————————————————————————————————
.PHONY: molecule-test
molecule-test: ## Run test sequence for default scenario
source .venv/bin/activate
molecule test

.PHONY: molecule-destroy
molecule-destroy: ## Run destroy sequence for default scenario
source .venv/bin/activate
molecule destroy

.PHONY: molecule-converge
molecule-converge: ## Run converge sequence for default scenario
source .venv/bin/activate
molecule converge

.PHONY: molecule-reconverge
molecule-reconverge: ## Run destroy and converge sequence for default scenario
source .venv/bin/activate
molecule destroy
molecule converge

.PHONY: molecule-test-all
molecule-test-all: ## Run test sequence for all scenarios
source .venv/bin/activate
molecule test --all

.PHONY: molecule-destroy-all
molecule-destroy-all: ## Run destroy sequence for all scenarios
source .venv/bin/activate
molecule destroy --all

.PHONY: molecule-test-scenario
molecule-test-scenario: ## Run molecule test with specific scenario (example: make molecule-test-scenario MOLECULE_SCENARIO="using_maven_repo")
source .venv/bin/activate
molecule test --scenario-name $(MOLECULE_SCENARIO)

.PHONY: molecule-destroy-scenario
molecule-destroy-scenario: ## Run molecule destroy with specific scenario (example: make molecule-destroy-scenario MOLECULE_SCENARIO="using_maven_repo")
source .venv/bin/activate
molecule destroy --scenario-name $(MOLECULE_SCENARIO)

.PHONY: molecule-converge-scenario
molecule-converge-scenario: ## Run molecule converge with specific scenario (example: make molecule-converge-scenario MOLECULE_SCENARIO="using_maven_repo")
source .venv/bin/activate
molecule converge --scenario-name $(MOLECULE_SCENARIO)

.PHONY: molecule-dependency
molecule-dependency: ## Run dependency sequence
source .venv/bin/activate
molecule dependency

.PHONY: molecule-verify
molecule-verify: ## Run verify sequence
source .venv/bin/activate
molecule verify

.PHONY: molecule-lint
molecule-lint: ## Run lint sequence
source .venv/bin/activate
molecule lint
75 changes: 75 additions & 0 deletions .config/make/python.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Python default launcher
python_launcher ?= python3.10
python_requirements_file ?= requirements.txt
python_requirements_dev_file ?= requirements.dev.txt

## —— Python —————————————————————————————————————————————————————————————————————————————————————
.PHONY: python-bootstrap
python-bootstrap: ## Bootstrap python
$(MAKE) python-venv-init
$(MAKE) python-venv-upgrade
$(MAKE) python-venv-requirements

.PHONY: python-bootstrap-dev
python-bootstrap-dev: ## Bootstrap python for dev env
$(MAKE) python-venv-requirements-dev
$(MAKE) python-venv-linters-install

# ===============================================================================================
# .venv
# ===============================================================================================
.PHONY: python-venv-init
python-venv-init: ## Create venv ".venv/" if not exist
if [ ! -d .venv ] ; then
$(python_launcher) -m venv .venv
fi

.PHONY: python-venv-upgrade
python-venv-upgrade: ## Upgrade venv with pip, setuptools and wheel
source .venv/bin/activate
pip install --upgrade pip setuptools wheel

.PHONY: python-venv-requirements
python-venv-requirements: ## Install or upgrade from $(python_requirements_file)
source .venv/bin/activate
pip install --upgrade --requirement $(python_requirements_file)

.PHONY: python-venv-requirements-dev
python-venv-requirements-dev: ## Install or upgrade from $(python_requirements_dev_file)
source .venv/bin/activate
pip install --upgrade --requirement $(python_requirements_dev_file)

.PHONY: python-venv-linters-install
python-venv-linters-install: ## Install or upgrade linters
source .venv/bin/activate
pip install --upgrade flake8

.PHONY: python-venv-purge
python-venv-purge: ## Remove venv ".venv/" folder
rm -rf .venv

# ===============================================================================================
# Utils
# ===============================================================================================
.PHONY: python-purge-cache
python-purge-cache: ## Purge cache to avoid used cached files
if [ -d .venv ] ; then
source .venv/bin/activate
pip cache purge
fi

.PHONY: python-version
python-version: ## Displays the python version used for the .venv
source .venv/bin/activate
$(python_launcher) --version

.PHONY: python-flake8
python-flake8: ## Run flake8 linter for python
source .venv/bin/activate
flake8 --config .config/.flake8

.PHONY: python-pytest
python-pytest: ## Run pytest to test python scripts
source .venv/bin/activate
cd scripts/
$(python_launcher) -m pytest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
.idea
.venv
127 changes: 127 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# [Please contribute](#please-contribute)

You can really make a difference by:

- [Making an issue](https://help.github.com/articles/creating-an-issue/). A well-described issue helps a lot. (Check the [known issues](https://github.com/search?q=user%3Avitabaks+is%3Aissue+state%3Aopen) first.)
- [Making a pull request](https://docs.github.com/fr/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) when you find an error in the code.

I will try to help and take every contribution seriously.

This is a great opportunity for me to learn how you use the role and also an opportunity for you to get into the habit of contributing to open-source software.

## [Step by step](#step-by-step)
vitabaks marked this conversation as resolved.
Show resolved Hide resolved

Here is how you can help, many steps are related to GitHub, not specifically to this project.

### [1. Make an issue.](#1-make-an-issue)

When you spot an issue, [create an issue](https://github.com/vitabaks/postgresql_cluster/issues).

Making the issue helps me and others to find similar problems in the future.

### [2. Fork the project.](#2-fork-the-project)

On the top right side of [the repository on GitHub](https://github.com/vitabaks/postgresql_cluster), click `fork`. This copies everything to your GitHub namespace.

### [3. Make the changes](#3-make-the-changes)

In your GitHub namespace, make the required changes.

I typically do that by cloning the repository (in your namespace) locally:

```
git clone git@github.com:YOURNAMESPACE/postgresql_cluster.git
```

Now you can start editing on your laptop.

### [4. Test your changes](#4-optionally-test-your-changes)


#### 4.1 Contributing with Gitpod

Gitpod is a cloud-based development environment platform that allows you to contribute to projects without setting up a local environment. You can use Gitpod to work on the `postgresql_cluster` project by following these steps:

1. **Sign up for Gitpod**: If you don't have a Gitpod account, sign up at https://gitpod.io using your GitHub account.

2. **Create a new fork**: If you haven't already, fork the `postgresql_cluster` repository by clicking the "Fork" button on the top-right corner of the repository's GitHub page (https://github.com/vitabaks/postgresql_cluster).

3. **Open your fork in Gitpod**: Replace the `username` in the following URL with your GitHub username and open it in a new browser tab: `https://gitpod.io/#https://github.com/username/postgresql_cluster`. This will launch a new Gitpod workspace with the `postgresql_cluster` project.

4. **Create a new branch**: In the Gitpod terminal, create a new branch for your changes:

```
git checkout -b my-feature-branch
```

Replace `my-feature-branch` with a descriptive name for your branch.

5. **Make your changes**: Modify the code, add new features, or fix existing issues in the project. Make sure to follow the project's coding guidelines and style.

6. **Commit your changes**: Once you've made your changes, stage and commit them using the following commands:

```
git add .
git commit -m "Add a brief description of your changes"
```

Replace the commit message with a clear and concise description of your changes.

7. **Push your changes**: Push your changes to your fork on GitHub:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the "Test your changes" item is missing here before pushing changes

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and tested on gitpod (working)


```
git push origin my-feature-branch
```

Replace `my-feature-branch` with the name of the branch you created in step 4.

8. **Create a pull request**: Go to your forked repository on GitHub and click on the "Pull requests" tab. Click on the "New pull request" button, select your branch from the "compare" dropdown, and follow the instructions to create a pull request.

9. **Wait for a review**: Your pull request will be reviewed by the project maintainers. They may request changes or provide feedback before merging your changes.

Remember to keep your Gitpod workspace up-to-date with the main repository by regularly syncing your fork and merging or rebasing the changes.

#### 4.2 Contributing on your desktop

Install [make](https://www.gnu.org/software/make/) and [Python3.10](https://www.python.org/) with [venv](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/) :

```
sudo apt update
sudo apt install -y make python3.10 python3.10-venv
vitabaks marked this conversation as resolved.
Show resolved Hide resolved
python3 -m pip install --upgrade pip
python3 -m pip install virtualenv
```

You also need [docker](https://docs.docker.com/engine/install/ubuntu/) installed.

And run `make`. You will see help from Makefile

```
make
```

Run `make reinitialization` or `make bootstrap` for initializing the virtualenv and installing all dependencies.

Then, run the test with `make molecule-test` or `make molecule-converge` for only the converge sequence.

If you want to test a specific distribution, set `distro`, optionally `tag`, and `namespace` :

```
IMAGE_DISTRO=rockylinux9 IMAGE_TAG=latest IMAGE_NAMESPACE=geerlingguy make molecule-converge
vitabaks marked this conversation as resolved.
Show resolved Hide resolved
```

Once it starts to work, you can push your code.

### [5. Make a pull request](#5-make-a-pull-request)

[GitHub](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork) has information on making pull requests.

In the comment box, you can [refer to the issue number](https://help.github.com/en/github/writing-on-github/autolinked-references-and-urls) by using #123, where 123 is the issue number.

### [6. Wait](#6-wait)

Now I'll get a message that you've added some code. Thank you, really.

CI starts to test your changes. You can follow the progress on GitHub.

Please consider sponsoring me via [github](https://github.com/sponsors/vitabaks) or [patreon](https://patreon.com/vitabaks).
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.PHONY: all test SHELL

# Makefile global config
.DEFAULT_GOAL:=help
.EXPORT_ALL_VARIABLES:
.ONESHELL:
.SILENT:
MAKEFLAGS += "-j$(NUM_CORES) -l$(NUM_CORES)"
MAKEFLAGS += --silent
SHELL:=/bin/bash

# Makefile colors config
bold=$(shell tput bold)
normal=$(shell tput sgr0)
errorTitle=$(shell tput setab 1 && tput bold && echo '\n')
recommendation=$(shell tput setab 4)
underline=$(shell tput smul)
reset=$(shell tput -Txterm sgr0)
black=$(shell tput setaf 0)
red=$(shell tput setaf 1)
green=$(shell tput setaf 2)
yellow=$(shell tput setaf 3)
blue=$(shell tput setaf 4)
magenta=$(shell tput setaf 5)
cyan=$(shell tput setaf 6)
white=$(shell tput setaf 7)

define HEADER
How to use me:
make && make bootstrap
make ${cyan}<target>${reset}

endef
export HEADER

python_launcher := python3.10

-include .config/make/help.mak
-include .config/make/python.mak
-include .config/make/molecule.mak

## —— Bootstrap collection ———————————————————————————————————————————————————————————————————————
.PHONY: bootstrap
bootstrap: ## Bootstrap Ansible collection
$(MAKE) python-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) bootstrap

.PHONY: clean
clean: ## Clean collection
rm -rf .venv/
rm -rf .pytest_cache/
rm -rf scripts/.pytest_cache/
rm -rf scripts/tests/__pycache__/
rm -rf scripts/modules/__pycache__/
rm -rf scripts/modules/services/__pycache__/
rm -rf scripts/modules/utils/__pycache__/
5 changes: 5 additions & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ansible-lint==6.15.0
yamllint==1.31.0
molecule==5.0.0
molecule-plugins[docker]==23.4.0
docker==6.0.1
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ansible>=2.7