diff --git a/.github/ci/path-policy.json b/.github/ci/path-policy.json new file mode 100644 index 0000000000..c2edb15270 --- /dev/null +++ b/.github/ci/path-policy.json @@ -0,0 +1,18 @@ +{ + "version": 1, + "rules": [ + { + "class": "generated-docs", + "include": "^docs/src/main/(paradox|categories)/.*\\.[mM][dD]$" + }, + { + "class": "prose", + "include": "\\.[mM][dD]$", + "exclude": "(^|/)src/" + }, + { + "class": "prose", + "include": "^remote/src/test/resources/ssl/(pem/)?README\\.md$" + } + ] +} diff --git a/.github/workflows/binary-compatibility-checks.yml b/.github/workflows/binary-compatibility-checks.yml index bcc352d10b..3bc0b38e0f 100644 --- a/.github/workflows/binary-compatibility-checks.yml +++ b/.github/workflows/binary-compatibility-checks.yml @@ -27,10 +27,16 @@ on: permissions: {} jobs: + classify-changes: + if: github.event_name == 'pull_request' + uses: ./.github/workflows/classify-pr-changes.yml + permissions: + contents: read check-binary-compatibility: + needs: classify-changes + if: always() && !cancelled() && github.repository == 'apache/pekko' && (github.event_name != 'pull_request' || needs.classify-changes.result != 'success' || (needs.classify-changes.outputs.validation-plan != 'prose' && needs.classify-changes.outputs.validation-plan != 'generated')) name: Check / Binary Compatibility runs-on: ubuntu-22.04 - if: github.repository == 'apache/pekko' strategy: fail-fast: false env: diff --git a/.github/workflows/build-test-prValidation.yml b/.github/workflows/build-test-prValidation.yml index ca0d651c1c..b7deaef4bd 100644 --- a/.github/workflows/build-test-prValidation.yml +++ b/.github/workflows/build-test-prValidation.yml @@ -19,7 +19,13 @@ concurrency: cancel-in-progress: true jobs: + classify-changes: + uses: ./.github/workflows/classify-pr-changes.yml + permissions: + contents: read check-code-style: + needs: classify-changes + if: always() && !cancelled() && (needs.classify-changes.result != 'success' || (needs.classify-changes.outputs.validation-plan != 'prose' && needs.classify-changes.outputs.validation-plan != 'generated')) name: Check / Code Style runs-on: ubuntu-22.04 env: @@ -53,6 +59,8 @@ jobs: -Dsbt.log.noformat=false \ checkCodeStyle pull-request-validation: + needs: classify-changes + if: always() && !cancelled() && (needs.classify-changes.result != 'success' || (needs.classify-changes.outputs.validation-plan != 'prose' && needs.classify-changes.outputs.validation-plan != 'generated')) name: Check / Tests runs-on: ubuntu-22.04 env: @@ -118,9 +126,10 @@ jobs: "++ ${scala_version}! validatePullRequest" pekko-classic-remoting-tests: + needs: classify-changes + if: always() && !cancelled() && github.repository == 'apache/pekko' && (needs.classify-changes.result != 'success' || (needs.classify-changes.outputs.validation-plan != 'prose' && needs.classify-changes.outputs.validation-plan != 'generated')) name: Pekko Classic Remoting Tests runs-on: ubuntu-22.04 - if: github.repository == 'apache/pekko' strategy: fail-fast: false matrix: @@ -167,6 +176,8 @@ jobs: clean ${{ matrix.command }} jdk-21-extra-tests: + needs: classify-changes + if: always() && !cancelled() && (needs.classify-changes.result != 'success' || (needs.classify-changes.outputs.validation-plan != 'prose' && needs.classify-changes.outputs.validation-plan != 'generated')) name: Java 21 Extra Tests runs-on: ubuntu-22.04 env: diff --git a/.github/workflows/classify-pr-changes.yml b/.github/workflows/classify-pr-changes.yml new file mode 100644 index 0000000000..3a295611ba --- /dev/null +++ b/.github/workflows/classify-pr-changes.yml @@ -0,0 +1,104 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +name: Classify pull request changes + +on: + workflow_call: + inputs: + policy-path: + description: Repository-relative path to the classification policy on the PR base + type: string + default: .github/ci/path-policy.json + outputs: + validation-plan: + description: Validation level (full, prose, or generated) + value: ${{ jobs.classify.outputs.validation-plan }} + +permissions: + contents: read + +jobs: + classify: + runs-on: ubuntu-22.04 + timeout-minutes: 2 + outputs: + validation-plan: ${{ steps.changed-paths.outputs.validation-plan }} + steps: + - id: changed-paths + shell: bash + env: + GH_TOKEN: ${{ github.token }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + CHANGED_FILES: ${{ github.event.pull_request.changed_files }} + POLICY_PATH: ${{ inputs.policy-path }} + run: | + # Read the repository's policy from the immutable base, never the PR's proposed policy. + # Compare supplies at most 300 files. Missing policy, data, or classifications run full CI. + validation_plan=full + if [[ "$CHANGED_FILES" =~ ^[1-9][0-9]{0,2}$ && "$CHANGED_FILES" -le 300 && + "$BASE_SHA" =~ ^[0-9a-f]{40}$ && "$HEAD_SHA" =~ ^[0-9a-f]{40}$ && + "$POLICY_PATH" =~ ^[A-Za-z0-9._-]+(/[A-Za-z0-9._-]+)*$ && + "$POLICY_PATH" != *..* && "/$POLICY_PATH/" != *"/./"* ]]; then + if policy=$(gh api "repos/$GITHUB_REPOSITORY/contents/$POLICY_PATH?ref=$BASE_SHA" | + jq -er 'select(.type == "file" and .encoding == "base64") | .content' | base64 --decode) && + result=$(gh api "repos/$GITHUB_REPOSITORY/compare/$BASE_SHA...$HEAD_SHA?per_page=1" | + jq -r --argjson count "$CHANGED_FILES" --argjson policy "$policy" --arg policy_path "$POLICY_PATH" ' + def valid_regex: + . as $pattern | + type == "string" and length > 0 and + (try ("" | test($pattern) | type == "boolean") catch false); + def valid_rule: + (.class == "prose" or .class == "generated-docs") + and (.include | valid_regex) + and (.exclude == null or (.exclude | valid_regex)); + def matches($name; $kind): + any($policy.rules[]; .class == $kind and + (.include as $include | .exclude as $exclude | + ($name | test($include)) and ($exclude == null or ($name | test($exclude) | not)))); + def path_class: + . as $name | + if type != "string" or length == 0 or $name == $policy_path or + test("^\\.github/(workflows|actions|ci)/") then "full" + elif matches($name; "generated-docs") then "generated" + elif matches($name; "prose") then "prose" + else "full" + end; + def changed_paths: + if .status == "renamed" and (.previous_filename | type == "string") + then [.filename, .previous_filename] + elif (.status == "added" or .status == "removed" or .status == "modified") and .previous_filename == null + then [.filename] + else [null] + end; + if $policy.version != 1 or ($policy.rules | type != "array" or length == 0 or + (all(.[]; valid_rule) | not)) then "full" + elif (.files | type != "array" or length != $count) then "full" + else [.files[] | changed_paths[] | path_class] | + if any(.[]; . == "full") then "full" + elif any(.[]; . == "generated") then "generated" + else "prose" + end + end + '); then + case "$result" in + prose|generated) validation_plan="$result" ;; + esac + fi + fi + echo "validation-plan=$validation_plan" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index d08180e494..cd447a9fc1 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -24,7 +24,14 @@ on: branches: ['**'] jobs: + classify-changes: + uses: ./.github/workflows/classify-pr-changes.yml + permissions: + contents: read build: + # Keep emitting this required check; an uncertain classification runs the original job. + needs: classify-changes + if: always() && !cancelled() && (needs.classify-changes.result != 'success' || (needs.classify-changes.outputs.validation-plan != 'prose' && needs.classify-changes.outputs.validation-plan != 'generated')) name: Code is formatted runs-on: ubuntu-26.04 steps: diff --git a/.github/workflows/generate-doc-check.yml b/.github/workflows/generate-doc-check.yml index dd0c08ab38..30b86dc02e 100644 --- a/.github/workflows/generate-doc-check.yml +++ b/.github/workflows/generate-doc-check.yml @@ -24,10 +24,15 @@ permissions: contents: read jobs: + classify-changes: + uses: ./.github/workflows/classify-pr-changes.yml + permissions: + contents: read generate-doc-check: + needs: classify-changes + if: always() && !cancelled() && github.repository == 'apache/pekko' && (needs.classify-changes.result != 'success' || needs.classify-changes.outputs.validation-plan != 'prose') name: Generate doc check runs-on: ubuntu-22.04 - if: github.repository == 'apache/pekko' steps: - name: Checkout uses: actions/checkout@v7.0.1 @@ -52,7 +57,14 @@ jobs: run: |- sudo apt-get install graphviz + - name: Generate Paradox documentation + if: needs.classify-changes.result == 'success' && needs.classify-changes.outputs.validation-plan == 'generated' + env: + DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }} + run: sbt docs/paradox + - name: Compile testClass&docs for all Scala versions + if: needs.classify-changes.result != 'success' || needs.classify-changes.outputs.validation-plan != 'generated' env: DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }} run: sbt ";+TestJdk21 / compile ; +compile:doc" diff --git a/.github/workflows/headers.yml b/.github/workflows/headers.yml index c85f38cb22..cb5965381b 100644 --- a/.github/workflows/headers.yml +++ b/.github/workflows/headers.yml @@ -23,7 +23,14 @@ on: permissions: {} jobs: + classify-changes: + uses: ./.github/workflows/classify-pr-changes.yml + permissions: + contents: read check-headers: + # Keep emitting this required check; an uncertain classification runs the original job. + needs: classify-changes + if: always() && !cancelled() && (needs.classify-changes.result != 'success' || (needs.classify-changes.outputs.validation-plan != 'prose' && needs.classify-changes.outputs.validation-plan != 'generated')) name: Check headers runs-on: ubuntu-22.04 steps: