Skip to content

Commit

Permalink
ci: Molecule Test and Rename to Publish role on Ansible Galaxy
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobLichterfeld committed Aug 31, 2023
1 parent 7d75a61 commit 5ef818e
Show file tree
Hide file tree
Showing 17 changed files with 291 additions and 52 deletions.
5 changes: 5 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
skip_list:
- 'yaml'
- 'risky-shell-pipe'
- 'no-handler'
- 'role-name'
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Information:**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS]
- Version [e.g. 0.0.1]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
15 changes: 15 additions & 0 deletions .github/actions/lint/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: "Lint"
description: "Lint"
runs:
using: "composite"
steps:
- uses: actions/checkout@v3

- name: Install lint dependencies
shell: bash
run: pip3 install yamllint

- name: Lint code
shell: bash
run: yamllint .
11 changes: 11 additions & 0 deletions .github/actions/set-up-ansible/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: 'Set up Ansible'
description: 'Set up Ansible'
runs:
using: "composite"
steps:
- uses: actions/checkout@v3

- name: Set up Ansible
shell: bash
run: pip3 install ansible-core
11 changes: 11 additions & 0 deletions .github/actions/set-up-molecule/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: 'Set up Molecule'
description: 'Set up Molecule'
runs:
using: "composite"
steps:
- uses: actions/checkout@v3

- name: Set up Molecule
shell: bash
run: pip3 install molecule molecule-plugins[docker] docker
12 changes: 12 additions & 0 deletions .github/actions/set-up-python/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: 'Set up Python'
description: 'Set up Python'
runs:
using: "composite"
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: CI
on:
push:
branches: ["main", "releases/**"]
#tags: ["v*", "v**", "v.*", "v.**" ]
pull_request:
branches: ["main", "releases/**"]
schedule:
- cron: "0 3 * * *"
workflow_dispatch:
workflow_call:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
# prevent stuck jobs
timeout-minutes: 20
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: ./.github/actions/set-up-python

- name: Lint
uses: ./.github/actions/lint

molecule:
needs: [lint]
name: Test with Ansible Molecule
runs-on: ubuntu-latest
# prevent stuck jobs
timeout-minutes: 20
strategy:
matrix:
distro: [ubuntu2204]
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: ./.github/actions/set-up-python

- name: Set up Ansible
uses: ./.github/actions/set-up-ansible

- name: Set up Molecule
uses: ./.github/actions/set-up-molecule

- name: Run Molecule tests
run: molecule test
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
MOLECULE_DISTRO: ${{ matrix.distro }}
28 changes: 28 additions & 0 deletions .github/workflows/publish_role_on_ansible_galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# see: https://github.com/geerlingguy/ansible-role-docker/blob/8bb277bd7fb7019eb129b4a07194f0364c060203/.github/workflows/release.yml
name: Publish role on Ansible Galaxy
on:
push:
workflow_dispatch:
workflow_call:

jobs:
release:
name: Publish role on Ansible Galaxy
runs-on: ubuntu-latest
# prevent stuck jobs
timeout-minutes: 20
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: ./.github/actions/set-up-python

- name: Set up Ansible
uses: ./.github/actions/set-up-ansible

- name: Import to Ansible Galaxy
run: >-
ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }}
$(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2)
36 changes: 0 additions & 36 deletions .github/workflows/release_to_ansible_galaxy.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
extends: default

rules:
line-length: disable
truthy:
allowed-values: ['true', 'false', 'yes', 'no']
comments:
min-spaces-from-content: 1
braces:
min-spaces-inside: 0
max-spaces-inside: 1

ignore: |
.cache
.github/workflows/*.yml
.github/actions/*/*.yml
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Ansible Role: Calibre

[![CI](https://github.com/JakobLichterfeld/ansible-role-calibre/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/JakobLichterfeld/ansible-role-calibre/actions/workflows/ci.yml)
[![Publish role on Ansible Galaxy](https://github.com/JakobLichterfeld/ansible-role-calibre/actions/workflows/publish_role_on_ansible_galaxy.yml/badge.svg?branch=main)](https://github.com/JakobLichterfeld/ansible-role-calibre/actions/workflows/publish_role_on_ansible_galaxy.yml)

Install Calibre via Binary Installer Download.

- Install dependencies
Expand Down Expand Up @@ -27,7 +30,7 @@ None.
```yaml
---
- hosts: all
gather_facts: yes
gather_facts: true
become: true

roles:
Expand Down
30 changes: 16 additions & 14 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
---
galaxy_info:
role_name: calibre
version: 1.0.0
author: JakobLichterfeld
description: Install Calibre via Binary Installer Download
role_name: calibre
namespace: jakoblichterfeld
standalone: true
author: JakobLichterfeld
description: Install Calibre via Binary Installer Download

homepage: https://github.com/JakobLichterfeld/ansible-role_calibre
issue_tracker_url: https://github.com/JakobLichterfeld/ansible-role_calibre/issues
# homepage: https://github.com/JakobLichterfeld/ansible-role_calibre
issue_tracker_url: https://github.com/JakobLichterfeld/ansible-role_calibre/issues

license: MIT
min_ansible_version: 2.1
license: MIT
min_ansible_version: "2.1"

platforms:
- name: Ubuntu
versions:
- jammy
platforms:
- name: Ubuntu
versions:
- jammy

galaxy_tags:
- calibre
galaxy_tags:
- calibre
- book

dependencies: []
15 changes: 15 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Converge
hosts: all
gather_facts: true
become: true

pre_tasks:
- name: Populate ansible user name
ansible.builtin.set_fact:
ansible_user: "root"

tasks:
- name: Testing role
ansible.builtin.include_role:
name: jakoblichterfeld.calibre
24 changes: 24 additions & 0 deletions molecule/default/destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
# no_log: "{{ molecule_no_log }}"
tasks:
# Developer must implement.

# Mandatory configuration for Molecule to function.

- name: Populate instance config
ansible.builtin.set_fact:
instance_conf: {}

- name: Dump instance config
ansible.builtin.copy:
content: |
# Molecule managed
{{ instance_conf | to_json | from_json | to_yaml }}
dest: "{{ molecule_instance_config }}"
mode: 0600
when: server.changed | default(false) | bool # noqa no-handler
23 changes: 23 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
role_name_check: 1
dependency:
name: galaxy

# Docker
driver:
name: docker
platforms:
- name: Instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
cgroupns_mode: host
privileged: true
pre_build_image: true

# ansible.cfg
provisioner:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
4 changes: 3 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@
state: directory
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: '0755'

- name: Download Binary Installer Script
become: true
become_user: "{{ ansible_user }}"
ansible.builtin.get_url:
url: "https://download.calibre-ebook.com/linux-installer.sh"
dest: "{{ download_dir_on_remote_host }}/calibre/linux-installer.sh"
timeout: 60
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: '0644'
register: calibre_installer

- name: Execute Binary Installer Script
#command, as this is the only way to run shell scripts in Ansible.
# command, as this is the only way to run shell scripts in Ansible.
ansible.builtin.command:
cmd: "sh {{ download_dir_on_remote_host }}/calibre/linux-installer.sh"
when: calibre_installer.changed or calibre.force_update | bool

0 comments on commit 5ef818e

Please sign in to comment.