From 54d61fd50a837f6e9748e28998827c7c9b5560c3 Mon Sep 17 00:00:00 2001 From: Michal Muransky Date: Fri, 24 May 2024 16:31:55 +0200 Subject: [PATCH 1/4] docs: update readme --- README.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/README.md b/README.md index 6457cb3..d4abea0 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,7 @@ Same example as above, but runner will be added to an organization and deployed ``` If you have a Github Enterprise Cloud license and you want to manage all the self-hosted runners from the enterprise: + ```yaml --- - name: Install GitHub Actions Runner @@ -221,6 +222,78 @@ In this example the Ansible role will uninstall the runner service and unregiste - role: monolithprojects.github_actions_runner ``` +## Testing with Molecule + +[Molecule](https://molecule.readthedocs.io/) is a testing framework for Ansible. This section is for code contributors. + +### Prerequisites + +* Python +* Docker +* Ansible +* Molecule + +### Installation + +1. Install Python, Docker, and Ansible if you haven't already. +2. Install Molecule and its Docker driver with pip: + +```bash +pip install molecule[docker] +``` +Sure, here's a basic example of how you might structure a README to explain how to test the `monolithprojects.github_actions_runner` Ansible role with Molecule: + +```markdown +# monolithprojects.github_actions_runner + +This is an Ansible role for setting up GitHub Actions runners. + +## Testing with Molecule + +[Molecule](https://molecule.readthedocs.io/) is a testing framework for Ansible that we use to test the `monolithprojects.github_actions_runner` role. + +### Prerequisites + +- Python +- Docker +- Ansible +- Molecule + +### Installation + +1. Install Python, Docker, and Ansible if you haven't already. +2. Install Molecule and its Docker driver with pip: + +```bash +pip install molecule[docker] +``` + +### Running Tests + +1. Navigate to the role's directory: + +```bash +cd path/to/monolithprojects.github_actions_runner +``` + +2. Set Environment variables + +```bash +export PERSONAL_ACCESS_TOKEN=your_github_pat # Your Personal Access Token to Github +export GITHUB_ACCOUNT=your_account # Your Github Account +export GITHUB_ACCOUNT=your_repository # Github Repository where you want to setup the Runner +``` + +3. Run Molecule: + +```bash +molecule test +``` + +This will run the molecule test, create a Docker container, run the role against it, run any associated `default` tests (see [molecule/default](./molecule/default) directory), and then destroy the container. + +For more information on using Molecule, see the [Molecule documentation](https://molecule.readthedocs.io/). + ## License MIT From b5eb5ea5877f51bfc4e290c70d325705a6bc6bc6 Mon Sep 17 00:00:00 2001 From: Michal Muransky Date: Fri, 24 May 2024 16:39:13 +0200 Subject: [PATCH 2/4] docs: update contributing --- .github/CONTRIBUTING.md | 44 +++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 55d1505..48f411b 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -23,19 +23,51 @@ Install [Pre-commit](https://pre-commit.com/#install) software Do the changes in your own GitHub namespace. -## 5. Test the changes +## 5. Test the changes with Molecule -**Note:** I will test the role again, so you don't need to do that if you don't want to. +[Molecule](https://molecule.readthedocs.io/) is a testing framework for Ansible that we use to test the `monolithprojects.github_actions_runner` role. -Install [molecule](https://molecule.readthedocs.io/en/stable/) and run the test: +### Prerequisites + +- Python +- Docker +- Ansible +- Molecule + +### Installation + +1. Install Python, Docker, and Ansible if you haven't already. +2. Install Molecule and its Docker driver with pip: + +```bash +pip install molecule[docker] +``` + +### Running Tests + +1. Navigate to the role's directory: + +```bash +cd path/to/monolithprojects.github_actions_runner +``` + +2. Set Environment variables + +```bash +export PERSONAL_ACCESS_TOKEN=your_github_pat # Your Personal Access Token to Github +export GITHUB_ACCOUNT=your_account # Your Github Account +export GITHUB_ACCOUNT=your_repository # Github Repository where you want to setup the Runner +``` + +3. Run Molecule: ```bash -pip install molecule molecule-docker ansible-lint docker -cd ansible-github_actions_runner molecule test ``` -> You will need to edit the files in `molecule/default` directory (please do not commit those changes) +This will run the molecule test, create a Docker container, run the role against it, run any associated `default` tests (see [molecule/default](../molecule/default) directory), and then destroy the container. + +For more information on using Molecule, see the [Molecule documentation](https://molecule.readthedocs.io/). ## 6. Create a pull request From b96bd908735be1769db2db32a18e782a7e2bba14 Mon Sep 17 00:00:00 2001 From: Michal Muransky Date: Fri, 24 May 2024 16:40:41 +0200 Subject: [PATCH 3/4] ci: fix custom_env molecule test --- molecule/custom_env/cleanup.yml | 1 + molecule/custom_env/converge.yml | 1 + molecule/custom_env/verify.yml | 4 ++-- molecule/default/verify.yml | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/molecule/custom_env/cleanup.yml b/molecule/custom_env/cleanup.yml index 8969cf2..34bc208 100644 --- a/molecule/custom_env/cleanup.yml +++ b/molecule/custom_env/cleanup.yml @@ -8,5 +8,6 @@ github_repo: "{{ lookup('env', 'GITHUB_REPO') }}" github_account: "{{ lookup('env', 'GITHUB_ACCOUNT') }}" runner_state: absent + runner_name: test_name roles: - monolithprojects.github_actions_runner diff --git a/molecule/custom_env/converge.yml b/molecule/custom_env/converge.yml index 3d9afd0..bd8f486 100644 --- a/molecule/custom_env/converge.yml +++ b/molecule/custom_env/converge.yml @@ -9,6 +9,7 @@ github_repo: "{{ lookup('env', 'GITHUB_REPO') }}" github_account: "{{ lookup('env', 'GITHUB_ACCOUNT') }}" runner_version: "latest" + runner_name: test_name runner_labels: - label1 - repo-runner diff --git a/molecule/custom_env/verify.yml b/molecule/custom_env/verify.yml index 95b8028..cba84e6 100644 --- a/molecule/custom_env/verify.yml +++ b/molecule/custom_env/verify.yml @@ -10,7 +10,7 @@ github_account: "{{ lookup('env', 'GITHUB_ACCOUNT') }}" github_api_url: "https://api.github.com" access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}" - runner_name: ubuntu16-latest + runner_name: test_name tasks: - name: Check currently registered runners @@ -32,7 +32,7 @@ ansible.builtin.assert: that: - runner_name in registered_runners.json.runners|map(attribute='name')|list - - registered_runners.json.runners|map(attribute='status') == ["online"] + - registered_runners.json.runners.0.status == "online" quiet: true - name: Check Labels (skipped if labels are OK) diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index dd95a09..a987064 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -10,7 +10,7 @@ github_account: "{{ lookup('env', 'GITHUB_ACCOUNT') }}" github_api_url: "https://api.github.com" access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}" - runner_name: ubuntu16-latest + runner_name: test_name tasks: - name: Check currently registered runners @@ -31,6 +31,7 @@ - name: Check Runner ansible.builtin.assert: that: + - runner_name in registered_runners.json.runners|map(attribute='name')|list - registered_runners.json.runners.0.status == "online" quiet: true From 5eac33f22041e4e49126217846aefa8ad117cd12 Mon Sep 17 00:00:00 2001 From: Michal Muransky Date: Fri, 24 May 2024 16:43:52 +0200 Subject: [PATCH 4/4] ci: run test when pushed to develop --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b16625c..342fdc1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,11 +1,13 @@ name: molecule test on: + push: + branches: + - develop pull_request: branches: - master - main - - devel* types: [opened, synchronize, reopened] paths: - 'defaults/**'