From 480159e7787761f2bd0bec69fbe62f6cac6f66d3 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Wed, 17 Nov 2021 22:03:47 -0500 Subject: [PATCH 1/2] only lint the files that changed (#22924) * only lint the files that changed * allowed action * do nothing * debug more * less debugging * debug * debug * debug * using patterns * testing something * testing something (2) * lemme try something * lemme try something * one more attempt * testing * tidying up * sample changes * add debugging * some code comments * fine but sample changes * update allowed actions * final cleaning before opening PR for review * tiny update * remove commented out code * feedbacked --- .github/allowed-actions.js | 1 + .github/workflows/test.yml | 14 +++++++++ tests/linting/lint-files.js | 57 +++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/.github/allowed-actions.js b/.github/allowed-actions.js index 3f372b3b83..e8e4cf3f9a 100644 --- a/.github/allowed-actions.js +++ b/.github/allowed-actions.js @@ -18,6 +18,7 @@ export default [ 'dawidd6/action-download-artifact@af92a8455a59214b7b932932f2662fdefbd78126', // v2.15.0 'docker://chinthakagodawita/autoupdate-action:v1', 'dorny/paths-filter@eb75a1edc117d3756a18ef89958ee59f9500ba58', + 'trilom/file-changes-action@a6ca26c14274c33b15e6499323aac178af06ad4b', // v1.2.4 'github/codeql-action/analyze@v1', 'github/codeql-action/init@v1', 'juliangruber/approve-pull-request-action@c530832d4d346c597332e20e03605aa94fa150a8', diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 67d93a3950..0dad27824f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,6 +46,18 @@ jobs: # Enables cloning the Early Access repo later with the relevant PAT persist-credentials: 'false' + - name: Gather files changed + uses: trilom/file-changes-action@a6ca26c14274c33b15e6499323aac178af06ad4b + id: get_diff_files + with: + # So that `steps.get_diff_files.outputs.files` becomes + # a string like `foo.js path/bar.md` + output: ' ' + + - name: Insight into changed files + run: | + echo ${{ steps.get_diff_files.outputs.files }} + - name: Setup node uses: actions/setup-node@270253e841af726300e85d718a5f606959b2903c with: @@ -67,4 +79,6 @@ jobs: run: npm run build - name: Run tests + env: + DIFF_FILES: ${{ steps.get_diff_files.outputs.files }} run: npm run test tests/${{ matrix.test-group }}/ diff --git a/tests/linting/lint-files.js b/tests/linting/lint-files.js index 6dc1bcab6f..4a3de39075 100644 --- a/tests/linting/lint-files.js +++ b/tests/linting/lint-files.js @@ -356,6 +356,63 @@ function getContent(content) { return null } +// Filter out entries from an array like this: +// +// [ +// [relativePath, absolutePath], +// ... +// so it's only the files mentioned in the DIFF_FILES environment +// variable, but only if it's set and present. + +// Setting an environment varible called `DIFF_FILES` is optional. +// But if and only if it's set, we will respect it. +// And if it set, turn it into a cleaned up Set so it's made available +// every time we use it. +if (process.env.DIFF_FILES) { + // Parse and turn that environment variable string into a set. + // It's faster to do this once and then re-use over and over in the + // .filter() later on. + const only = new Set( + // If the environment variable encodes all the names + // with quotation marks, strip them. + // E.g. Turn `"foo" "bar"` into ['foo', 'bar'] + // Note, this assumes no possible file contains a space. + process.env.DIFF_FILES.split(/\s+/g).map((name) => { + if (/^['"]/.test(name) && /['"]$/.test(name)) { + return name.slice(1, -1) + } + return name + }) + ) + const filterFiles = (tuples) => + tuples.filter( + ([relativePath, absolutePath]) => only.has(relativePath) || only.has(absolutePath) + ) + mdToLint = filterFiles(mdToLint) + ymlToLint = filterFiles(ymlToLint) + ghesReleaseNotesToLint = filterFiles(ghesReleaseNotesToLint) + ghaeReleaseNotesToLint = filterFiles(ghaeReleaseNotesToLint) + learningTracksToLint = filterFiles(learningTracksToLint) + featureVersionsToLint = filterFiles(featureVersionsToLint) +} + +if ( + mdToLint.length + + ymlToLint.length + + ghesReleaseNotesToLint.length + + ghaeReleaseNotesToLint.length + + learningTracksToLint.length + + featureVersionsToLint.length < + 1 +) { + // With this in place, at least one `test()` is called and you don't + // get the `Your test suite must contain at least one test.` error + // from `jest`. + describe('deliberately do nothing', () => { + test('void', () => {}) + }) +} + describe('lint markdown content', () => { if (mdToLint.length < 1) return describe.each(mdToLint)('%s', (markdownRelPath, markdownAbsPath) => { From 2768f16b50cc0ce00962f6c74af5ea772664d8c5 Mon Sep 17 00:00:00 2001 From: Rachael Sewell Date: Wed, 17 Nov 2021 19:10:43 -0800 Subject: [PATCH 2/2] only observe failure status when not caused by freeze (#22943) --- .github/workflows/check-broken-links-github-github.yml | 4 ++-- .github/workflows/enterprise-dates.yml | 4 ++-- .github/workflows/remove-unused-assets.yml | 2 +- .github/workflows/update-graphql-files.yml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check-broken-links-github-github.yml b/.github/workflows/check-broken-links-github-github.yml index 2d27a0fd0a..5b720e62c8 100644 --- a/.github/workflows/check-broken-links-github-github.yml +++ b/.github/workflows/check-broken-links-github-github.yml @@ -59,11 +59,11 @@ jobs: # # https://docs.github.com/actions/reference/context-and-expression-syntax-for-github-actions#job-status-check-functions - - if: ${{ failure() }} + - if: ${{ failure() && env.FREEZE != 'true' }} name: Get title for issue id: check run: echo "::set-output name=title::$(head -1 broken_github_github_links.md)" - - if: ${{ failure() }} + - if: ${{ failure() && env.FREEZE != 'true'}} name: Create issue from file id: github-github-broken-link-report uses: peter-evans/create-issue-from-file@b4f9ee0a9d4abbfc6986601d9b1a4f8f8e74c77e diff --git a/.github/workflows/enterprise-dates.yml b/.github/workflows/enterprise-dates.yml index 86e3c421a0..283f74436b 100644 --- a/.github/workflows/enterprise-dates.yml +++ b/.github/workflows/enterprise-dates.yml @@ -68,7 +68,7 @@ jobs: branch: enterprise-server-dates-update delete-branch: true - - if: ${{ failure() }} + - if: ${{ failure() && env.FREEZE != 'true' }} name: Delete remote branch (if previous steps failed) uses: dawidd6/action-delete-branch@47743101a121ad657031e6704086271ca81b1911 with: @@ -84,7 +84,7 @@ jobs: - name: Send Slack notification if workflow fails uses: someimportantcompany/github-actions-slack-message@f8d28715e7b8a4717047d23f48c39827cacad340 - if: failure() + if: ${{ failure() && env.FREEZE != 'true' }} with: channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }} bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} diff --git a/.github/workflows/remove-unused-assets.yml b/.github/workflows/remove-unused-assets.yml index abaa4c28a0..3b1094ae8f 100644 --- a/.github/workflows/remove-unused-assets.yml +++ b/.github/workflows/remove-unused-assets.yml @@ -58,7 +58,7 @@ jobs: project: Core docs work for the current week project-column: Should do branch: remove-unused-assets - - if: ${{ failure() }} + - if: ${{ failure() && env.FREEZE != 'true' }} name: Delete remote branch (if previous steps failed) uses: dawidd6/action-delete-branch@47743101a121ad657031e6704086271ca81b1911 with: diff --git a/.github/workflows/update-graphql-files.yml b/.github/workflows/update-graphql-files.yml index 8c90fc9db1..f12e2f8c53 100644 --- a/.github/workflows/update-graphql-files.yml +++ b/.github/workflows/update-graphql-files.yml @@ -75,7 +75,7 @@ jobs: number: ${{ steps.create-pull-request.outputs.pull-request-number }} - name: Send Slack notification if workflow fails uses: someimportantcompany/github-actions-slack-message@f8d28715e7b8a4717047d23f48c39827cacad340 - if: failure() + if: ${{ failure() && env.FREEZE != 'true' }} with: channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }} bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}