From bd39a37da2617e8176e621c0bcfd305515d2ebae Mon Sep 17 00:00:00 2001 From: Levente Balogh Date: Thu, 28 May 2026 11:46:43 +0200 Subject: [PATCH] refactor(ci): replace 3rd-party path-filter actions with local composite Adds a local composite at .github/actions/paths-filter that lists changed files via `gh api /repos/.../pulls/{n}/files --paginate` and matches them against newline-separated bash glob patterns. - Drops `dorny/paths-filter` from test-build.yml. - Drops `tj-actions/changed-files` from metadata-lint.yml; removes the now-unused `change-detection` composite that wrapped it. --- .github/actions/change-detection/action.yml | 39 ------------- .github/actions/paths-filter/action.yml | 64 +++++++++++++++++++++ .github/workflows/metadata-lint.yml | 13 +++-- .github/workflows/test-build.yml | 21 ++++--- 4 files changed, 84 insertions(+), 53 deletions(-) delete mode 100644 .github/actions/change-detection/action.yml create mode 100644 .github/actions/paths-filter/action.yml diff --git a/.github/actions/change-detection/action.yml b/.github/actions/change-detection/action.yml deleted file mode 100644 index 7c3422f5e4..0000000000 --- a/.github/actions/change-detection/action.yml +++ /dev/null @@ -1,39 +0,0 @@ - -name: Detect changed files -description: Detects whether any matching files have changed in the current PR -inputs: - self: - description: The path to the calling workflow (for example `.github/workflows/backend-unit-tests.yml`). Change detection always treats this file as part of every category. - required: true -outputs: - self: - description: Whether the calling workflow has changed in any way - value: ${{ steps.changed-files.outputs.self_any_changed || 'true' }} - docs: - description: Whether the docs or self have changed in any way - value: ${{ steps.changed-files.outputs.docs_any_changed || 'true' }} -runs: - using: composite - steps: - # Assumption: We've done a checkout with the actions/checkout action. - # It must persist credentials to allow the changed-files action to get more history. - - name: Detect changes - id: changed-files - if: github.event_name == 'pull_request' - uses: tj-actions/changed-files@7dee1b0c1557f278e5c7dc244927139d78c0e22a # v47.0.4 - with: - files_yaml: | - self: - - '.github/actions/change-detection/**' - - '${{ inputs.self }}' - docs: - - 'docusaurus/docs/**' - - '.github/actions/change-detection/**' - - '${{ inputs.self }}' - - name: Print all change groups - shell: bash - run: | - echo "Self: ${{ steps.changed-files.outputs.self_any_changed || 'true' }}" - echo " --> ${{ steps.changed-files.outputs.self_all_changed_files }}" - echo "Docs: ${{ steps.changed-files.outputs.docs_any_changed || 'true' }}" - echo " --> ${{ steps.changed-files.outputs.docs_all_changed_files }}" diff --git a/.github/actions/paths-filter/action.yml b/.github/actions/paths-filter/action.yml new file mode 100644 index 0000000000..6833925748 --- /dev/null +++ b/.github/actions/paths-filter/action.yml @@ -0,0 +1,64 @@ +name: Paths filter +description: Detects whether any file changed in the current PR matches at least one of the supplied glob patterns. + +inputs: + patterns: + description: | + Newline-separated list of glob patterns to match against the changed files + in the PR. Patterns use bash glob syntax (e.g. `path/**`, `path/file.ext`). + required: true + +outputs: + changed: + description: '`''true''` if at least one changed file matches one of the patterns, otherwise `''false''`. Always `''true''` on non-pull_request events.' + value: ${{ steps.filter.outputs.changed }} + +runs: + using: composite + steps: + - name: Match changed files against patterns + id: filter + shell: bash + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + EVENT_NAME: ${{ github.event_name }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PATTERNS: ${{ inputs.patterns }} + run: | + set -euo pipefail + + if [[ "${EVENT_NAME}" != "pull_request" && "${EVENT_NAME}" != "pull_request_target" ]]; then + echo "Event '${EVENT_NAME}' is not a pull_request; defaulting changed=true." + echo "changed=true" >> "${GITHUB_OUTPUT}" + exit 0 + fi + + mapfile -t patterns < <(printf '%s\n' "${PATTERNS}" | sed -E 's/^[[:space:]]+|[[:space:]]+$//g' | grep -v '^$' || true) + if [[ ${#patterns[@]} -eq 0 ]]; then + echo "No patterns supplied; nothing to match." + echo "changed=false" >> "${GITHUB_OUTPUT}" + exit 0 + fi + + echo "Patterns:" + printf ' %s\n' "${patterns[@]}" + + mapfile -t changed_files < <(gh api --paginate "/repos/${REPO}/pulls/${PR_NUMBER}/files" --jq '.[].filename') + echo "Changed files (${#changed_files[@]}):" + printf ' %s\n' "${changed_files[@]:-(none)}" + + shopt -s extglob + any_match=false + for file in "${changed_files[@]:-}"; do + [[ -z "${file}" ]] && continue + for pattern in "${patterns[@]}"; do + if [[ "${file}" == ${pattern} ]]; then + echo "Match: ${file} ~ ${pattern}" + any_match=true + break + fi + done + done + + echo "changed=${any_match}" >> "${GITHUB_OUTPUT}" diff --git a/.github/workflows/metadata-lint.yml b/.github/workflows/metadata-lint.yml index 1957f76c31..92c7a767a6 100644 --- a/.github/workflows/metadata-lint.yml +++ b/.github/workflows/metadata-lint.yml @@ -13,18 +13,21 @@ jobs: runs-on: ubuntu-latest permissions: contents: read + pull-requests: read outputs: - docs: ${{ steps.detect-changes.outputs.docs }} + docs: ${{ steps.detect-changes.outputs.changed }} steps: - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 with: - persist-credentials: true # required to get more history in the changed-files action - fetch-depth: 2 + persist-credentials: false - name: Detect changes id: detect-changes - uses: ./.github/actions/change-detection + uses: ./.github/actions/paths-filter with: - self: .github/workflows/metadata-lint.yml + patterns: | + .github/workflows/metadata-lint.yml + .github/actions/paths-filter/** + docusaurus/docs/** lint-metadata: needs: detect-changes diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index 55759b1af0..dd2cfc7d02 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -14,18 +14,21 @@ jobs: permissions: pull-requests: read outputs: - docs: ${{ steps.filter.outputs.docs }} + docs: ${{ steps.filter.outputs.changed }} steps: - - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - uses: ./.github/actions/paths-filter id: filter with: - filters: | - docs: - - '.github/workflows/deploy-to-developer-portal-dev.yml' - - '.github/workflows/deploy-to-developer-portal-prod.yml' - - '.github/workflows/test-build.yml' - - 'docusaurus/**' - - 'package-lock.json' + patterns: | + .github/workflows/deploy-to-developer-portal-dev.yml + .github/workflows/deploy-to-developer-portal-prod.yml + .github/workflows/test-build.yml + .github/actions/paths-filter/** + docusaurus/** + package-lock.json build-docs: needs: changes