python-jsonschema / check-jsonschema

A CLI and set of pre-commit hooks for jsonschema validation with built-in support for GitHub Workflows, Renovate, Azure Pipelines, and more!
https://check-jsonschema.readthedocs.io/en/stable
Other
207 stars 40 forks source link

[BUG] `github-workflows-require-timeout.json`: `timeout-minutes` should allow expressions #354

Closed webknjaz closed 10 months ago

webknjaz commented 10 months ago

$sbj. I want to have timeout-minutes: ${{ inputs.qemu && '60' || '20' }} set for a job. The inputs is a context that exists in reusable workflows. Here's the table of context availability FTR: https://docs.github.com/en/actions/learn-github-actions/contexts.

Here's how it fails for me:

  .github/workflows/reusable-build-wheel.yml::$.jobs.build-wheel: {'name': 'Build wheels on ${{ inputs.os }} ${{ inputs.qemu }}', 'runs-on': '${{ inputs.os }}-latest', 'timeout-minutes': '${{ inputs.qemu && 60 || 20 }}', 'steps': [{'name': 'Retrieve the project source from an sdist inside the GHA artifact', 'uses': 're-actors/checkout-python-sdist@release/v1', 'with': {'source-tarball-name': '${{ inputs.source-tarball-name }}', 'workflow-artifact-name': '${{ inputs.dists-artifact-name }}'}}, {'name': 'Set up QEMU', 'if': 'inputs.qemu', 'uses': 'docker/setup-qemu-action@v3', 'with': {'platforms': 'all'}, 'id': 'qemu'}, {'name': 'Prepare emulation', 'if': 'inputs.qemu', 'run': '# Build emulated architectures only if QEMU is set,\n# use default "auto" otherwise\necho "CIBW_ARCHS_LINUX=${{ inputs.qemu }}" >> "${GITHUB_ENV}"\n', 'shell': 'bash'}, {'name': 'Setup Python', 'uses': 'actions/setup-python@v4'}, {'name': 'Build wheels', 'uses': 'pypa/cibuildwheel@v2.16.2', 'env': {'CIBW_ARCHS_MACOS': 'x86_64 arm64 universal2'}}, {'name': 'Upload built artifacts for testing and publishing', 'uses': 'actions/upload-artifact@v3', 'with': {'name': '${{ inputs.dists-artifact-name }}', 'path': './wheelhouse/*.whl'}}]} is not valid under any of the given schemas
  Underlying errors caused this.

  Best Match:
    $.jobs.build-wheel: 'uses' is a required property
  Best Deep Match:
    $.jobs.build-wheel.timeout-minutes: '${{ inputs.qemu && 60 || 20 }}' is not of type 'number'

Approximate reusable workflow look:

# partial file, specific bit that is failing
on:
  workflow-call:
    inputs:
      ...
      qemu:
          default: ''
          ...
          required: false
          ...
      ...
...
jobs:
  job-id:
    ...
    timeout-minutes: ${{ inputs.qemu && '60' || '20' }}
    ...

Haven't looked into how to fix this, but the upstream github-workflow.json doesn't error out, so this custom schema must be too strict...

sirosen commented 10 months ago

Yep; accepted! The schema was written with type: number. I'll put something in for expression evaluation strings and then it can be OR-ed together.

webknjaz commented 10 months ago

This is where I'm trying to stick it, by the way: https://github.com/aio-libs/yarl/blob/3a5e605/.github/workflows/reusable-build-wheel.yml#L38.

sirosen commented 10 months ago

I just got around to this today and handled it in v0.27.2, freshly released! Please let me know if it does or doesn't work for you.

webknjaz commented 9 months ago

@sirosen yes, thank you! Just got to verifying and it does work for me: https://github.com/aio-libs/frozenlist/commit/a1c0e492308c3f76dff72a442e806f08a11312c9 / https://github.com/aio-libs/frozenlist/commit/3367693497276766c03d5f53ac6b344a1cf93ed9.

Though, there was one problem with my example above: the numbers should be unquoted. So it must be timeout-minutes: ${{ inputs.qemu && 60 || 20 }}. I don't know why I thought the quoted values worked — perhaps, it does work in non-reusable workflows or something changed.

Anyway, the schema looks good to me now.