From 1b40cb3c61ff3ee1877a76b52526370b947e7864 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Thu, 30 Nov 2023 11:07:26 +0000 Subject: [PATCH] Use MIRSG `molecule-test` (#5) 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 https://github.com/UCL-MIRSG/.github/pull/80 being merged first. And linting is broken will fix in a different pr --- .github/workflows/add-issue-to-project.yml | 2 +- .github/workflows/linting.yml | 2 +- .github/workflows/molecule-firewalld.yml | 36 +++------------------- .github/workflows/molecule-provision.yml | 36 +++------------------- .github/workflows/molecule.yml | 28 +++++++++++++++++ 5 files changed, 40 insertions(+), 64 deletions(-) create mode 100644 .github/workflows/molecule.yml diff --git a/.github/workflows/add-issue-to-project.yml b/.github/workflows/add-issue-to-project.yml index a6f326c9..9f7496d5 100644 --- a/.github/workflows/add-issue-to-project.yml +++ b/.github/workflows/add-issue-to-project.yml @@ -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 }} diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 8ddaef63..cb44c915 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -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 diff --git a/.github/workflows/molecule-firewalld.yml b/.github/workflows/molecule-firewalld.yml index 15ac044b..bfb9f68e 100644 --- a/.github/workflows/molecule-firewalld.yml +++ b/.github/workflows/molecule-firewalld.yml @@ -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 diff --git a/.github/workflows/molecule-provision.yml b/.github/workflows/molecule-provision.yml index b9447b16..15827565 100644 --- a/.github/workflows/molecule-provision.yml +++ b/.github/workflows/molecule-provision.yml @@ -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 diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml new file mode 100644 index 00000000..f510d4ca --- /dev/null +++ b/.github/workflows/molecule.yml @@ -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/molecule-test@v0.38.0 + with: + scenario: ${{ matrix.scenario }} + checkout_path: ansible_collections/mirsg/infrastructure + tests_path: ansible_collections/mirsg/infrastructure/tests