Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

104 lines
3.1 KiB

  1. # SPDX-FileCopyrightText: 2026 Slavi Pantaleev
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. name: Molecule
  6. # Unlike the MASH role repositories, where one repository holds one role, every
  7. # role here lives in the same repository. Running every scenario on every push
  8. # would be unaffordable, so a first job works out which roles the push actually
  9. # touched and the matrix is built from that. A push that changes documentation,
  10. # or a role with no scenario yet, runs nothing at all.
  11. on: # yamllint disable-line rule:truthy
  12. push:
  13. paths:
  14. - "roles/custom/**"
  15. - "molecule-shared/**"
  16. - ".github/workflows/molecule.yml"
  17. - "bin/molecule-select-roles.py"
  18. - "bin/test-molecule-select-roles.py"
  19. pull_request:
  20. paths:
  21. - "roles/custom/**"
  22. - "molecule-shared/**"
  23. - ".github/workflows/molecule.yml"
  24. - "bin/molecule-select-roles.py"
  25. - "bin/test-molecule-select-roles.py"
  26. workflow_dispatch:
  27. inputs:
  28. role:
  29. description: "Single role to test (directory name under roles/custom), or empty for all roles that have a scenario"
  30. required: false
  31. type: string
  32. permissions:
  33. contents: read
  34. jobs:
  35. detect:
  36. name: Work out which roles to test
  37. runs-on: ubuntu-latest
  38. # Same rule as the MASH repositories: a pull request from a branch of this
  39. # repository would otherwise run everything twice, once for the push and
  40. # once for the pull request.
  41. if: >-
  42. github.event_name != 'pull_request'
  43. || github.event.pull_request.head.repo.full_name != github.repository
  44. outputs:
  45. roles: ${{ steps.detect.outputs.roles }}
  46. steps:
  47. - name: Check out
  48. uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
  49. with:
  50. fetch-depth: 0
  51. - name: Test scenario selection
  52. run: python3 bin/test-molecule-select-roles.py
  53. - name: Detect roles with a Molecule scenario that this change touches
  54. id: detect
  55. env:
  56. EVENT_NAME: ${{ github.event_name }}
  57. BASE_SHA: ${{ github.event.pull_request.base.sha }}
  58. BEFORE_SHA: ${{ github.event.before }}
  59. DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
  60. INPUT_ROLE: ${{ inputs.role }}
  61. run: python3 bin/molecule-select-roles.py
  62. molecule:
  63. name: "Molecule: ${{ matrix.role }}"
  64. runs-on: ubuntu-latest
  65. needs: detect
  66. if: needs.detect.outputs.roles != '[]'
  67. strategy:
  68. matrix:
  69. role: ${{ fromJson(needs.detect.outputs.roles) }}
  70. fail-fast: false
  71. env:
  72. MOLECULE_DISTRO: ubuntu2604
  73. PY_COLORS: "1"
  74. ANSIBLE_FORCE_COLOR: "1"
  75. steps:
  76. - name: Check out
  77. uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
  78. - name: Set up Python
  79. uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
  80. with:
  81. python-version: "3.x"
  82. - name: Install test dependencies
  83. run: python3 -m pip install -r molecule-shared/requirements.txt
  84. - name: Run Molecule
  85. working-directory: roles/custom/${{ matrix.role }}
  86. run: molecule test --scenario-name default