Skip to content

Commit 21732e0

Browse files
authored
Merge pull request #36981 from github/repo-sync
Repo sync
2 parents 2bdcf81 + 3549368 commit 21732e0

11 files changed

Lines changed: 46 additions & 86 deletions

.github/actions/get-changed-files/action.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,29 @@ name: Get changed files
22
description: Get a list of changed files
33

44
inputs:
5-
files:
6-
description: 'Files or directories to check for changes'
5+
file_filter:
6+
description: 'Files or directories to check for changes, supports names, directories, trailing slashes, and single trailing wildcard'
77
required: false
88
default: '.'
99
head:
1010
description: 'Head ref to check for changes against'
1111
required: false
12+
pr:
13+
description: 'The PR to check for changes against'
14+
required: false
15+
token:
16+
description: 'The token'
17+
required: true
18+
output_file:
19+
description: 'Optional file path to write the changes to'
20+
required: false
1221

1322
outputs:
1423
all_changed_files:
1524
description: 'List of all changed files (unfiltered)'
1625
value: ${{ steps.get_changes.outputs.all_changed_files }}
1726
filtered_changed_files:
18-
description: 'List of changed files matching the filter'
27+
description: 'List of changed files matching the `files` filter'
1928
value: ${{ steps.get_changes.outputs.filtered_changed_files }}
2029

2130
runs:
@@ -25,7 +34,9 @@ runs:
2534
id: get_changes
2635
env:
2736
INPUT_FILES: ${{ inputs.files }}
28-
PR: ${{ github.event.pull_request.number }}
29-
HEAD: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref || inputs.head || github.ref_name }}
37+
INPUT_PR: ${{ inputs.pr || github.event.pull_request.number }}
38+
INPUT_HEAD: ${{ inputs.head || github.event.pull_request.head.ref || github.event.merge_group.head_ref || github.ref_name }}
39+
INPUT_OUTPUT_FILE: ${{ inputs.output_file }}
40+
GH_TOKEN: ${{ inputs.token }}
3041
shell: bash
3142
run: ${{ github.action_path }}/get-changed-files.sh

.github/actions/get-changed-files/get-changed-files.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
# Required environment variables:
44
# $INPUT_FILES: Pattern(s) to filter files by (e.g., "content/** data/**")
5-
# $FILTER: Derived from INPUT_FILES, defaults to "." if not provided
6-
# $PR: Pull request number (if running in PR context)
7-
# $HEAD: Current branch or SHA for git diff
5+
# $INPUT_PR: Pull request number (if running in PR context)
6+
# $INPUT_HEAD: Current branch or SHA for git diff
7+
# $INPUT_OUTPUT_FILE: Optional file to redirect output to.
8+
# $GH_TOKEN: the access token
89

910
# Default value for files parameter if not provided
1011
FILTER=${INPUT_FILES:-.}
@@ -16,21 +17,21 @@ echo "$FILTER"
1617
# Find the file diff in the pull request or merge group
1718
# If its a pull request, use the faster call to the GitHub API
1819
# For push, workflow_dispatch, and merge_group, use git diff
19-
if [ -n "$PR" ]
20+
if [ -n "$INPUT_PR" ]
2021
then
2122
echo "__ running gh pr diff __"
22-
DIFF=`gh pr diff $PR --name-only`
23+
DIFF=$(gh pr diff $INPUT_PR --name-only)
2324
if [ -z "$DIFF" ]; then
2425
echo "__ gh pr diff failed, falling back to git diff __"
25-
HEAD=$(gh pr view $PR --json headRefName --jq .headRefName)
26+
HEAD=$(gh pr view $INPUT_PR --json headRefName --jq .headRefName)
2627
fi
2728
fi
2829

2930
if [ -z "$DIFF" ]; then
30-
echo "__ using branch name $HEAD __"
31+
echo "__ using branch name $INPUT_HEAD __"
3132
git fetch origin main --depth 1
3233
echo "__ running git diff __"
33-
DIFF=`git diff --name-only origin/main $HEAD`
34+
DIFF=$(git diff --name-only origin/main $INPUT_HEAD)
3435
fi
3536

3637
# So we can inspect the output
@@ -64,9 +65,16 @@ echo "$FORMATTED_DIFF"
6465

6566
# Set the output for GitHub Actions
6667
if [[ -n "$GITHUB_OUTPUT" ]]; then
67-
echo "all_changed_files=$DIFF" >> "$GITHUB_OUTPUT"
68+
ALL_FORMATTED=$(echo "$DIFF" | tr '\n' ' ' | tr -s ' ')
69+
echo "all_changed_files=$ALL_FORMATTED" >> "$GITHUB_OUTPUT"
6870
echo "filtered_changed_files=$FORMATTED_DIFF" >> "$GITHUB_OUTPUT"
6971
else
7072
echo "all_changed_files=$DIFF"
7173
echo "filtered_changed_files=$FORMATTED_DIFF"
7274
fi
75+
76+
# If output file is specified, write the filtered changes to it
77+
if [[ -n "$INPUT_OUTPUT_FILE" ]]; then
78+
echo "$FORMATTED_DIFF" > "$INPUT_OUTPUT_FILE"
79+
echo "__ wrote changes to $INPUT_OUTPUT_FILE __"
80+
fi

.github/workflows/content-lint-markdown.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,37 @@ jobs:
2525
- name: Check out repo
2626
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2727
with:
28-
# Picking this number is a "best guess". If we make it too large,
29-
# the checkout will take potentially unnecessariily long.
30-
# This reduces the chance that tj-actions/changed-files has to
31-
# fetch deeper history. But if it needs to, it will.
3228
fetch-depth: 10
3329

3430
- name: Set up Node and dependencies
3531
uses: ./.github/actions/node-npm-setup
3632

3733
- name: Get changed content/data files
38-
id: changed-files
34+
id: changed_files
3935
uses: ./.github/actions/get-changed-files
4036
with:
4137
files: |
4238
content/**
4339
data/**
40+
token: ${{ secrets.GITHUB_TOKEN }}
4441

4542
- name: Print content linter annotations if changed content/data files
46-
if: steps.changed-files.outputs.filtered_changed_files
43+
if: steps.changed_files.outputs.filtered_changed_files
4744
env:
4845
# Make it an environment variable so that its value doesn't need to be escaped.
4946
# See https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
5047
CHANGED_FILES: |-
51-
${{ steps.changed-files.outputs.filtered_changed_files }}
48+
${{ steps.changed_files.outputs.filtered_changed_files }}
5249
# If there are errors, using `--print-annotations` will make it
5350
# so it does *not* exit non-zero.
5451
# This is so that all warnings and errors are printed.
5552
run: npm run lint-content -- --print-annotations --paths $CHANGED_FILES
5653

5754
- name: Run content linter if changed content/data files
58-
if: steps.changed-files.outputs.any_changed == 'true'
55+
if: steps.changed_files.outputs.any_changed == 'true'
5956
env:
6057
# Make it an environment variable so that its value doesn't need to be escaped.
6158
# See https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
6259
CHANGED_FILES: |-
63-
${{ steps.changed-files.outputs.filtered_changed_files }}
60+
${{ steps.changed_files.outputs.filtered_changed_files }}
6461
run: npm run lint-content -- --errors-only --paths $CHANGED_FILES

.github/workflows/test.yml

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -131,37 +131,12 @@ jobs:
131131

132132
- name: Gather files changed
133133
if: ${{ matrix.name == 'content-linter' }}
134-
env:
135-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
136-
PR: ${{ github.event.pull_request.number }}
137-
HEAD: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }}
138-
run: |
139-
# Find the file diff in the pull request or merge group
140-
# If its a pull request, use the faster call to the GitHub API
141-
# For push, workflow_dispatch, and merge_group, use git diff
142-
if [ -n "$PR" ]
143-
then
144-
echo __ running gh pr diff __
145-
DIFF=`gh pr diff $PR --name-only`
146-
elif [ -n "$HEAD" ]
147-
then
148-
echo __ running git fetch main __
149-
git fetch origin main --depth 1
150-
echo __ running git diff __
151-
DIFF=`git diff --name-only origin/main`
152-
else
153-
echo __ no head, empty diff __
154-
DIFF=''
155-
fi
156-
# So we can inspect the output
157-
echo __ DIFF found __
158-
echo $DIFF
159-
160-
# So that becomes a string like `foo.js path/bar.md`
161-
# Must do this because the list of files can be HUGE. Especially
162-
# in a repo-sync when there are lots of translation files involved.
163-
echo __ format, write to get_diff_files.txt __
164-
echo $DIFF | tr '\n' ' ' > get_diff_files.txt
134+
uses: ./.github/actions/get-changed-files
135+
with:
136+
token: ${{ secrets.GITHUB_TOKEN }}
137+
pr: ${{ github.event.pull_request.number }}
138+
head: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }}
139+
output_file: get_diff_files.txt
165140

166141
- uses: ./.github/actions/cache-nextjs
167142

data/features/actions-default-workflow-permissions-restrictive.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

data/features/allow-actions-to-approve-pr-with-ent-repo.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

data/features/answered-fields-for-discussions.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

data/features/archive-organizations.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

data/features/classic-project-visibility-permissions.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

data/reusables/apps/enterprise-apps-beta.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)