From 2e0f7a1133dbf14129d9a1f2f774bcd8f16564ec Mon Sep 17 00:00:00 2001 From: Kevin Heis Date: Tue, 20 Sep 2022 13:04:08 -0700 Subject: [PATCH] Remove fetch-depth: 0 by running git fetch instead (#30953) --- .github/workflows/link-check-all.yml | 25 +++++++++++++++---------- .github/workflows/test.yml | 17 +++++++++++++---- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/.github/workflows/link-check-all.yml b/.github/workflows/link-check-all.yml index 0a5e1cea58..f11f3e2faf 100644 --- a/.github/workflows/link-check-all.yml +++ b/.github/workflows/link-check-all.yml @@ -28,9 +28,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748 - # Get the branches so merge_group can make the comparison with git diff - with: - fetch-depth: 0 - name: Setup node uses: actions/setup-node@17f8bd926464a1afa4c6a11669539e9c1ba77048 @@ -41,38 +38,46 @@ jobs: - name: Install run: npm ci - # Creates file "${{ env.HOME }}/files.json", among others - name: Gather files changed env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR: ${{ github.event.pull_request.number }} HEAD: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }} run: | + # Find the file diff in the pull request or merge group # 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 # Formats into single line JSON array, removing any empty strings - echo $DIFF | tr ' ' '\n' | jq --raw-input | jq --slurp --compact-output 'map(select(length > 0))' > $HOME/files.json - - # For verification - - name: Show files changed - run: cat $HOME/files.json + echo __ format, write to files.json __ + echo $DIFF | \ + tr ' ' '\n' | \ + jq --raw-input | \ + jq --slurp --compact-output 'map(select(length > 0))' \ + > $HOME/files.json - name: Link check (warnings, changed files) env: # Don't care about CDN caching image URLs DISABLE_REWRITE_ASSET_URLS: true run: | - # Note as of Aug 2022, we *don't* check external links # on the pages you touched in the PR. We could enable that # but it has the added risk of false positives blocking CI. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c8e0be7623..e470a58d20 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,7 +36,6 @@ jobs: strategy: fail-fast: false matrix: - # The same array lives in test-windows.yml, so make any updates there too. test-group: [ content, @@ -73,9 +72,9 @@ jobs: # only for the test groups that we know need the files. lfs: ${{ matrix.test-group == 'content' }} # Enables cloning the Early Access repo later with the relevant PAT - persist-credentials: 'false' - # Get the branches so merge_group can make the comparison with git diff - fetch-depth: 0 + # persist-credentials: 'false' + # ->> Do we really need this? actions/checkout doesn't use it for the nested example: + # https://github.com/actions/checkout#checkout-multiple-repos-nested - name: Figure out which docs-early-access branch to checkout, if internal repo if: ${{ github.repository == 'github/docs-internal' }} @@ -135,21 +134,31 @@ jobs: PR: ${{ github.event.pull_request.number }} HEAD: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }} run: | + # Find the file diff in the pull request or merge group # 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 to 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 - name: Setup node