Optionally proceed when another needs job skipped

The Context

I have a series of jobs:

  • check-db-files-changed Emits an output whether any database models changed
  • generate-code Does code generation and caching of said generated code
  • unit-test Has a needs: generate-code
  • db-test Has a needs: [check-db-files-changed, generate-code]
  • lint Has a needs: generate-code
  • upload-report Has a needs: [ unit-test, db-test, lint ]

db-test is optionally executed depending if check-db-files-changed has the output set to true, otherwise the job is skipped.

The problem

Because upload-report has a needs on db-test, if db-test is not run, upload-report is not run either (skipped).

Now, I’ve tried the following:

        runs-on: ubuntu-18.04
        needs: [ unit-test, lint, db-test ]
        name: "Export test and linting reports"
        if: ${{ always() && needs.unit-test.success && needs.lint.success }}

but even the if in the job does not enable the job to run.

I’d like to avoid having the if on the db-test for all steps such that the job itself doesn’t get resembled as “run” when it’s skipped all its steps, but it seems like it’s the only way to get around a needs job being skipped causing the dependent job being skipped regardless of the if

if: ${{ always() && (needs.db-test.result ==‘skipped’ || needs.db-test.result ==‘success’) }}

You have to use something like the above on the upload-report action.