changed-files

changed-files

GitHub Action工具实现高效文件变更追踪

changed-files是一个GitHub Action工具,用于追踪项目中的文件和目录变更。它可以检测相对于目标分支、当前分支或自定义提交的变化,支持pull request、push等多种触发事件。该工具执行迅速,适用于大型仓库,功能包括glob模式文件匹配、JSON输出生成和Git子模块支持等。changed-files为开发者提供了高效的文件变更追踪方案。

GitHub Actions代码变更检测工作流自动化持续集成版本控制Github开源项目

Ubuntu Mac OS Windows Public workflows that use this action.

Codacy Badge CI Update release version.

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

All Contributors

<!-- ALL-CONTRIBUTORS-BADGE:END -->

changed-files

Effortlessly track all changed files and directories relative to a target branch, the current branch (preceding commit or the last remote commit), multiple branches, or custom commits returning relative paths from the project root using this GitHub action.

[!NOTE]

Table of contents

Features 🚀

  • Fast execution, averaging 0-10 seconds.
  • Leverages either Github's REST API or Git's native diff to determine changed files.
  • Facilitates easy debugging.
  • Scales to handle large/mono repositories.
  • Supports Git submodules.
  • Supports merge queues for pull requests.
  • Generates escaped JSON output for running matrix jobs based on changed files.
  • Lists changed directories.
    • Limits matching changed directories to a specified maximum depth.
    • Optionally excludes the current directory.
  • Writes outputs to a designated .txt or .json file for further processing.
  • Restores deleted files to their previous location or a newly specified location.
  • Supports fetching a fixed number of commits which improves performance.
  • Compatible with all platforms (Linux, MacOS, Windows).
  • Supports GitHub-hosted runners.
  • Supports GitHub Enterprise Server.
  • Supports self-hosted runners.
  • Lists all files and directories that have changed:
    • Between the current pull request branch and the last commit on the target branch.
    • Between the last commit and the current pushed change.
    • Between the last remote branch commit and the current HEAD.
  • Restricts change detection to a subset of files and directories:

And many more...

Usage 💻

[!IMPORTANT]

  • Push Events: When configuring actions/checkout, make sure to set fetch-depth to either 0 or 2, depending on your use case.
  • Mono Repositories: To avoid pulling the entire branch history, you can utilize the default actions/checkout's fetch-depth of 1 for pull_request events.
  • Quoting Multiline Inputs: Avoid using single or double quotes for multiline inputs. The value is already a string separated by a newline character. Refer to the Examples section for more information.
  • Credentials Persistence: If fetch-depth is not set to 0, make sure to set persist-credentials to true when configuring actions/checkout.
  • Matching Files and Folders: To match all files and folders under a directory, this requires a globstar pattern e.g. dir_name/** which matches any number of subdirectories and files.

Visit the discussions for more information or create a new discussion for usage-related questions.

On pull_request 🔀

Detect changes to all files in a Pull request relative to the target branch or since the last pushed commit.

Using local .git directory 📁

name: CI on: pull_request: branches: - main jobs: # ------------------------------------------------------------------------------------------------------------------------------------------------ # Event `pull_request`: Compare the last commit of the main branch or last remote commit of the PR branch -> to the current commit of a PR branch. # ------------------------------------------------------------------------------------------------------------------------------------------------ changed_files: runs-on: ubuntu-latest # windows-latest || macos-latest name: Test changed-files steps: - uses: actions/checkout@v4 # ----------------------------------------------------------------------------------------------------------- # Example 1 # ----------------------------------------------------------------------------------------------------------- - name: Get changed files id: changed-files uses: tj-actions/changed-files@v44 # To compare changes between the current commit and the last pushed remote commit set `since_last_remote_commit: true`. e.g # with: # since_last_remote_commit: true - name: List all changed files env: ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} run: | for file in ${ALL_CHANGED_FILES}; do echo "$file was changed" done # ----------------------------------------------------------------------------------------------------------- # Example 2 # ----------------------------------------------------------------------------------------------------------- - name: Get all changed markdown files id: changed-markdown-files uses: tj-actions/changed-files@v44 with: # Avoid using single or double quotes for multiline patterns files: | **.md - name: List all changed files markdown files if: steps.changed-markdown-files.outputs.any_changed == 'true' env: ALL_CHANGED_FILES: ${{ steps.changed-markdown-files.outputs.all_changed_files }} run: | for file in ${ALL_CHANGED_FILES}; do echo "$file was changed" done # ----------------------------------------------------------------------------------------------------------- # Example 3 # ----------------------------------------------------------------------------------------------------------- - name: Get all test, doc and src files that have changed id: changed-files-yaml uses: tj-actions/changed-files@v44 with: files_yaml: | doc: - '**.md' - docs/** test: - test/** - '!test/**.md' src: - src/** # Optionally set `files_yaml_from_source_file` to read the YAML from a file. e.g `files_yaml_from_source_file: .github/changed-files.yml` - name: Run step if test file(s) change # NOTE: Ensure all outputs are prefixed by the same key used above e.g. `test_(...)` | `doc_(...)` | `src_(...)` when trying to access the `any_changed` output. if: steps.changed-files-yaml.outputs.test_any_changed == 'true' env: TEST_ALL_CHANGED_FILES: ${{ steps.changed-files-yaml.outputs.test_all_changed_files }} run: | echo "One or more test file(s) has changed." echo "List all the files that have changed: $TEST_ALL_CHANGED_FILES" - name: Run step if doc file(s) change if: steps.changed-files-yaml.outputs.doc_any_changed == 'true' env: DOC_ALL_CHANGED_FILES: ${{ steps.changed-files-yaml.outputs.doc_all_changed_files }} run: | echo "One or more doc file(s) has changed." echo "List all the files that have changed: $DOC_ALL_CHANGED_FILES" # ----------------------------------------------------------------------------------------------------------- # Example 4 # ----------------------------------------------------------------------------------------------------------- - name: Get changed files in the docs folder id: changed-files-specific uses: tj-actions/changed-files@v44 with: files: docs/*.{js,html} # Alternatively using: `docs/**` files_ignore: docs/static.js - name: Run step if any file(s) in the docs folder change if: steps.changed-files-specific.outputs.any_changed == 'true' env: ALL_CHANGED_FILES: ${{ steps.changed-files-specific.outputs.all_changed_files }} run: | echo "One or more files in the docs folder has changed." echo "List all the files that have changed: $ALL_CHANGED_FILES"

Using Github's API :octocat:

name: CI on: pull_request: branches: - main jobs: # ------------------------------------------------------------- # Event `pull_request`: Returns all changed pull request files. # -------------------------------------------------------------- changed_files: # NOTE: # - This is limited to pull_request* events and would raise an error for other events. # - A maximum of 3000 files can be returned. # - For more flexibility and no limitations see "Using local .git directory" above. runs-on: ubuntu-latest # windows-latest || macos-latest name: Test changed-files permissions: pull-requests: read steps: - name: Get changed files id: changed-files uses: tj-actions/changed-files@v44 - name: List all changed files env: ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} run: | for file in ${ALL_CHANGED_FILES}; do echo "$file was changed" done

On push ⬆️

Detect changes to files made since the last pushed commit.

name: CI on: push: branches: - main jobs: # ------------------------------------------------------------- # Using GitHub's API is not supported for push events # ------------------------------------------------------------- # # ---------------------------------------------------------------------------------------------- # Using local .git history # ---------------------------------------------------------------------------------------------- # Event `push`: Compare the preceding remote commit -> to the current commit of the main branch # ---------------------------------------------------------------------------------------------- changed_files: runs-on: ubuntu-latest # windows-latest || macos-latest name: Test changed-files steps: - uses: actions/checkout@v4 with: fetch-depth: 0 # OR "2" -> To retrieve the preceding commit. - name: Get changed files id: changed-files uses: tj-actions/changed-files@v44 # NOTE: `since_last_remote_commit: true` is implied by default and falls back to the previous local commit. - name: List all changed files env: ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} run: | for file in ${ALL_CHANGED_FILES}; do echo "$file was changed" done ...

Other supported events :electron:

To access more examples, navigate to the Examples section.

If you feel generous and want to show some extra appreciation:

Support this project with a :star:

Buy me a coffee

[!IMPORTANT]

  • When using files_yaml* inputs:
    • All keys must start with a letter or _ and contain only alphanumeric characters, -, or _.

      For example, test or test_key or test-key or _test_key are all valid choices.

Inputs ⚙️

<!-- AUTO-DOC-INPUT:START - Do not remove or modify this section -->
- uses: tj-actions/changed-files@v44 id: changed-files with: # Github API URL. # Type: string # Default: "${{ github.api_url }}" api_url: '' # Specify a different base commit # SHA or branch used for # comparing changes # Type: string base_sha: '' # Exclude changes outside the current # directory and show path names # relative to it. NOTE: This # requires you to specify the # top-level directory via the `path` # input. # Type: boolean # Default: "true" diff_relative: ''

编辑推荐精选

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

AI辅助写作AI工具AI论文工具论文写作智能生成大纲数据安全AI助手热门
博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

iTerms

iTerms

企业专属的AI法律顾问

iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。

SimilarWeb流量提升

SimilarWeb流量提升

稳定高效的流量提升解决方案,助力品牌曝光

稳定高效的流量提升解决方案,助力品牌曝光

Sora2视频免费生成

Sora2视频免费生成

最新版Sora2模型免费使用,一键生成无水印视频

最新版Sora2模型免费使用,一键生成无水印视频

下拉加载更多