Skip to content

Commit 8c4da28

Browse files
authored
feat: add support for excluding symlinks and fix bug with commit not found (#2770)
1 parent 2f2f6cf commit 8c4da28

File tree

15 files changed

+802
-22
lines changed

15 files changed

+802
-22
lines changed

.github/workflows/test.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,113 @@ jobs:
275275
shell:
276276
bash
277277

278+
test-skip-same-base-and-commit-sha:
279+
name: Test changed-files skip same base and commit sha
280+
runs-on: ubuntu-latest
281+
needs: build
282+
if: needs.build.outputs.files_changed != 'true'
283+
permissions:
284+
contents: read
285+
286+
steps:
287+
- name: Checkout branch
288+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
289+
with:
290+
repository: ${{ github.event.pull_request.head.repo.full_name }}
291+
fetch-depth: 0
292+
293+
- name: Download build assets
294+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
295+
with:
296+
name: build-assets
297+
298+
- name: Get head SHA
299+
id: head-sha
300+
run: |
301+
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
302+
shell:
303+
bash
304+
305+
- name: Run changed-files with same base and commit sha
306+
id: changed-files
307+
uses: ./
308+
with:
309+
base_sha: ${{ steps.head-sha.outputs.sha }}
310+
sha: ${{ steps.head-sha.outputs.sha }}
311+
skip_same_sha: true
312+
313+
- name: Verify empty outputs
314+
if: steps.changed-files.outputs.all_changed_files_count != '0' || steps.changed-files.outputs.any_changed != 'false'
315+
run: |
316+
echo "Expected empty outputs; got count=${{ steps.changed-files.outputs.all_changed_files_count }} any_changed=${{ steps.changed-files.outputs.any_changed }}"
317+
exit 1
318+
shell:
319+
bash
320+
321+
- name: Show output
322+
run: |
323+
echo '${{ toJSON(steps.changed-files.outputs) }}'
324+
shell:
325+
bash
326+
327+
test-exclude-symlinks:
328+
name: Test changed-files exclude symlinks
329+
runs-on: ubuntu-latest
330+
needs: build
331+
if: needs.build.outputs.files_changed != 'true'
332+
permissions:
333+
contents: read
334+
335+
steps:
336+
- name: Checkout branch
337+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
338+
with:
339+
repository: ${{ github.event.pull_request.head.repo.full_name }}
340+
fetch-depth: 0
341+
342+
- name: Download build assets
343+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
344+
with:
345+
name: build-assets
346+
347+
- name: Run changed-files without symlink exclusion
348+
id: changed-files-symlink-included
349+
uses: ./
350+
with:
351+
base_sha: 955f38aa4f30f1ec92d08049b26e6d736ffea013
352+
sha: ddde96a55848a649c09322c7094b22ef4b4abe23
353+
354+
- name: Verify symlink is present
355+
if: "!contains(steps.changed-files-symlink-included.outputs.added_files, 'test/symlink-to-target')"
356+
run: |
357+
echo "Expected symlink to be present in added_files; got ${{ steps.changed-files-symlink-included.outputs.added_files }}"
358+
exit 1
359+
shell:
360+
bash
361+
362+
- name: Run changed-files excluding symlinks
363+
id: changed-files-symlink-excluded
364+
uses: ./
365+
with:
366+
base_sha: 955f38aa4f30f1ec92d08049b26e6d736ffea013
367+
sha: ddde96a55848a649c09322c7094b22ef4b4abe23
368+
exclude_symlinks: true
369+
370+
- name: Verify symlink is excluded
371+
if: "contains(steps.changed-files-symlink-excluded.outputs.added_files, 'test/symlink-to-target') || contains(steps.changed-files-symlink-excluded.outputs.all_changed_files, 'test/symlink-to-target')"
372+
run: |
373+
echo "Expected symlink to be excluded; got added=${{ steps.changed-files-symlink-excluded.outputs.added_files }} all=${{ steps.changed-files-symlink-excluded.outputs.all_changed_files }}"
374+
exit 1
375+
shell:
376+
bash
377+
378+
- name: Show output
379+
run: |
380+
echo '${{ toJSON(steps.changed-files-symlink-included.outputs) }}'
381+
echo '${{ toJSON(steps.changed-files-symlink-excluded.outputs) }}'
382+
shell:
383+
bash
384+
278385
test-using-branch-names-for-base-sha-and-sha-inputs:
279386
name: Test using branch names for base_sha and sha inputs
280387
runs-on: ubuntu-latest

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,16 @@ Support this project with a :star:
412412
# Default: "false"
413413
exclude_submodules: ''
414414

415+
# Exclude symlinks from changed files.
416+
# Type: boolean
417+
# Default: "false"
418+
exclude_symlinks: ''
419+
420+
# Do not fail when base and head SHAs are identical.
421+
# Type: boolean
422+
# Default: "false"
423+
skip_same_sha: ''
424+
415425
# Fail when the initial diff
416426
# fails.
417427
# Type: boolean

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ inputs:
227227
description: "Exclude changes to submodules."
228228
required: false
229229
default: "false"
230+
exclude_symlinks:
231+
description: "Exclude symlinks from changed files."
232+
required: false
233+
default: "false"
234+
skip_same_sha:
235+
description: "Do not fail when base and head SHAs are identical."
236+
required: false
237+
default: "false"
230238
fetch_missing_history_max_retries:
231239
description: "Maximum number of retries to fetch missing history."
232240
required: false

0 commit comments

Comments
 (0)