diff --git a/.github/problem-matchers/README.md b/.github/problem-matchers/README.md deleted file mode 100644 index 60ede5cbb..000000000 --- a/.github/problem-matchers/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Problem Matchers - -GitHub [Problem Matchers](https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md) are a mechanism that enable workflow steps to scan the outputs of GitHub Actions for regex patterns and automatically write annotations in the workflow summary page. Using Problem Matchers allows information to be displayed more prominently in the GitHub user interface. - -This directory contains Problem Matchers used by the GitHub Actions workflows in the [`workflows`](./workflows) subdirectory. - -The following problem matcher JSON files found in this directory were copied from the [Home Assistant](https://github.com/home-assistant/core) project on GitHub. The Home Assistant project is licensed under the Apache 2.0 open-source license. The version of the files at the time they were copied was 2025.1.2. - -- [`pylint.json`](https://github.com/home-assistant/core/blob/dev/.github/workflows/matchers/pylint.json) -- [`yamllint.json`](https://github.com/home-assistant/core/blob/dev/.github/workflows/matchers/yamllint.json) diff --git a/.github/problem-matchers/clang-format.json b/.github/problem-matchers/clang-format.json deleted file mode 100644 index 29cd03f37..000000000 --- a/.github/problem-matchers/clang-format.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "problemMatcher": [ - { - "owner": "clang-format-error", - "severity": "error", - "pattern": [ - { - "regexp": "^(.*?)\\((\\d+),(\\d*)\\):\\s+(?:fatal\\s+)?error:\\s+(.*)$", - "file": 1, - "line": 2, - "column": 3, - "message": 4 - } - ] - }, - { - "owner": "clang-format-warning", - "severity": "warning", - "pattern": [ - { - "regexp": "^(.*?)\\((\\d+),(\\d*)\\):\\s+(?:fatal\\s+)?warning:\\s+(.*)$", - "file": 1, - "line": 2, - "column": 3, - "message": 4 - } - ] - } - ] -} diff --git a/.github/problem-matchers/pylint.json b/.github/problem-matchers/pylint.json deleted file mode 100644 index 5624ca695..000000000 --- a/.github/problem-matchers/pylint.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "problemMatcher": [ - { - "owner": "pylint-error", - "severity": "error", - "pattern": [ - { - "regexp": "^(.+):(\\d+):(\\d+):\\s(([EF]\\d{4}):\\s.+)$", - "file": 1, - "line": 2, - "column": 3, - "message": 4, - "code": 5 - } - ] - }, - { - "owner": "pylint-warning", - "severity": "warning", - "pattern": [ - { - "regexp": "^(.+):(\\d+):(\\d+):\\s(([CRW]\\d{4}):\\s.+)$", - "file": 1, - "line": 2, - "column": 3, - "message": 4, - "code": 5 - } - ] - } - ] -} diff --git a/.github/problem-matchers/yamllint.json b/.github/problem-matchers/yamllint.json deleted file mode 100644 index ab9449dd7..000000000 --- a/.github/problem-matchers/yamllint.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "problemMatcher": [ - { - "owner": "yamllint", - "pattern": [ - { - "regexp": "^(.*\\.ya?ml)$", - "file": 1 - }, - { - "regexp": "^\\s{2}(\\d+):(\\d+)\\s+(error|warning)\\s+(.*?)\\s+\\((.*)\\)$", - "line": 1, - "column": 2, - "severity": 3, - "message": 4, - "code": 5, - "loop": true - } - ] - } - ] -} diff --git a/.github/workflows/ci-file-checks.yaml b/.github/workflows/ci-file-checks.yaml deleted file mode 100644 index 166af5c90..000000000 --- a/.github/workflows/ci-file-checks.yaml +++ /dev/null @@ -1,383 +0,0 @@ -# Copyright 2025 The TensorFlow Quantum Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Summary: TFQ continuous integration workflow for static code analysis. -# -# This workflow runs linters and code format/style checkers on certain events -# such as pull requests and merge-queue merges. It tries to be as efficient as -# possible by only running jobs when specific types of files were affected by -# a PR, and by caching the Python installation so that it doesn't have to be -# re-installed on every run. It reads the requirements.txt file to find out -# the required versions of some program like pylint and yapf, to adhere to DRY -# principles. It uses GitHub "problem matchers" to write error outputs to the -# workflow summary to make it easier to learn the outcome. Finally, It can be -# invoked manually using the "Run workflow" button on the page at -# https://github.com/tensorflow/quantum/actions/workflows/ci-file-checks.yaml - -name: 'CI: lint & check formating' -run-name: Continuous integration lint and format checks - -on: - pull_request: - types: [opened, synchronize] - branches: - - master - - merge_group: - types: - - checks_requested - - push: - branches: - - master - - # Allow manual invocation, with options that can be useful for debugging. - workflow_dispatch: - inputs: - sha: - description: 'SHA of commit to run against:' - type: string - required: true - - python_ver: - description: 'Python version:' - type: string - - pylint_ver: - description: 'Pylint version:' - type: string - - yapf_ver: - description: 'Yapf version:' - type: string - - clang_format_ver: - description: 'clang-format version:' - type: string - - remake_python_cache: - description: 'Delete & remake the Python cache' - type: boolean - default: false - -env: - # Default Python version to use. - python_ver: '3.10' - # Note: as of 2025-01-16, clang-format v. 18 is the latest available on - # GitHub, and you have to use Ubuntu 24 to get it. - clang_format_ver: '18' - -concurrency: - # Cancel any previously-started but still active runs on the same branch. - cancel-in-progress: true - group: ${{github.workflow}}-${{github.event.pull_request.number||github.ref}} - -permissions: read-all - -jobs: - Changes: - runs-on: ubuntu-24.04 - timeout-minutes: 5 - outputs: - python: ${{steps.filter.outputs.python}} - python_files: ${{steps.filter.outputs.python_files}} - cc: ${{steps.filter.outputs.cc}} - cc_files: ${{steps.filter.outputs.cc_files}} - yaml: ${{steps.filter.outputs.yaml}} - yaml_files: ${{steps.filter.outputs.yaml_files}} - steps: - # When invoked manually, use the given SHA to figure out the change list. - - if: github.event_name == 'workflow_dispatch' - name: Use the user-provided SHA as the basis for comparison - env: - GH_TOKEN: ${{github.token}} - run: | - set -x +e - url="repos/${{github.repository}}/commits/${{inputs.sha}}" - full_sha="$(gh api $url -q '.sha')" - exit_code=$? - if [[ "$exit_code" == "0" ]]; then - echo "base=$full_sha" >> "$GITHUB_ENV" - else - { - echo "### :x: Workflow error" - echo "The SHA provided to _Run Workflow_ does not exist:" - echo "${{inputs.sha}}" - } >> "$GITHUB_STEP_SUMMARY" - exit 1 - fi - - - if: github.event_name != 'workflow_dispatch' - name: Use ref ${{github.ref_name}} as the basis for comparison - run: | - echo base=${{github.ref_name}} >> "$GITHUB_ENV" - - - name: Check out a copy of the TFQ git repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - - - name: Determine files changed by this ${{github.event_name}} event - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3 - id: filter - with: - base: ${{env.base}} - list-files: 'shell' - # The outputs will be variables named "foo_files" for a filter "foo". - filters: | - python: - - added|modified: - - '**/*.py' - cc: - - added|modified: - - '**/*.cc' - - '**/*.h' - - '**/*.proto' - yaml: - - added|modified: - - '**/*.yaml' - - '**/*.yml' - - Setup: - if: needs.Changes.outputs.python == 'true' - needs: Changes - runs-on: ubuntu-22.04 - timeout-minutes: 10 - outputs: - cache_key: ${{steps.parameters.outputs.cache_key}} - cache_paths: ${{steps.parameters.outputs.cache_paths}} - steps: - - name: Check out a copy of the TFQ git repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - - # Note: setup-python has a cache facility, but we don't use it here - # because we want to cache more Python things than setup-python does. - - name: Set up Python ${{inputs.python_ver || env.python_ver}} - uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5 - with: - python-version: ${{inputs.python_ver || env.python_ver}} - - - name: Set cache keys and other parameters - id: parameters - run: | - key="${{github.workflow_ref}}-${{hashFiles('requirements.txt')}}" - echo "cache_key=$key" >> "$GITHUB_OUTPUT" - # The paths used for actions/cache need to be on separate lines. - # Constructing a multiline value for an output variable is awkward. - # shellcheck disable=SC2005 - { - echo "cache_paths<> "$GITHUB_OUTPUT" - - - name: Test if the cache already exists - uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4 - id: check_cache - with: - lookup-only: true - key: ${{steps.parameters.outputs.cache_key}} - path: ${{steps.parameters.outputs.cache_paths}} - - - if: >- - steps.check_cache.outputs.cache-hit == 'true' && - inputs.remake_python_cache == 'true' - name: Clear the Python cache - continue-on-error: true - env: - GH_TOKEN: ${{secrets.GITHUB_TOKEN}} - run: | - key="${{steps.parameters.outputs.cache_key}}" - gh extension install actions/gh-actions-cache - gh actions-cache delete "$key" --confirm - - - if: >- - steps.check_cache.outputs.cache-hit != 'true' || - inputs.remake_python_cache == 'true' - name: Set up the Python cache - uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4 - id: restore_cache - with: - key: ${{steps.parameters.outputs.cache_key}} - path: ${{steps.parameters.outputs.cache_paths}} - - - if: >- - steps.check_cache.outputs.cache-hit != 'true' || - inputs.remake_python_cache == 'true' - name: Install TFQ dependencies - # Need to install all requirements b/c Pylint needs to load modules. - run: | - pip install -r requirements.txt - - - if: ${{inputs.pylint_ver != ''}} - name: Install requested version ${{inputs.pylint_ver}} of Pylint - # Override version of Pylint installed from requirements.txt - run: | - set -x - pip install pylint==${{inputs.pylint_ver}} - - - if: ${{inputs.yapf_ver != ''}} - name: Install requested version ${{inputs.yapf_ver}} of Yapf - # Override version of Yapf installed from requirements.txt - run: | - set -x - pip install yapf==${{inputs.yapf_ver}} - - Cplusplus-format: - if: needs.Changes.outputs.cc == 'true' - name: Check C++ and Protobuf coding style - needs: Changes - runs-on: ubuntu-24.04 - env: - changed_files: ${{needs.Changes.outputs.cc_files}} - steps: - - name: Check out a copy of the TFQ git repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - - - name: Set up clang-format output problem matcher - run: echo '::add-matcher::.github/problem-matchers/clang-format.json' - - - name: Run clang-format on C++ and Protobuf files - run: | - set -x +e -o pipefail - version=${{inputs.clang_format_ver || env.clang_format_ver}} - clang-format-$version --verbose -Werror --style google --dry-run \ - ${{env.changed_files}} > diff.out 2>&1 - exit_code=$? - if [[ "$exit_code" != "0" ]]; then - # Write output both here and to the job summary. - bo=$'\e[1m'; bl=$'\e[38;5;117m'; rs=$'\e[0m'; hi='👋🏻' - u="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" - echo "$hi ${bl}Visit $bo$u${rs}$bl for formatted diff output$rs $hi" - echo '::group::clang-format output' - cat diff.out - echo '::endgroup::' - # shellcheck disable=SC2006 - { - echo "### Output from clang-format version $version" - echo '```diff' - echo "$(< diff.out)" - echo '```' - } >> "$GITHUB_STEP_SUMMARY" - fi - exit $exit_code - - Python-lint: - if: needs.Changes.outputs.python == 'true' - name: Check Python lint - needs: [Changes, Setup] - runs-on: ubuntu-22.04 - steps: - - name: Check out a copy of the TFQ git repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - - - name: Set up Python - uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5 - with: - python-version: ${{inputs.python_ver || env.python_ver}} - - - name: Restore the Python cache - uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4 - with: - key: ${{needs.Setup.outputs.cache_key}} - path: ${{needs.Setup.outputs.cache_paths}} - fail-on-cache-miss: true - - - name: Set up Pylint output problem matcher - run: echo '::add-matcher::.github/problem-matchers/pylint.json' - - - name: Lint the changed Python files - run: | - set +e -o pipefail - pylint -v ${{needs.Changes.outputs.python_files}} |& tee ./pylint.out - exit_code=$? - if [[ "$exit_code" != "0" ]]; then - { - echo '### Output from pylint' - echo '' - echo '```' - echo "$(< ./pylint.out)" - echo '```' - } >> "$GITHUB_STEP_SUMMARY" - fi - exit $exit_code - - Python-format: - if: needs.Changes.outputs.python == 'true' - name: Check Python coding style - needs: [Changes, Setup] - runs-on: ubuntu-22.04 - steps: - - name: Check out a copy of the TFQ git repository - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - - - name: Set up Python - uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5 - with: - python-version: ${{inputs.python_ver || env.python_ver}} - - - name: Restore the Python cache - uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f # v4 - with: - key: ${{needs.Setup.outputs.cache_key}} - path: ${{needs.Setup.outputs.cache_paths}} - fail-on-cache-miss: true - - - name: Run Yapf on the Python changed files - run: | - set +e - yapf --parallel --diff --style=google \ - ${{needs.Changes.outputs.python_files}} > diff.out 2>&1 - exit_code=$? - if [[ -s ./diff.out ]]; then - # Write output both here and to the job summary. - bo=$'\e[1m'; bl=$'\e[38;5;117m'; rs=$'\e[0m'; hi='👋🏻' - u="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" - echo "$hi ${bl}Visit $bo$u${rs}$bl for formatted diff output$rs $hi" - echo '::group::Yapf output' - cat diff.out - echo '::endgroup::' - # shellcheck disable=SC2006 - { - echo '### Output from yapf' - echo '' - echo '```diff' - echo "$(< diff.out)" - echo '```' - } >> "$GITHUB_STEP_SUMMARY" - fi - exit $exit_code - - Yaml-lint: - if: needs.Changes.outputs.yaml == 'true' - name: YAML lint - needs: Changes - runs-on: ubuntu-24.04 - steps: - - name: Check out a copy of the TFQ git repository - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4 - - - name: Set up yamllint output problem matcher - run: echo '::add-matcher::.github/problem-matchers/yamllint.json' - - - name: Find out the yamllint version - id: yamllint - run: | - version=$(yamllint --version) - echo "version=${version#yamllint }" >> "$GITHUB_OUTPUT" - - - name: Run yamllint ${{steps.yamllint.outputs.version}} - run: | - set -x - # shellcheck disable=SC2086 - yamllint --format github ${{needs.Changes.outputs.yaml_files}} diff --git a/.github/workflows/ci-build-checks.yaml b/.github/workflows/ci.yaml similarity index 61% rename from .github/workflows/ci-build-checks.yaml rename to .github/workflows/ci.yaml index b7ff4461b..d86e1e0fd 100644 --- a/.github/workflows/ci-build-checks.yaml +++ b/.github/workflows/ci.yaml @@ -12,8 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -name: 'CI: build & test' -run-name: Continuous integration build and test +name: CI +run-name: >- + Run CI checks on ${{ + github.event_name == 'pull_request' + && format('PR #{0}', github.event.pull_request.number) + || github.event_name + }} by @${{github.actor}} on: pull_request: @@ -24,6 +29,10 @@ on: types: - checks_requested +env: + # Python version to use for actions/setup-python. + python-version: '3.11' + concurrency: cancel-in-progress: true group: ${{github.workflow}}-${{github.event.pull_request.number||github.ref}} @@ -31,22 +40,55 @@ concurrency: permissions: read-all jobs: + format-and-lint-checks: + name: File format & lint checks + runs-on: ubuntu-22.04 + timeout-minutes: 30 + steps: + - name: Check out a copy of the TFQ git repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + with: + python-version: ${{env.python-version}} + cache: pip + cache-dependency-path: requirements.txt + + - name: Install Python dependencies + run: | + pip install --upgrade pip + pip install -r requirements.txt + + - name: Check code formatting + run: ./scripts/format_check.sh + + - name: Check code lint + run: ./scripts/lint_all.sh + wheel-build: name: Wheel test runs-on: ubuntu-22.04 timeout-minutes: 60 - steps: - - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - - uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v5 + - name: Check out a copy of the TFQ git repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Set up Python + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: - python-version: '3.10' - architecture: 'x64' + python-version: ${{env.python-version}} cache: pip + cache-dependency-path: requirements.txt + - name: Install Bazel on CI run: ./scripts/ci_install.sh + - name: Build Wheel Test run: ./scripts/build_pip_package_test.sh + - name: Test Wheel run: ./scripts/run_example.sh @@ -56,7 +98,6 @@ jobs: container: image: us-docker.pkg.dev/ml-oss-artifacts-published/ml-public-container/ml-build:infrastructure-public-image-82c7ac59ba4b timeout-minutes: 60 - steps: - name: Adjust the ml-build runner to our needs run: | @@ -64,16 +105,23 @@ jobs: sudo apt-get update && sudo apt-get install -y lsb-release # This file, though it's empty, hangs the Bazel install step. rm -f /etc/bazel.bazelrc - - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - - uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v5 + + - name: Check out a copy of the TFQ git repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Set up Python + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: - python-version: '3.10' - architecture: 'x64' + python-version: ${{env.python-version}} cache: pip + cache-dependency-path: requirements.txt + - name: Install Bazel on CI run: ./scripts/ci_install.sh + - name: Configure CI TF run: echo "Y\n" | ./configure.sh + - name: Full Library Test run: ./scripts/test_all.sh @@ -105,7 +153,6 @@ jobs: container: image: us-docker.pkg.dev/ml-oss-artifacts-published/ml-public-container/ml-build:infrastructure-public-image-82c7ac59ba4b timeout-minutes: 60 - steps: - name: Adjust the ml-build runner to our needs run: | @@ -113,17 +160,25 @@ jobs: sudo apt-get update && sudo apt-get install -y lsb-release # This file, though it's empty, hangs the Bazel install step. rm -f /etc/bazel.bazelrc - - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - - uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v5 + + - name: Check out a copy of the TFQ git repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Set up Python + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 with: - python-version: '3.10' - architecture: 'x64' + python-version: ${{env.python-version}} cache: pip - - name: Install notebook dependencies - run: pip install --upgrade pip seaborn==0.10.0 + cache-dependency-path: requirements.txt + + - name: Upgrade pip + run: pip install --upgrade pip + - name: Install Bazel on CI run: ./scripts/ci_install.sh + - name: Build Wheel run: ./scripts/build_pip_package_test.sh + - name: Test Notebooks run: ./scripts/ci_validate_tutorials.sh