1
0
mirror of synced 2025-12-19 18:10:59 -05:00

Update main test workflow to use composite changed files action (#54889)

This commit is contained in:
Hector Alfaro
2025-03-18 18:00:48 -04:00
committed by GitHub
parent 0f4060ab43
commit 7168aad7c6
3 changed files with 39 additions and 45 deletions

View File

@@ -2,20 +2,29 @@ name: Get changed files
description: Get a list of changed files
inputs:
files:
description: 'Files or directories to check for changes'
file_filter:
description: 'Files or directories to check for changes, supports names, directories, trailing slashes, and single trailing wildcard'
required: false
default: '.'
head:
description: 'Head ref to check for changes against'
required: false
pr:
description: 'The PR to check for changes against'
required: false
token:
description: 'The token'
required: true
output_file:
description: 'Optional file path to write the changes to'
required: false
outputs:
all_changed_files:
description: 'List of all changed files (unfiltered)'
value: ${{ steps.get_changes.outputs.all_changed_files }}
filtered_changed_files:
description: 'List of changed files matching the filter'
description: 'List of changed files matching the `files` filter'
value: ${{ steps.get_changes.outputs.filtered_changed_files }}
runs:
@@ -25,7 +34,9 @@ runs:
id: get_changes
env:
INPUT_FILES: ${{ inputs.files }}
PR: ${{ github.event.pull_request.number }}
HEAD: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref || inputs.head || github.ref_name }}
INPUT_PR: ${{ inputs.pr || github.event.pull_request.number }}
INPUT_HEAD: ${{ inputs.head || github.event.pull_request.head.ref || github.event.merge_group.head_ref || github.ref_name }}
INPUT_OUTPUT_FILE: ${{ inputs.output_file }}
GH_TOKEN: ${{ inputs.token }}
shell: bash
run: ${{ github.action_path }}/get-changed-files.sh

View File

@@ -2,9 +2,10 @@
# Required environment variables:
# $INPUT_FILES: Pattern(s) to filter files by (e.g., "content/** data/**")
# $FILTER: Derived from INPUT_FILES, defaults to "." if not provided
# $PR: Pull request number (if running in PR context)
# $HEAD: Current branch or SHA for git diff
# $INPUT_PR: Pull request number (if running in PR context)
# $INPUT_HEAD: Current branch or SHA for git diff
# $INPUT_OUTPUT_FILE: Optional file to redirect output to.
# $GH_TOKEN: the access token
# Default value for files parameter if not provided
FILTER=${INPUT_FILES:-.}
@@ -16,21 +17,21 @@ echo "$FILTER"
# Find the file diff in the pull request or merge group
# If its a pull request, use the faster call to the GitHub API
# For push, workflow_dispatch, and merge_group, use git diff
if [ -n "$PR" ]
if [ -n "$INPUT_PR" ]
then
echo "__ running gh pr diff __"
DIFF=`gh pr diff $PR --name-only`
DIFF=$(gh pr diff $INPUT_PR --name-only)
if [ -z "$DIFF" ]; then
echo "__ gh pr diff failed, falling back to git diff __"
HEAD=$(gh pr view $PR --json headRefName --jq .headRefName)
HEAD=$(gh pr view $INPUT_PR --json headRefName --jq .headRefName)
fi
fi
if [ -z "$DIFF" ]; then
echo "__ using branch name $HEAD __"
echo "__ using branch name $INPUT_HEAD __"
git fetch origin main --depth 1
echo "__ running git diff __"
DIFF=`git diff --name-only origin/main $HEAD`
DIFF=$(git diff --name-only origin/main $INPUT_HEAD)
fi
# So we can inspect the output
@@ -64,9 +65,16 @@ echo "$FORMATTED_DIFF"
# Set the output for GitHub Actions
if [[ -n "$GITHUB_OUTPUT" ]]; then
echo "all_changed_files=$DIFF" >> "$GITHUB_OUTPUT"
ALL_FORMATTED=$(echo "$DIFF" | tr '\n' ' ' | tr -s ' ')
echo "all_changed_files=$ALL_FORMATTED" >> "$GITHUB_OUTPUT"
echo "filtered_changed_files=$FORMATTED_DIFF" >> "$GITHUB_OUTPUT"
else
echo "all_changed_files=$DIFF"
echo "filtered_changed_files=$FORMATTED_DIFF"
fi
# If output file is specified, write the filtered changes to it
if [[ -n "$INPUT_OUTPUT_FILE" ]]; then
echo "$FORMATTED_DIFF" > "$INPUT_OUTPUT_FILE"
echo "__ wrote changes to $INPUT_OUTPUT_FILE __"
fi

View File

@@ -131,37 +131,12 @@ jobs:
- name: Gather files changed
if: ${{ matrix.name == 'content-linter' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR: ${{ github.event.pull_request.number }}
HEAD: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }}
run: |
# Find the file diff in the pull request or merge group
# If its a pull request, use the faster call to the GitHub API
# For push, workflow_dispatch, and merge_group, use git diff
if [ -n "$PR" ]
then
echo __ running gh pr diff __
DIFF=`gh pr diff $PR --name-only`
elif [ -n "$HEAD" ]
then
echo __ running git fetch main __
git fetch origin main --depth 1
echo __ running git diff __
DIFF=`git diff --name-only origin/main`
else
echo __ no head, empty diff __
DIFF=''
fi
# So we can inspect the output
echo __ DIFF found __
echo $DIFF
# So that becomes a string like `foo.js path/bar.md`
# Must do this because the list of files can be HUGE. Especially
# in a repo-sync when there are lots of translation files involved.
echo __ format, write to get_diff_files.txt __
echo $DIFF | tr '\n' ' ' > get_diff_files.txt
uses: ./.github/actions/get-changed-files
with:
token: ${{ secrets.GITHUB_TOKEN }}
pr: ${{ github.event.pull_request.number }}
head: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }}
output_file: get_diff_files.txt
- uses: ./.github/actions/cache-nextjs