From 81005890a3a4a7ed94a5960121875f062ea39c4a Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 9 Mar 2026 14:59:17 +0000 Subject: [PATCH] Add `changed-files` action --- .github/actions/changed-files/action.yml | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/actions/changed-files/action.yml diff --git a/.github/actions/changed-files/action.yml b/.github/actions/changed-files/action.yml new file mode 100644 index 000000000..43252a20a --- /dev/null +++ b/.github/actions/changed-files/action.yml @@ -0,0 +1,53 @@ +name: Get changed files +description: Outputs a stringified JSON array of changed files for a PR +inputs: + github-token: + description: GitHub token + required: true + pattern: + description: "The glob pattern to use to check for changed files" + required: true + default: "${{ github.workspace }}/**/*" + exclude: + description: "A stringified JSON array of files to exclude" + required: false + default: "[]" +outputs: + files: + description: Stringified JSON array of changed file paths + value: ${{ steps.changed-files.outputs.files }} +runs: + using: "composite" + steps: + - name: Get changed files + id: changed-files + uses: actions/github-script@v7 + env: + PATTERN: ${{ inputs.pattern }} + EXCLUDE: ${{ inputs.exclude }} + with: + github-token: ${{ inputs.github-token }} + script: | + const exclude = JSON.parse(process.env['EXCLUDE']); + const path = require('path'); + const pr = context.payload.pull_request; + if (!pr) { + core.setOutput('files', JSON.stringify([])); + return; + } + const files = await github.paginate( + github.rest.pulls.listFiles, + { + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pr.number, + per_page: 100 + } + ); + const results = files + .filter(f => path.matchesGlob( + f.filename, process.env['PATTERN'] + ) && !exclude.includes(f.filename)) + .map(f => f.filename); + console.debug(results); + core.setOutput('files', JSON.stringify(results));