Skip to content

Commit

Permalink
feat: add support for retrieving changed files via github rest api (#…
Browse files Browse the repository at this point in the history
…1289)

Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: tj-actions[bot] <[email protected]>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Jun 23, 2023
1 parent c4a394a commit fd5b3a4
Show file tree
Hide file tree
Showing 14 changed files with 8,420 additions and 199 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ jobs:
uses: actions/download-artifact@v3
with:
name: build-assets
path: dir1/dist

- name: Run changed-files with defaults on the dir1
id: changed-files-dir1
Expand All @@ -153,6 +154,12 @@ jobs:
shell:
bash

- name: Download build assets
uses: actions/download-artifact@v3
with:
name: build-assets
path: dir2/dist

- name: Checkout into dir2
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -508,6 +515,38 @@ jobs:
echo "Expected: (failure) got ${{ steps.changed-files-specific.outcome }}"
exit 1
test-rest-api:
name: Test changed-files with REST API
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'push'
permissions:
pull-requests: read
steps:
- name: Checkout into dir1
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true
fetch-depth: 0
path: dir1

- name: Download build assets
uses: actions/download-artifact@v3
with:
name: build-assets
path: dir1/dist

- name: Run changed-files with REST API
id: changed-files
uses: ./dir1

- name: Show output
run: |
echo '${{ toJSON(steps.changed-files.outputs) }}'
shell:
bash

test-submodules:
name: Test changed-files with submodule
runs-on: ubuntu-latest
Expand Down
40 changes: 31 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Effortlessly track all changed files and directories relative to a target branch
## Features

* Provides fast execution, averaging 0-10 seconds.
* Leverages either [Github's REST API](https://docs.github.com/en/rest/reference/repos#list-commits) or [Git's native diff](https://git-scm.com/docs/git-diff) to determine changed files.
* Facilitates easy debugging.
* Scales to handle large repositories.
* Supports Git submodules.
Expand Down Expand Up @@ -91,13 +92,34 @@ on:
branches:
- main

# ------------------------------------------------------------------------------------------------------------
# Event `push`: Compare the preceding commit -> to the current commit of the main branch.
# Event `pull_request`: Compare the last commit of main -> to the current commit of a Pull Request branch.
# ------------------------------------------------------------------------------------------------------------

jobs:
job1: # Example 1
# -------------------------------------------------------------
# Event `pull_request`: Returns all changed pull request files.
# --------------------------------------------------------------
job1: # Example 1 - Using GitHub's API
# NOTE:
# - This is limited to pull_request* events and would raise an error for other events.
# - A maximum of 3000 files can be returned.
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@v36

- name: List all changed files
run: |
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo "$file was changed"
done
# ------------------------------------------------------------------------------------------------------------
# Event `push`: Compare the preceding commit -> to the current commit of the main branch.
# Event `pull_request`: Compare the last commit of main -> to the current commit of a Pull Request branch.
# ------------------------------------------------------------------------------------------------------------
job2: # Example 2 - Using local .git history
runs-on: ubuntu-latest # windows-latest | macos-latest
name: Test changed-files
steps:
Expand All @@ -119,7 +141,7 @@ jobs:
echo "$file was changed"
done
job2: # Example 2
job3: # Example 3 - Using local .git history
runs-on: ubuntu-latest # windows-latest | macos-latest
name: Test changed-files
steps:
Expand All @@ -139,7 +161,7 @@ jobs:
echo "One or more files in the docs folder has changed."
echo "List all the files that have changed: ${{ steps.changed-files-specific.outputs.all_changed_files }}"
job3: # Example 3
job4: # Example 4 - Using local .git history
runs-on: ubuntu-latest # windows-latest | macos-latest
name: Test changed-files
steps:
Expand All @@ -162,7 +184,7 @@ jobs:
echo "One or more .js file(s) or any file in the static folder but not in the doc folder has changed."
echo "List all the files that have changed: ${{ steps.changed-files-excluded.outputs.all_changed_files }}"
job4: # Example 4
job5: # Example 5 - Using local .git history
runs-on: ubuntu-latest # windows-latest | macos-latest
name: Test changed-files
steps:
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ inputs:
description: "Recover deleted files to a new destination directory, defaults to the original location."
required: false
default: ""
token:
description: "Github token used to fetch changed files from Github's API."
required: false
default: ${{ github.token }}
api_url:
description: "Github API URL."
required: false
default: ${{ github.api_url }}

outputs:
added_files:
Expand Down
Loading

0 comments on commit fd5b3a4

Please sign in to comment.