Skip to content

Commit dd216e9

Browse files
committed
Replace usage of external action for changed files
1 parent eea2551 commit dd216e9

5 files changed

Lines changed: 99 additions & 46 deletions

File tree

.github/workflows/check_required_files.yml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,29 @@ jobs:
8282
git config --local user.name "stdlib-bot"
8383
git fetch --all
8484
85-
# Get list of changed files:
86-
- name: 'Get list of changed files'
85+
# Get list of added files:
86+
- name: 'Get list of added files'
8787
if: steps.check-reviewers.outputs.is_stdlib_bot == 'true'
88-
id: changed-files
89-
uses: tj-actions/changed-files@v35
90-
with:
91-
separator: ' '
92-
base_sha: ${{ github.event.pull_request.base.sha }}
93-
sha: ${{ github.event.pull_request.head.sha }}
88+
id: added-files
89+
run: |
90+
page=1
91+
files=""
92+
while true; do
93+
new_files=$(curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ github.event.pull_request.number }}/files?page=$page&per_page=100" | jq -r '.[] | select(.status == "added") | .filename')
94+
if [ -z "$new_files" ]; then
95+
break
96+
fi
97+
files="$files $new_files"
98+
page=$((page+1))
99+
done
100+
files=$(echo "$files" | tr '\n' ' ' | sed 's/ $//')
101+
echo "files=${files}" >> $GITHUB_OUTPUT
94102
95103
# Check whether the pull request contains a new `README.md` file; if not, exit with a non-zero exit code:
96104
- name: 'Exit if pull request does not contain a new README.md file'
97105
if: steps.check-reviewers.outputs.is_stdlib_bot == 'true'
98106
run: |
99-
if [[ ! "${{ steps.changed-files.outputs.added_files }}" =~ "README.md" ]]; then
107+
if [[ ! "${{ steps.added-files.outputs.files }}" =~ "README.md" ]]; then
100108
echo "Pull request does not contain a new README.md file."
101109
exit 1
102110
fi
@@ -120,7 +128,7 @@ jobs:
120128
"test/test.js"
121129
)
122130
# Get path of first added `README.md` file:
123-
readme_path=$(echo "${{ steps.changed-files.outputs.added_files }}" | tr ' ' '\n' | grep -E 'README.md$' | head -n 1)
131+
readme_path=$(echo "${{ steps.added-files.outputs.files }}" | tr ' ' '\n' | grep -E 'README.md$' | head -n 1)
124132
125133
if grep -q '## CLI' "${readme_path}"; then
126134
required_files+=("bin/cli")
@@ -153,7 +161,7 @@ jobs:
153161
# Iterate over the list of required files:
154162
for file in "${required_files[@]}"; do
155163
# Check whether the file is present in the pull request:
156-
if [[ ! "${{ steps.changed-files.outputs.added_files }}" =~ "${file}" ]]; then
164+
if [[ ! "${{ steps.added-files.outputs.files }}" =~ "${file}" ]]; then
157165
# If not, add the file to the list of missing files:
158166
missing_files+=("${file}")
159167

.github/workflows/run_affected_benchmarks.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
process:
4343

4444
# Define a display name:
45-
name: 'Run changed benchmarks'
45+
name: 'Run affected benchmarks'
4646

4747
# Define the type of virtual host machine:
4848
runs-on: ubuntu-latest
@@ -85,16 +85,31 @@ jobs:
8585
# Get list of changed files:
8686
- name: 'Get list of changed files'
8787
id: changed-files
88-
uses: tj-actions/changed-files@v35
89-
with:
90-
separator: ' '
91-
files: |
92-
**/benchmark/**
88+
run: |
89+
if [ -n "${{ github.event.pull_request.number }}" ]; then
90+
# Get the list of changed files in pull request via the GitHub API:
91+
page=1
92+
files=""
93+
while true; do
94+
new_files=$(curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ github.event.pull_request.number }}/files?page=$page&per_page=100" | jq -r '.[] | .filename')
95+
if [ -z "$new_files" ]; then
96+
break
97+
fi
98+
files="$files $new_files"
99+
page=$((page+1))
100+
done
101+
else
102+
# Get changed files by comparing the current commit to the commit before the push event:
103+
files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
104+
fi
105+
# Keep only benchmark files:
106+
files=$(echo "$files" | grep -E 'benchmark/' | tr '\n' ' ' | sed 's/ $//')
107+
echo "files=${files}" >> $GITHUB_OUTPUT
93108
94109
# Run JavaScript benchmarks:
95110
- name: 'Run JavaScript benchmarks'
96111
run: |
97-
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep -E '\.js$' | tr '\n' ' ' | sed 's/ $//')
112+
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.js$' | tr '\n' ' ' | sed 's/ $//')
98113
if [ -n "$files" ]; then
99114
make benchmark-javascript-files FILES="${files}"
100115
fi

.github/workflows/run_affected_examples.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,31 @@ jobs:
8787
# Get list of changed files:
8888
- name: 'Get list of changed files'
8989
id: changed-files
90-
uses: tj-actions/changed-files@v35
91-
with:
92-
separator: ' '
93-
files: |
94-
**/examples/**
95-
**/README.md
90+
run: |
91+
if [ -n "${{ github.event.pull_request.number }}" ]; then
92+
# Get the list of changed files in pull request via the GitHub API:
93+
page=1
94+
files=""
95+
while true; do
96+
new_files=$(curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ github.event.pull_request.number }}/files?page=$page&per_page=100" | jq -r '.[] | .filename')
97+
if [ -z "$new_files" ]; then
98+
break
99+
fi
100+
files="$files $new_files"
101+
page=$((page+1))
102+
done
103+
else
104+
# Get changed files by comparing the current commit to the commit before the push event:
105+
files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
106+
fi
107+
# Keep only examples and `README.md` files:
108+
files=$(echo "$files" | grep -E 'examples/|README.md') | tr '\n' ' ' | sed 's/ $//')
109+
echo "files=${files}" >> $GITHUB_OUTPUT
96110
97111
# Run JavaScript examples:
98112
- name: 'Run JavaScript examples'
99113
run: |
100-
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep -E '\.js$' | tr '\n' ' ' | sed 's/ $//')
114+
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.js$' | tr '\n' ' ' | sed 's/ $//')
101115
if [ -n "$files" ]; then
102116
make examples-javascript-files FILES="${files}"
103117
fi
@@ -106,7 +120,7 @@ jobs:
106120
# Run examples in Markdown files:
107121
- name: 'Run examples in Markdown files'
108122
run: |
109-
files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep -E '\.md$' | tr '\n' ' ' | sed 's/ $//')
123+
files=$(echo "${{ steps.changed-files.outputs.files }}" | tr ' ' '\n' | grep -E '\.md$' | tr '\n' ' ' | sed 's/ $//')
110124
if [ -n "$files" ]; then
111125
make markdown-examples-javascript-files FILES="${files}"
112126
fi

.github/workflows/run_affected_tests.yml

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ on:
6767

6868
workflow_dispatch:
6969
inputs:
70-
files:
71-
description: 'List of changed files for which to run affected tests (space separated):'
70+
directories:
71+
description: 'List of changed directories for which to run affected tests (space separated):'
7272

7373
# Workflow jobs:
7474
jobs:
@@ -117,30 +117,45 @@ jobs:
117117
make init
118118
timeout-minutes: 5
119119

120-
# Get list of changed files from PR and push events:
121-
- name: 'Get list of changed files'
120+
# Get list of changed directories from PR and push events:
121+
- name: 'Get list of changed directories'
122122
if: github.event_name != 'workflow_dispatch'
123-
id: changed-files
124-
uses: tj-actions/changed-files@v35
125-
with:
126-
separator: ' '
127-
dir_names: 'true'
123+
id: changed-directories
124+
run: |
125+
if [ -n "${{ github.event.pull_request.number }}" ]; then
126+
# Get the list of changed files in pull request via the GitHub API:
127+
page=1
128+
files=""
129+
while true; do
130+
new_files=$(curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ github.event.pull_request.number }}/files?page=$page&per_page=100" | jq -r '.[] | .filename')
131+
if [ -z "$new_files" ]; then
132+
break
133+
fi
134+
files="$files $new_files"
135+
page=$((page+1))
136+
done
137+
else
138+
# Get changed files by comparing the current commit to the commit before the push event:
139+
files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
140+
fi
141+
directories=$(for file in $files; do dirname $file; done | uniq | tr '\n' ' ' | sed 's/ $//')
142+
echo "directories=${directories}" >> $GITHUB_OUTPUT
128143
129-
# Get list of changed files from workflow dispatch event:
130-
- name: 'Get list of changed files (from user input)'
144+
# Get list of changed directories from workflow dispatch event:
145+
- name: 'Get list of changed directories (from user input)'
131146
if: github.event_name == 'workflow_dispatch'
132-
id: changed-files-user-input
147+
id: changed-directories-user-input
133148
run: |
134-
echo "all_changed_files=${{ github.event.inputs.files }}" >> $GITHUB_OUTPUT
149+
echo "directories=${{ github.event.inputs.directories }}" >> $GITHUB_OUTPUT
135150
timeout-minutes: 5
136151

137152
# Run JavaScript tests:
138153
- name: 'Run JavaScript tests'
139154
run: |
140155
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
141-
all_changed_files="${{ steps.changed-files-user-input.outputs.all_changed_files }}"
156+
directories="${{ steps.changed-directories-user-input.outputs.directories }}"
142157
else
143-
all_changed_files="${{ steps.changed-files.outputs.all_changed_files }}"
158+
directories="${{ steps.changed-directories.outputs.directories }}"
144159
fi
145-
. "$GITHUB_WORKSPACE/.github/workflows/scripts/run_affected_tests" "$all_changed_files"
160+
. "$GITHUB_WORKSPACE/.github/workflows/scripts/run_affected_tests" "$directories"
146161
timeout-minutes: 15

.github/workflows/scaffold_pkg_via_branch_push.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ jobs:
6060
# Get list of changed files:
6161
- name: 'Get list of changed files'
6262
id: changed-files
63-
uses: tj-actions/changed-files@v35
64-
with:
65-
separator: ' '
63+
run: |
64+
files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
65+
files=$(echo "$files" | tr '\n' ' ' | sed 's/ $//')
66+
echo "files=${files}" >> $GITHUB_OUTPUT
6667
6768
# Run the command to scaffold a package:
6869
- name: 'Scaffold package'
@@ -71,7 +72,7 @@ jobs:
7172
with:
7273
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
7374
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74-
added-files: ${{ steps.changed-files.outputs.added_files }}
75+
added-files: ${{ steps.changed-files.outputs.files }}
7576

7677
# Configure git:
7778
- name: 'Configure git'

0 commit comments

Comments
 (0)