Skip to content

Commit

Permalink
Use MIRSG molecule-test (#5)
Browse files Browse the repository at this point in the history
Reduce duplication in workflows by:
- using our `molecule-test` GitHub Action
- adding a reusable workflow for running the action
- use this reusable workflow for running tests on the `provision` and
`firewalld` roles (more workflows can be added in a separate pr)
- run the tests for a given role when either the role itself changes or
the workflow changes

Note, this depends on UCL-MIRSG/.github#80 being
merged first.
And linting is broken will fix in a different pr
  • Loading branch information
p-j-smith authored Nov 30, 2023
1 parent 0c3dfea commit 1b40cb3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/add-issue-to-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
add-issue-to-project:
runs-on: ubuntu-latest
steps:
- uses: UCL-MIRSG/.github/actions/add-to-project@v0.36.0
- uses: UCL-MIRSG/.github/actions/add-to-project@v0.38.0
with:
app-id: ${{ secrets.APP_ID }}
app-pem: ${{ secrets.APP_PEM }}
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
linting:
runs-on: ubuntu-latest
steps:
- uses: UCL-MIRSG/.github/actions/linting@v0.36.0
- uses: UCL-MIRSG/.github/actions/linting@v0.38.0
with:
ansible-roles-config: ./meta/requirements.yml
pre-commit-config: ./.pre-commit-config.yaml
36 changes: 5 additions & 31 deletions .github/workflows/molecule-firewalld.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,11 @@ on:
pull_request:
paths:
- "roles/firewalld/**"
- ".github/workflows/molecule.yml"
- ".github/workflows/molecule-firewalld.yml"

jobs:
molecule-firewalld:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
scenario:
- centos7
env:
MOLECULE_RUN_TAGS: firewalld
PY_COLORS: 1
ANSIBLE_FORCE_COLOR: 1
steps:
- name: Check out the codebase
uses: actions/checkout@v4
with:
path: ansible_collections/mirsg/infrastructure

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install test dependencies
run: |
sudo apt-get update && sudo apt-get -y install rsync
python3 -m pip install --upgrade pip
python3 -m pip install ansible molecule molecule-plugins[docker] docker requests
- name: Test with molecule
run: |
cd ansible_collections/mirsg/infrastructure/tests
molecule test --scenario-name "${{ matrix.scenario }}"
uses: ./.github/workflows/molecule.yml
with:
run-tags: firewalld
36 changes: 5 additions & 31 deletions .github/workflows/molecule-provision.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,11 @@ on:
pull_request:
paths:
- "roles/provision/**"
- ".github/workflows/molecule.yml"
- ".github/workflows/molecule-provision.yml"

jobs:
molecule-provision:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
scenario:
- centos7
env:
MOLECULE_RUN_TAGS: provision
PY_COLORS: 1
ANSIBLE_FORCE_COLOR: 1
steps:
- name: Check out the codebase
uses: actions/checkout@v4
with:
path: ansible_collections/mirsg/infrastructure

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install test dependencies
run: |
sudo apt-get update && sudo apt-get -y install rsync
python3 -m pip install --upgrade pip
python3 -m pip install ansible molecule molecule-plugins[docker] docker requests
- name: Test with molecule
run: |
cd ansible_collections/mirsg/infrastructure/tests
molecule test --scenario-name "${{ matrix.scenario }}"
uses: ./.github/workflows/molecule.yml
with:
run-tags: provision
28 changes: 28 additions & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test with Molecule
on:
workflow_call:
inputs:
run-tags:
type: string
default: all

jobs:
molecule:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
scenario:
- centos7
env:
MOLECULE_RUN_TAGS: ${{ inputs.run-tags }}
PY_COLORS: 1
ANSIBLE_FORCE_COLOR: 1

steps:
- name: Run `molecule test`
uses: UCL-MIRSG/.github/actions/[email protected]
with:
scenario: ${{ matrix.scenario }}
checkout_path: ansible_collections/mirsg/infrastructure
tests_path: ansible_collections/mirsg/infrastructure/tests

0 comments on commit 1b40cb3

Please sign in to comment.