Update main test workflow to use composite changed files action (#54889)
This commit is contained in:
21
.github/actions/get-changed-files/action.yml
vendored
21
.github/actions/get-changed-files/action.yml
vendored
@@ -2,20 +2,29 @@ name: Get changed files
|
|||||||
description: Get a list of changed files
|
description: Get a list of changed files
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
files:
|
file_filter:
|
||||||
description: 'Files or directories to check for changes'
|
description: 'Files or directories to check for changes, supports names, directories, trailing slashes, and single trailing wildcard'
|
||||||
required: false
|
required: false
|
||||||
default: '.'
|
default: '.'
|
||||||
head:
|
head:
|
||||||
description: 'Head ref to check for changes against'
|
description: 'Head ref to check for changes against'
|
||||||
required: false
|
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:
|
outputs:
|
||||||
all_changed_files:
|
all_changed_files:
|
||||||
description: 'List of all changed files (unfiltered)'
|
description: 'List of all changed files (unfiltered)'
|
||||||
value: ${{ steps.get_changes.outputs.all_changed_files }}
|
value: ${{ steps.get_changes.outputs.all_changed_files }}
|
||||||
filtered_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 }}
|
value: ${{ steps.get_changes.outputs.filtered_changed_files }}
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
@@ -25,7 +34,9 @@ runs:
|
|||||||
id: get_changes
|
id: get_changes
|
||||||
env:
|
env:
|
||||||
INPUT_FILES: ${{ inputs.files }}
|
INPUT_FILES: ${{ inputs.files }}
|
||||||
PR: ${{ github.event.pull_request.number }}
|
INPUT_PR: ${{ inputs.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_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
|
shell: bash
|
||||||
run: ${{ github.action_path }}/get-changed-files.sh
|
run: ${{ github.action_path }}/get-changed-files.sh
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
# Required environment variables:
|
# Required environment variables:
|
||||||
# $INPUT_FILES: Pattern(s) to filter files by (e.g., "content/** data/**")
|
# $INPUT_FILES: Pattern(s) to filter files by (e.g., "content/** data/**")
|
||||||
# $FILTER: Derived from INPUT_FILES, defaults to "." if not provided
|
# $INPUT_PR: Pull request number (if running in PR context)
|
||||||
# $PR: Pull request number (if running in PR context)
|
# $INPUT_HEAD: Current branch or SHA for git diff
|
||||||
# $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
|
# Default value for files parameter if not provided
|
||||||
FILTER=${INPUT_FILES:-.}
|
FILTER=${INPUT_FILES:-.}
|
||||||
@@ -16,21 +17,21 @@ echo "$FILTER"
|
|||||||
# Find the file diff in the pull request or merge group
|
# Find the file diff in the pull request or merge group
|
||||||
# If its a pull request, use the faster call to the GitHub API
|
# If its a pull request, use the faster call to the GitHub API
|
||||||
# For push, workflow_dispatch, and merge_group, use git diff
|
# For push, workflow_dispatch, and merge_group, use git diff
|
||||||
if [ -n "$PR" ]
|
if [ -n "$INPUT_PR" ]
|
||||||
then
|
then
|
||||||
echo "__ running gh pr diff __"
|
echo "__ running gh pr diff __"
|
||||||
DIFF=`gh pr diff $PR --name-only`
|
DIFF=$(gh pr diff $INPUT_PR --name-only)
|
||||||
if [ -z "$DIFF" ]; then
|
if [ -z "$DIFF" ]; then
|
||||||
echo "__ gh pr diff failed, falling back to git diff __"
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$DIFF" ]; then
|
if [ -z "$DIFF" ]; then
|
||||||
echo "__ using branch name $HEAD __"
|
echo "__ using branch name $INPUT_HEAD __"
|
||||||
git fetch origin main --depth 1
|
git fetch origin main --depth 1
|
||||||
echo "__ running git diff __"
|
echo "__ running git diff __"
|
||||||
DIFF=`git diff --name-only origin/main $HEAD`
|
DIFF=$(git diff --name-only origin/main $INPUT_HEAD)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# So we can inspect the output
|
# So we can inspect the output
|
||||||
@@ -64,9 +65,16 @@ echo "$FORMATTED_DIFF"
|
|||||||
|
|
||||||
# Set the output for GitHub Actions
|
# Set the output for GitHub Actions
|
||||||
if [[ -n "$GITHUB_OUTPUT" ]]; then
|
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"
|
echo "filtered_changed_files=$FORMATTED_DIFF" >> "$GITHUB_OUTPUT"
|
||||||
else
|
else
|
||||||
echo "all_changed_files=$DIFF"
|
echo "all_changed_files=$DIFF"
|
||||||
echo "filtered_changed_files=$FORMATTED_DIFF"
|
echo "filtered_changed_files=$FORMATTED_DIFF"
|
||||||
fi
|
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
|
||||||
|
|||||||
37
.github/workflows/test.yml
vendored
37
.github/workflows/test.yml
vendored
@@ -131,37 +131,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Gather files changed
|
- name: Gather files changed
|
||||||
if: ${{ matrix.name == 'content-linter' }}
|
if: ${{ matrix.name == 'content-linter' }}
|
||||||
env:
|
uses: ./.github/actions/get-changed-files
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
with:
|
||||||
PR: ${{ github.event.pull_request.number }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
HEAD: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }}
|
pr: ${{ github.event.pull_request.number }}
|
||||||
run: |
|
head: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }}
|
||||||
# Find the file diff in the pull request or merge group
|
output_file: get_diff_files.txt
|
||||||
# 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/cache-nextjs
|
- uses: ./.github/actions/cache-nextjs
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user