Skip to content

Commit 2601464

Browse files
authored
Massive DIFF_FILES crashes bash in repo-sync (#23326)
* Massive DIFF_FILES crashes bash in repo-sync Part of #1304 * gst * make exception
1 parent 4ff5167 commit 2601464

File tree

4 files changed

+44
-18
lines changed

4 files changed

+44
-18
lines changed

Diff for: .github/workflows/test.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ jobs:
5656

5757
- name: Insight into changed files
5858
run: |
59-
echo ${{ steps.get_diff_files.outputs.files }}
59+
60+
# Must to do this because the list of files can be HUGE. Especially
61+
# in a repo-sync when there are lots of translation files involved.
62+
echo "${{ steps.get_diff_files.outputs.files }}" > get_diff_files.txt
6063
6164
- name: Setup node
6265
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
@@ -80,5 +83,5 @@ jobs:
8083

8184
- name: Run tests
8285
env:
83-
DIFF_FILES: ${{ steps.get_diff_files.outputs.files }}
86+
DIFF_FILE: get_diff_files.txt
8487
run: npm run test tests/${{ matrix.test-group }}/

Diff for: tests/linting/lint-files.js

+9-15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import { supported, next, nextNext, deprecated } from '../../lib/enterprise-serv
2323
import { getLiquidConditionals } from '../../script/helpers/get-liquid-conditionals.js'
2424
import allowedVersionOperators from '../../lib/liquid-tags/ifversion-supported-operators.js'
2525
import semver from 'semver'
26+
import { jest } from '@jest/globals'
27+
import { getDiffFiles } from '../utils.js'
28+
29+
jest.useFakeTimers('legacy')
2630

2731
const __dirname = path.dirname(fileURLToPath(import.meta.url))
2832
const enterpriseServerVersions = Object.keys(allVersions).filter((v) =>
@@ -357,28 +361,18 @@ function getContent(content) {
357361
return null
358362
}
359363

360-
// Filter out entries from an array like this:
361-
//
362-
// [
363-
// [relativePath, absolutePath],
364-
// ...
365-
// so it's only the files mentioned in the DIFF_FILES environment
366-
// variable, but only if it's set and present.
367-
368-
// Setting an environment varible called `DIFF_FILES` is optional.
369-
// But if and only if it's set, we will respect it.
370-
// And if it set, turn it into a cleaned up Set so it's made available
371-
// every time we use it.
372-
if (process.env.DIFF_FILES) {
373-
// Parse and turn that environment variable string into a set.
364+
const diffFiles = getDiffFiles()
365+
366+
// If present, and not empty, leverage it because in most cases it's empty.
367+
if (diffFiles.length > 0) {
374368
// It's faster to do this once and then re-use over and over in the
375369
// .filter() later on.
376370
const only = new Set(
377371
// If the environment variable encodes all the names
378372
// with quotation marks, strip them.
379373
// E.g. Turn `"foo" "bar"` into ['foo', 'bar']
380374
// Note, this assumes no possible file contains a space.
381-
process.env.DIFF_FILES.split(/\s+/g).map((name) => {
375+
diffFiles.map((name) => {
382376
if (/^['"]/.test(name) && /['"]$/.test(name)) {
383377
return name.slice(1, -1)
384378
}

Diff for: tests/meta/orphan-tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { filter as asyncFilter } from 'async'
55
describe('check for orphan tests', () => {
66
test('all tests are in sub-directories', async () => {
77
// A known list of exceptions that can live outside of directories
8-
const EXCEPTIONS = ['README.md', 'package.json']
8+
const EXCEPTIONS = ['README.md', 'package.json', 'utils.js']
99
const pathToTests = path.join(process.cwd(), 'tests')
1010

1111
// Get a list of files/directories in `/tests`

Diff for: tests/utils.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import fs from 'fs'
2+
3+
// The reason we're not manually doing a spawned subprocess
4+
// of `git diff --name-only ...` or something here is because that stuff
5+
// is unpredictable in GitHub Actions because of how it does `git clone`.
6+
// So we rely on environment variables instead.
7+
8+
export function getDiffFiles() {
9+
// Instead of testing every single file possible, if there's
10+
// an environment variable called `DIFF_FILES` or one called
11+
// `DIFF_FILE` then use that.
12+
// If `DIFF_FILES` is set, it's expected to be a space separated
13+
// string. If `DIFF_FILE` is set, it's expected to be a text file
14+
// which contains a space separated string.
15+
const diffFiles = []
16+
// Setting an environment varible called `DIFF_FILES` is optional.
17+
// But if and only if it's set, we will respect it.
18+
// And if it set, turn it into a cleaned up Set so it's made available
19+
// every time we use it.
20+
// Alternatively, you can put all the files change changed into a
21+
// text file and do `export DIFF_FILE=files-that-changed.txt`
22+
if (process.env.DIFF_FILES) {
23+
diffFiles.push(...process.env.DIFF_FILES.trim().split(/\s+/g))
24+
} else if (process.env.DIFF_FILE) {
25+
diffFiles.push(...fs.readFileSync(process.env.DIFF_FILE, 'utf-8').trim().split(/\s+/g))
26+
}
27+
28+
return diffFiles
29+
}

0 commit comments

Comments
 (0)