CI: fix auto builds and make sure that we always have at least a single CI job

This commit is contained in:
Jakub Beránek 2024-05-05 08:05:10 +02:00
parent bf8bcc4c2d
commit b3e9060178
No known key found for this signature in database
GPG Key ID: 909CD0D26483516B
2 changed files with 5 additions and 9 deletions

View File

@ -77,14 +77,6 @@ jobs:
matrix: matrix:
# Check the `calculate_matrix` job to see how is the matrix defined. # Check the `calculate_matrix` job to see how is the matrix defined.
include: ${{ fromJSON(needs.calculate_matrix.outputs.jobs) }} include: ${{ fromJSON(needs.calculate_matrix.outputs.jobs) }}
# GitHub Actions fails the workflow if an empty list of jobs is provided to
# the workflow, so we need to skip this job if nothing was produced by
# the Python script.
#
# Unfortunately checking whether a list is empty is not possible in a nice
# way due to GitHub Actions expressions limits.
# This hack is taken from https://github.com/ferrocene/ferrocene/blob/d43edc6b7697cf1719ec1c17c54904ab94825763/.github/workflows/release.yml#L75-L82
if: fromJSON(needs.calculate_matrix.outputs.jobs)[0] != null
steps: steps:
- if: contains(matrix.os, 'windows') - if: contains(matrix.os, 'windows')
uses: msys2/setup-msys2@v2.22.0 uses: msys2/setup-msys2@v2.22.0

View File

@ -136,7 +136,7 @@ def calculate_jobs(run_type: WorkflowRunType, job_data: Dict[str, Any]) -> List[
raise Exception(f"Custom job(s) `{unknown_jobs}` not found in auto jobs") raise Exception(f"Custom job(s) `{unknown_jobs}` not found in auto jobs")
return add_base_env(name_jobs(jobs, "try"), job_data["envs"]["try"]) return add_base_env(name_jobs(jobs, "try"), job_data["envs"]["try"])
elif run_type is AutoRunType: elif isinstance(run_type, AutoRunType):
return add_base_env(name_jobs(job_data["auto"], "auto"), job_data["envs"]["auto"]) return add_base_env(name_jobs(job_data["auto"], "auto"), job_data["envs"]["auto"])
return [] return []
@ -192,6 +192,10 @@ if __name__ == "__main__":
if run_type is not None: if run_type is not None:
jobs = calculate_jobs(run_type, data) jobs = calculate_jobs(run_type, data)
jobs = skip_jobs(jobs, channel) jobs = skip_jobs(jobs, channel)
if not jobs:
raise Exception("Scheduled job list is empty, this is an error")
run_type = format_run_type(run_type) run_type = format_run_type(run_type)
logging.info(f"Output:\n{yaml.dump(dict(jobs=jobs, run_type=run_type), indent=4)}") logging.info(f"Output:\n{yaml.dump(dict(jobs=jobs, run_type=run_type), indent=4)}")