Try an approach with github-script calling Github API
This commit is contained in:
90
.github/workflows/molecule.yml
vendored
90
.github/workflows/molecule.yml
vendored
@@ -8,37 +8,71 @@ on:
|
|||||||
branches: [ "master" ]
|
branches: [ "master" ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
detect:
|
||||||
molecule:
|
name: Detect changed roles
|
||||||
name: molecule
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 10
|
outputs:
|
||||||
|
matrix: ${{ steps.make-matrix.outputs.matrix }}
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
distro:
|
|
||||||
- ubuntu2404
|
|
||||||
- ubuntu2204
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- name: Get PR files and build role matrix
|
||||||
|
id: make-matrix
|
||||||
- uses: mamba-org/setup-micromamba@4d84239119b14cba1690b971f05c0bab912bea04
|
uses: actions/github-script@v6
|
||||||
with:
|
with:
|
||||||
micromamba-version: '2.4.0-0'
|
script: |
|
||||||
environment-file: ci/conda.yml
|
// List files changed in the PR and extract top-level role folders under `roles/`
|
||||||
init-shell: bash
|
const files = await github.paginate(github.rest.pulls.listFiles, {
|
||||||
post-cleanup: 'all'
|
owner: context.repo.owner,
|
||||||
cache-environment: true
|
repo: context.repo.repo,
|
||||||
|
pull_number: context.payload.pull_request.number,
|
||||||
|
per_page: 100
|
||||||
|
});
|
||||||
|
|
||||||
- name: "Install role dependencies"
|
const roles = Array.from(new Set(files.map(f => {
|
||||||
run: ansible-galaxy install -r requirements.yml
|
const m = f.filename.match(/^roles\/([^/]+)/);
|
||||||
shell: micromamba-shell {0}
|
return m ? `roles/${m[1]}` : null;
|
||||||
|
}).filter(Boolean)));
|
||||||
|
|
||||||
- name: "Run Molecule tests"
|
// If nothing changed, use a sentinel so the matrix is never empty (empty matrices fail the runner)
|
||||||
run: molecule test
|
if (roles.length === 0) {
|
||||||
shell: micromamba-shell {0}
|
roles.push('__no_role__');
|
||||||
env:
|
}
|
||||||
PY_COLORS: '1'
|
|
||||||
ANSIBLE_FORCE_COLOR: '1'
|
const matrix = { include: roles.map(r => ({ role: r })) };
|
||||||
MOLECULE_DISTRO: ${{ matrix.distro }}
|
core.setOutput('matrix', JSON.stringify(matrix));
|
||||||
|
|
||||||
|
console.log(matrix);
|
||||||
|
|
||||||
|
# molecule:
|
||||||
|
# name: molecule
|
||||||
|
# runs-on: ubuntu-latest
|
||||||
|
# timeout-minutes: 10
|
||||||
|
|
||||||
|
# strategy:
|
||||||
|
# matrix:
|
||||||
|
# distro:
|
||||||
|
# - ubuntu2404
|
||||||
|
# - ubuntu2204
|
||||||
|
|
||||||
|
# steps:
|
||||||
|
# - uses: actions/checkout@v6
|
||||||
|
|
||||||
|
# - uses: mamba-org/setup-micromamba@4d84239119b14cba1690b971f05c0bab912bea04
|
||||||
|
# with:
|
||||||
|
# micromamba-version: '2.4.0-0'
|
||||||
|
# environment-file: ci/conda.yml
|
||||||
|
# init-shell: bash
|
||||||
|
# post-cleanup: 'all'
|
||||||
|
# cache-environment: true
|
||||||
|
|
||||||
|
# - name: "Install role dependencies"
|
||||||
|
# run: ansible-galaxy install -r requirements.yml
|
||||||
|
# shell: micromamba-shell {0}
|
||||||
|
|
||||||
|
# - name: "Run Molecule tests"
|
||||||
|
# run: molecule test
|
||||||
|
# shell: micromamba-shell {0}
|
||||||
|
# env:
|
||||||
|
# PY_COLORS: '1'
|
||||||
|
# ANSIBLE_FORCE_COLOR: '1'
|
||||||
|
# MOLECULE_DISTRO: ${{ matrix.distro }}
|
||||||
|
|||||||
Reference in New Issue
Block a user