3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2025-02-20 21:01:53 +00:00

Implement path parameter (#168)

* Implement path parameter

* Add test

* Update README.md

* Corrections after code review

* Update action.yml

* Update test.yml

* Do not use realpath

* Update entrypoint.sh

* Update test.yml

Co-authored-by: Ivan Pizhenko <IvanPizhenko@users.noreply.github.com>
Co-authored-by: Tonye Jack <jtonye@ymail.com>
This commit is contained in:
Ivan Pizhenko 2021-08-28 04:53:03 +03:00 committed by GitHub
parent fcd69a6202
commit 8a41500fbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 13 deletions

View file

@ -32,6 +32,16 @@
"code", "code",
"doc" "doc"
] ]
},
{
"login": "IvanPizhenko",
"name": "Ivan Pizhenko",
"avatar_url": "https://avatars.githubusercontent.com/u/11859904?v=4",
"profile": "https://github.com/IvanPizhenko",
"contributions": [
"code",
"doc"
]
} }
], ],
"contributorsPerLine": 7, "contributorsPerLine": 7,

View file

@ -20,6 +20,59 @@ jobs:
- name: shellcheck - name: shellcheck
uses: reviewdog/action-shellcheck@v1.7 uses: reviewdog/action-shellcheck@v1.7
test-multiple-repositories:
name: Test with multiple repositories
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout into dir1
uses: actions/checkout@v2
with:
fetch-depth: 0
path: dir1
- name: Run changed-files with defaults on the dir1
id: changed-files-dir1
uses: ./dir1
with:
path: dir1
- name: Show output
run: |
echo "${{ toJSON(steps.changed-files-dir1.outputs) }}"
shell:
bash
- name: List all modified files
run: |
for file in "${{ steps.changed-files-dir1.outputs.modified_files }}"; do
echo $file
done
shell:
bash
- name: Checkout into dir2
uses: actions/checkout@v2
with:
fetch-depth: 0
path: dir2
- name: Run changed-files with defaults on the dir2
id: changed-files-dir2
uses: ./dir2
with:
path: dir2
- name: Show output
run: |
echo "${{ toJSON(steps.changed-files-dir2.outputs) }}"
shell:
bash
- name: List all modified files
run: |
for file in "${{ steps.changed-files-dir2.outputs.modified_files }}"; do
echo $file
done
shell:
bash
test-no-head-sha: test-no-head-sha:
name: Test changed-files missing head sha name: Test changed-files missing head sha
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.platform }}
@ -31,12 +84,12 @@ jobs:
steps: steps:
- name: Checkout to branch - name: Checkout to branch
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Run changed-files with defaults - name: Run changed-files with defaults
id: changed-files id: changed-files
continue-on-error: true continue-on-error: true
uses: ./ uses: ./
- name: Show output - name: Show output
run: | run: |
echo "${{ toJSON(steps.changed-files.outputs) }}" echo "${{ toJSON(steps.changed-files.outputs) }}"

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
.idea/ .idea/
.envrc .envrc
tag.sh
untag.sh

View file

@ -53,11 +53,11 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with: with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit. fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.
- name: Get changed files - name: Get changed files
id: changed-files id: changed-files
uses: tj-actions/changed-files@v1.0.0 uses: tj-actions/changed-files@v1.0.0
- name: List all modified files - name: List all modified files
run: | run: |
for file in "${{ steps.changed-files.outputs.all_modified_files }}"; do for file in "${{ steps.changed-files.outputs.all_modified_files }}"; do
@ -104,6 +104,7 @@ jobs:
| base_sha | `string` | `false` | | Specify a different <br> base commit SHA <br> used for <br> comparing changes | | base_sha | `string` | `false` | | Specify a different <br> base commit SHA <br> used for <br> comparing changes |
| sha | `string` | `true` | `${{ github.sha }}` | Specify a different <br> commit SHA <br> used for <br> comparing changes | | sha | `string` | `true` | `${{ github.sha }}` | Specify a different <br> commit SHA <br> used for <br> comparing changes |
| files_from_source_file | `string` | `false` | | Source file <br> used to populate <br> the files input | | files_from_source_file | `string` | `false` | | Source file <br> used to populate <br> the files input |
| path | `string` | `false` | | Relative path under <br> `GITHUB_WORKSPACE` <br> to the repository |
## Example ## Example
@ -115,7 +116,7 @@ jobs:
- name: Get changed files using defaults - name: Get changed files using defaults
id: changed-files id: changed-files
uses: tj-actions/changed-files@v1.0.0 uses: tj-actions/changed-files@v1.0.0
- name: Get changed files using a comma separator - name: Get changed files using a comma separator
id: changed-files-comma id: changed-files-comma
uses: tj-actions/changed-files@v1.0.0 uses: tj-actions/changed-files@v1.0.0
@ -148,7 +149,7 @@ jobs:
new.txt new.txt
test_directory test_directory
*.sh *.sh
.(png|jpeg)$ .(png|jpeg)$
.(sql)$ .(sql)$
^(mynewfile|custom) ^(mynewfile|custom)
@ -156,12 +157,12 @@ jobs:
if: steps.changed-files-specific.outputs.any_changed == 'true' if: steps.changed-files-specific.outputs.any_changed == 'true'
run: | run: |
echo "One or more files listed above has changed." echo "One or more files listed above has changed."
- name: Run step if only the files listed above change - name: Run step if only the files listed above change
if: steps.changed-files-specific.outputs.only_changed == 'true' if: steps.changed-files-specific.outputs.only_changed == 'true'
run: | run: |
echo "Only files listed above have changed." echo "Only files listed above have changed."
- name: Use a source file or list of file(s) to populate to files input. - name: Use a source file or list of file(s) to populate to files input.
id: changed-files-specific-source-file id: changed-files-specific-source-file
uses: tj-actions/changed-files@v1.0.0 uses: tj-actions/changed-files@v1.0.0
@ -183,13 +184,13 @@ jobs:
uses: tj-actions/changed-files@v1.0.0 uses: tj-actions/changed-files@v1.0.0
with: with:
sha: ${{ github.event.pull_request.head.sha }} sha: ${{ github.event.pull_request.head.sha }}
- name: Use a different base SHA - name: Use a different base SHA
id: changed-files-custom-base-sha id: changed-files-custom-base-sha
uses: tj-actions/changed-files@v1.0.0 uses: tj-actions/changed-files@v1.0.0
with: with:
base_sha: "2096ed0" base_sha: "2096ed0"
``` ```
### Running [pre-commit](https://pre-commit.com/) on all modified files ### Running [pre-commit](https://pre-commit.com/) on all modified files
@ -200,7 +201,7 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Get changed files - name: Get changed files
id: changed-files id: changed-files
uses: tj-actions/changed-files@v1.0.0 uses: tj-actions/changed-files@v1.0.0

View file

@ -25,6 +25,9 @@ inputs:
base_sha: base_sha:
description: 'Specify a base commit SHA on used for comparing changes' description: 'Specify a base commit SHA on used for comparing changes'
required: false required: false
path:
description: 'Specify a relative path under $GITHUB_WORKSPACE to locate the repository'
required: false
outputs: outputs:
added_files: added_files:
@ -100,6 +103,7 @@ runs:
INPUT_TOKEN: ${{ inputs.token }} INPUT_TOKEN: ${{ inputs.token }}
INPUT_FILES: ${{ join(format('{0} {1}', inputs.files, steps.source-input-files.outputs.files), ' ') }} INPUT_FILES: ${{ join(format('{0} {1}', inputs.files, steps.source-input-files.outputs.files), ' ') }}
INPUT_SEPARATOR: ${{ inputs.separator }} INPUT_SEPARATOR: ${{ inputs.separator }}
INPUT_PATH: ${{ inputs.path }}
branding: branding:
icon: file-text icon: file-text

View file

@ -4,6 +4,17 @@ set -e
echo "::group::changed-files" echo "::group::changed-files"
echo "Resolving repository path..."
if [[ -n $INPUT_PATH ]]; then
REPO_DIR="$GITHUB_WORKSPACE/$INPUT_PATH"
if [[ ! -d "$REPO_DIR" ]]; then
echo "::warning::Invalid repository path"
exit 1
fi
cd "$REPO_DIR"
fi
git remote add temp_changed_files "https://${INPUT_TOKEN}@github.com/${GITHUB_REPOSITORY}" git remote add temp_changed_files "https://${INPUT_TOKEN}@github.com/${GITHUB_REPOSITORY}"
echo "Getting HEAD info..." echo "Getting HEAD info..."
@ -27,7 +38,7 @@ if [[ -z $GITHUB_BASE_REF ]]; then
fi fi
TARGET_BRANCH=${GITHUB_REF/refs\/heads\//} TARGET_BRANCH=${GITHUB_REF/refs\/heads\//}
CURRENT_BRANCH=$TARGET_BRANCH CURRENT_BRANCH=$TARGET_BRANCH
if [[ $exit_status -ne 0 ]]; then if [[ $exit_status -ne 0 ]]; then
echo "::warning::Unable to determine the previous commit sha" echo "::warning::Unable to determine the previous commit sha"
echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage" echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage"
@ -42,7 +53,7 @@ else
else else
PREVIOUS_SHA=$INPUT_BASE_SHA PREVIOUS_SHA=$INPUT_BASE_SHA
fi fi
if [[ $exit_status -ne 0 ]]; then if [[ $exit_status -ne 0 ]]; then
echo "::warning::Unable to determine the base ref sha for ${TARGET_BRANCH}" echo "::warning::Unable to determine the base ref sha for ${TARGET_BRANCH}"
exit 1 exit 1