Skip to content

Commit

Permalink
Merge pull request #212 from MonolithProjects/develop
Browse files Browse the repository at this point in the history
Develop to Master
  • Loading branch information
MonolithProjects authored May 25, 2024
2 parents b95b43c + c864603 commit 5b2d407
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 10 deletions.
44 changes: 38 additions & 6 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: molecule test

on:
push:
branches:
- develop
pull_request:
branches:
- master
- main
- devel*
types: [opened, synchronize, reopened]
paths:
- 'defaults/**'
Expand Down
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions molecule/custom_env/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions molecule/custom_env/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions molecule/custom_env/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 5b2d407

Please sign in to comment.