Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for retrieving changed files via github rest api #1289

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bec5861
feat: add support for retrieving changed files via github rest api
jackton1 Jun 23, 2023
d1e3ff8
Fixed lint errors
jackton1 Jun 23, 2023
2eb11f6
Updated check
jackton1 Jun 23, 2023
ca880f4
Fixed the test
jackton1 Jun 23, 2023
df7d06f
Updated the test
jackton1 Jun 23, 2023
b0c1b49
Updated the test
jackton1 Jun 23, 2023
efe3e32
Update to fetch changes at most once
jackton1 Jun 23, 2023
71c896b
Revert change
jackton1 Jun 23, 2023
d2a6112
Updated silent setting.
jackton1 Jun 23, 2023
2b9972b
Merge d2a611248f09ceb00de1306eb79d8588d9acb22b into 50ae49b0e4dc2c5bd…
jackton1 Jun 23, 2023
264f5d1
Added missing changes and modified dist assets.
actions-user Jun 23, 2023
892ab7d
Updated error message
jackton1 Jun 23, 2023
8a7b17f
Merge 892ab7db122596e9c80ccbb06bb3e85cf0138755 into 50ae49b0e4dc2c5bd…
jackton1 Jun 23, 2023
8754808
Added missing changes and modified dist assets.
actions-user Jun 23, 2023
8553fa5
update the test
jackton1 Jun 23, 2023
43a0752
update the unsupported fields
jackton1 Jun 23, 2023
3071e92
Fixed error with API call
jackton1 Jun 23, 2023
0bf5b3c
Merge 3071e92d9c1511b5a8fff42ab236dd1411183933 into 50ae49b0e4dc2c5bd…
jackton1 Jun 23, 2023
dd52589
Added missing changes and modified dist assets.
actions-user Jun 23, 2023
717f9a8
Updated API call
jackton1 Jun 23, 2023
026f91b
Updated build assets
jackton1 Jun 23, 2023
6fc9333
Updated build assets
jackton1 Jun 23, 2023
34b412d
Updated build assets
jackton1 Jun 23, 2023
23621ad
Updated build assets
jackton1 Jun 23, 2023
bb454f8
Updated the request
jackton1 Jun 23, 2023
6b49ee4
Updated the request
jackton1 Jun 23, 2023
452e6cc
Updated assets
jackton1 Jun 23, 2023
a0b7e9e
Updated change type mapping
jackton1 Jun 23, 2023
efb5d1e
Merge a0b7e9ea8f55d51f95c2c7f8c1fea4584848891b into 50ae49b0e4dc2c5bd…
jackton1 Jun 23, 2023
e2ab48f
Added missing changes and modified dist assets.
actions-user Jun 23, 2023
27ebd62
Updated the test
jackton1 Jun 23, 2023
61692e1
Updated docs
jackton1 Jun 23, 2023
6b6cd3f
Updated docs
jackton1 Jun 23, 2023
4137c1b
Apply suggestions from code review
jackton1 Jun 23, 2023
30161c1
Merge 4137c1b5bce5b092826139711564b758774de3d7 into 50ae49b0e4dc2c5bd…
jackton1 Jun 23, 2023
9f2ca0e
Added missing changes and modified dist assets.
actions-user Jun 23, 2023
0feec72
Merge branch 'main' into feat/add-support-for-retrieving-changed-file…
repo-ranger[bot] Jun 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading