Skip to content

Commit 5b2d407

Browse files
Merge pull request #212 from MonolithProjects/develop
Develop to Master
2 parents b95b43c + c864603 commit 5b2d407

File tree

7 files changed

+120
-10
lines changed

7 files changed

+120
-10
lines changed

.github/CONTRIBUTING.md

+38-6
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,51 @@ Install [Pre-commit](https://pre-commit.com/#install) software
2323

2424
Do the changes in your own GitHub namespace.
2525

26-
## 5. Test the changes
26+
## 5. Test the changes with Molecule
2727

28-
**Note:** I will test the role again, so you don't need to do that if you don't want to.
28+
[Molecule](https://molecule.readthedocs.io/) is a testing framework for Ansible that we use to test the `monolithprojects.github_actions_runner` role.
2929

30-
Install [molecule](https://molecule.readthedocs.io/en/stable/) and run the test:
30+
### Prerequisites
31+
32+
- Python
33+
- Docker
34+
- Ansible
35+
- Molecule
36+
37+
### Installation
38+
39+
1. Install Python, Docker, and Ansible if you haven't already.
40+
2. Install Molecule and its Docker driver with pip:
41+
42+
```bash
43+
pip install molecule[docker]
44+
```
45+
46+
### Running Tests
47+
48+
1. Navigate to the role's directory:
49+
50+
```bash
51+
cd path/to/monolithprojects.github_actions_runner
52+
```
53+
54+
2. Set Environment variables
55+
56+
```bash
57+
export PERSONAL_ACCESS_TOKEN=your_github_pat # Your Personal Access Token to Github
58+
export GITHUB_ACCOUNT=your_account # Your Github Account
59+
export GITHUB_ACCOUNT=your_repository # Github Repository where you want to setup the Runner
60+
```
61+
62+
3. Run Molecule:
3163

3264
```bash
33-
pip install molecule molecule-docker ansible-lint docker
34-
cd ansible-github_actions_runner
3565
molecule test
3666
```
3767

38-
> You will need to edit the files in `molecule/default` directory (please do not commit those changes)
68+
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.
69+
70+
For more information on using Molecule, see the [Molecule documentation](https://molecule.readthedocs.io/).
3971

4072
## 6. Create a pull request
4173

.github/workflows/tests.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
name: molecule test
22

33
on:
4+
push:
5+
branches:
6+
- develop
47
pull_request:
58
branches:
69
- master
710
- main
8-
- devel*
911
types: [opened, synchronize, reopened]
1012
paths:
1113
- 'defaults/**'

README.md

+73
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ Same example as above, but runner will be added to an organization and deployed
165165
```
166166
167167
If you have a Github Enterprise Cloud license and you want to manage all the self-hosted runners from the enterprise:
168+
168169
```yaml
169170
---
170171
- name: Install GitHub Actions Runner
@@ -221,6 +222,78 @@ In this example the Ansible role will uninstall the runner service and unregiste
221222
- role: monolithprojects.github_actions_runner
222223
```
223224

225+
## Testing with Molecule
226+
227+
[Molecule](https://molecule.readthedocs.io/) is a testing framework for Ansible. This section is for code contributors.
228+
229+
### Prerequisites
230+
231+
* Python
232+
* Docker
233+
* Ansible
234+
* Molecule
235+
236+
### Installation
237+
238+
1. Install Python, Docker, and Ansible if you haven't already.
239+
2. Install Molecule and its Docker driver with pip:
240+
241+
```bash
242+
pip install molecule[docker]
243+
```
244+
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:
245+
246+
```markdown
247+
# monolithprojects.github_actions_runner
248+
249+
This is an Ansible role for setting up GitHub Actions runners.
250+
251+
## Testing with Molecule
252+
253+
[Molecule](https://molecule.readthedocs.io/) is a testing framework for Ansible that we use to test the `monolithprojects.github_actions_runner` role.
254+
255+
### Prerequisites
256+
257+
- Python
258+
- Docker
259+
- Ansible
260+
- Molecule
261+
262+
### Installation
263+
264+
1. Install Python, Docker, and Ansible if you haven't already.
265+
2. Install Molecule and its Docker driver with pip:
266+
267+
```bash
268+
pip install molecule[docker]
269+
```
270+
271+
### Running Tests
272+
273+
1. Navigate to the role's directory:
274+
275+
```bash
276+
cd path/to/monolithprojects.github_actions_runner
277+
```
278+
279+
2. Set Environment variables
280+
281+
```bash
282+
export PERSONAL_ACCESS_TOKEN=your_github_pat # Your Personal Access Token to Github
283+
export GITHUB_ACCOUNT=your_account # Your Github Account
284+
export GITHUB_ACCOUNT=your_repository # Github Repository where you want to setup the Runner
285+
```
286+
287+
3. Run Molecule:
288+
289+
```bash
290+
molecule test
291+
```
292+
293+
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.
294+
295+
For more information on using Molecule, see the [Molecule documentation](https://molecule.readthedocs.io/).
296+
224297
## License
225298

226299
MIT

molecule/custom_env/cleanup.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
github_repo: "{{ lookup('env', 'GITHUB_REPO') }}"
99
github_account: "{{ lookup('env', 'GITHUB_ACCOUNT') }}"
1010
runner_state: absent
11+
runner_name: test_name
1112
roles:
1213
- monolithprojects.github_actions_runner

molecule/custom_env/converge.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
github_repo: "{{ lookup('env', 'GITHUB_REPO') }}"
1010
github_account: "{{ lookup('env', 'GITHUB_ACCOUNT') }}"
1111
runner_version: "latest"
12+
runner_name: test_name
1213
runner_labels:
1314
- label1
1415
- repo-runner

molecule/custom_env/verify.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
github_account: "{{ lookup('env', 'GITHUB_ACCOUNT') }}"
1111
github_api_url: "https://api.github.com"
1212
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
13-
runner_name: ubuntu16-latest
13+
runner_name: test_name
1414

1515
tasks:
1616
- name: Check currently registered runners
@@ -32,7 +32,7 @@
3232
ansible.builtin.assert:
3333
that:
3434
- runner_name in registered_runners.json.runners|map(attribute='name')|list
35-
- registered_runners.json.runners|map(attribute='status') == ["online"]
35+
- registered_runners.json.runners.0.status == "online"
3636
quiet: true
3737

3838
- name: Check Labels (skipped if labels are OK)

molecule/default/verify.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
github_account: "{{ lookup('env', 'GITHUB_ACCOUNT') }}"
1111
github_api_url: "https://api.github.com"
1212
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
13-
runner_name: ubuntu16-latest
13+
runner_name: test_name
1414

1515
tasks:
1616
- name: Check currently registered runners
@@ -31,6 +31,7 @@
3131
- name: Check Runner
3232
ansible.builtin.assert:
3333
that:
34+
- runner_name in registered_runners.json.runners|map(attribute='name')|list
3435
- registered_runners.json.runners.0.status == "online"
3536
quiet: true
3637

0 commit comments

Comments
 (0)