| name: Reusable build context | |
| on: # yamllint disable-line rule:truthy | |
| workflow_call: | |
| outputs: | |
| # Every referenced step MUST always set its output variable, | |
| # either via ``Tools/build/compute-changes.py`` or in this workflow file. | |
| # Boolean outputs (generally prefixed ``run-``) can then later be used | |
| # safely through the following idiom in job conditionals and other | |
| # expressions. Here's some examples: | |
| # | |
| # if: fromJSON(needs.build-context.outputs.run-tests) | |
| # | |
| # ${{ | |
| # fromJSON(needs.build-context.outputs.run-tests) | |
| # && 'truthy-branch' | |
| # || 'falsy-branch' | |
| # }} | |
| # | |
| run-android: | |
| description: Whether to run the Android tests | |
| value: ${{ jobs.compute-changes.outputs.run-android }} # bool | |
| run-ci-fuzz: | |
| description: Whether to run the CIFuzz job for 'cpython' fuzzer | |
| value: ${{ jobs.compute-changes.outputs.run-ci-fuzz }} # bool | |
| run-ci-fuzz-stdlib: | |
| description: Whether to run the CIFuzz job for 'python3-libraries' fuzzer | |
| value: ${{ jobs.compute-changes.outputs.run-ci-fuzz-stdlib }} # bool | |
| run-docs: | |
| description: Whether to build the docs | |
| value: ${{ jobs.compute-changes.outputs.run-docs }} # bool | |
| run-ios: | |
| description: Whether to run the iOS tests | |
| value: ${{ jobs.compute-changes.outputs.run-ios }} # bool | |
| run-macos: | |
| description: Whether to run the macOS tests | |
| value: ${{ jobs.compute-changes.outputs.run-macos }} # bool | |
| run-tests: | |
| description: Whether to run the regular tests | |
| value: ${{ jobs.compute-changes.outputs.run-tests }} # bool | |
| run-ubuntu: | |
| description: Whether to run the Ubuntu tests | |
| value: ${{ jobs.compute-changes.outputs.run-ubuntu }} # bool | |
| run-emscripten: | |
| description: Whether to run the Emscripten tests | |
| value: ${{ jobs.compute-changes.outputs.run-emscripten }} # bool | |
| run-wasi: | |
| description: Whether to run the WASI tests | |
| value: ${{ jobs.compute-changes.outputs.run-wasi }} # bool | |
| run-windows-tests: | |
| description: Whether to run the Windows tests | |
| value: ${{ jobs.compute-changes.outputs.run-windows-tests }} # bool | |
| permissions: | |
| contents: read | |
| jobs: | |
| compute-changes: | |
| name: Create context from changed files | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| outputs: | |
| run-android: ${{ steps.changes.outputs.run-android }} | |
| run-ci-fuzz: ${{ steps.changes.outputs.run-ci-fuzz }} | |
| run-ci-fuzz-stdlib: ${{ steps.changes.outputs.run-ci-fuzz-stdlib }} | |
| run-docs: ${{ steps.changes.outputs.run-docs }} | |
| run-ios: ${{ steps.changes.outputs.run-ios }} | |
| run-macos: ${{ steps.changes.outputs.run-macos }} | |
| run-tests: ${{ steps.changes.outputs.run-tests }} | |
| run-ubuntu: ${{ steps.changes.outputs.run-ubuntu }} | |
| run-emscripten: ${{ steps.changes.outputs.run-emscripten }} | |
| run-wasi: ${{ steps.changes.outputs.run-wasi }} | |
| run-windows-tests: ${{ steps.changes.outputs.run-windows-tests }} | |
| steps: | |
| - name: Set up Python | |
| uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 | |
| with: | |
| python-version: "3" | |
| - run: >- | |
| echo '${{ github.event_name }}' | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| ref: >- | |
| ${{ | |
| github.event_name == 'pull_request' | |
| && github.event.pull_request.head.sha | |
| || '' | |
| }} | |
| # Adapted from https://github.com/actions/checkout/issues/520#issuecomment-1167205721 | |
| - name: Fetch commits to get branch diff | |
| if: github.event_name == 'pull_request' | |
| run: | | |
| set -eux | |
| # Fetch enough history to find a common ancestor commit (aka merge-base): | |
| git fetch origin "${refspec_pr}" --depth=$(( commits + 1 )) \ | |
| --no-tags --prune --no-recurse-submodules | |
| # This should get the oldest commit in the local fetched history (which may not be the commit the PR branched from): | |
| COMMON_ANCESTOR=$( git rev-list --first-parent --max-parents=0 --max-count=1 "${branch_pr}" ) | |
| DATE=$( git log --date=iso8601 --format=%cd "${COMMON_ANCESTOR}" ) | |
| # Get all commits since that commit date from the base branch (eg: main): | |
| git fetch origin "${refspec_base}" --shallow-since="${DATE}" \ | |
| --no-tags --prune --no-recurse-submodules | |
| env: | |
| branch_pr: 'origin/${{ github.event.pull_request.head.ref }}' | |
| commits: ${{ github.event.pull_request.commits }} | |
| refspec_base: '+${{ github.event.pull_request.base.sha }}:remotes/origin/${{ github.event.pull_request.base.ref }}' | |
| refspec_pr: '+${{ github.event.pull_request.head.sha }}:remotes/origin/${{ github.event.pull_request.head.ref }}' | |
| # We only want to run tests on PRs when related files are changed, | |
| # or when someone triggers a manual workflow run. | |
| - name: Compute changed files | |
| id: changes | |
| run: python Tools/build/compute-changes.py | |
| env: | |
| GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | |
| GITHUB_EVENT_NAME: ${{ github.event_name }} | |
| CCF_TARGET_REF: ${{ github.base_ref || github.event.repository.default_branch }} | |
| CCF_HEAD_REF: ${{ github.event.pull_request.head.sha || github.sha }} |