From 7ff0438ecc7afdad42ab72219e290205f07d68b7 Mon Sep 17 00:00:00 2001 From: Paul Gottschling Date: Wed, 6 Nov 2024 14:39:44 -0500 Subject: [PATCH] Check redirects introduced by docs changes --- .github/workflows/doc-tests.yaml | 84 ++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 16 deletions(-) diff --git a/.github/workflows/doc-tests.yaml b/.github/workflows/doc-tests.yaml index cc5acd19fe25d..ac557050fbc61 100644 --- a/.github/workflows/doc-tests.yaml +++ b/.github/workflows/doc-tests.yaml @@ -41,21 +41,70 @@ jobs: contents: read steps: - - name: Checkout + - name: Check out teleport + uses: actions/checkout@v4 + with: + repository: 'gravitational/teleport' + path: 'teleport' + + - name: Check out docs + uses: actions/checkout@v4 + with: + repository: 'gravitational/docs' + path: 'docs' + + - name: Generate GitHub Token + id: generate_token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ secrets.REVIEWERS_APP_ID }} + private-key: ${{ secrets.REVIEWERS_PRIVATE_KEY }} + + - name: Check out shared-workflows uses: actions/checkout@v4 with: - repository: "gravitational/docs" - path: "docs" + repository: gravitational/shared-workflows + path: .github/shared-workflows + ref: paul.gottschling/2024-11-06-docs-redirs + + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: 'stable' + + - name: Ensure docs changes include redirects + run: cd .github/shared-workflows/bot && go run main.go -workflow=docpaths -token="${{ steps.generate_token.outputs.token }}" -docs-config-path="${{ github.workspace }}/teleport/docs/config.json" -reviewers="${{ secrets.reviewers }}" + + # Cache node_modules. Unlike the example in the actions/cache repo, this + # caches the node_modules directory instead of the yarn cache. This is + # because yarn needs to build fresh packages even when it copies files + # from the yarn cache into node_modules. + # See: + # https://github.com/actions/cache/blob/main/examples.md#node---yarn + - uses: actions/cache@v4 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: '${{ github.workspace }}/docs/node_modules' + key: ${{ runner.os }}-yarn-${{ hashFiles(format('{0}/docs/yarn.lock', github.workspace)) }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install docs site dependencies + working-directory: docs + if: ${{ steps.yarn-cache.outputs.cache-hit != 'true' }} + # Prevent occasional `yarn install` executions that run indefinitely + timeout-minutes: 10 + run: yarn install - name: Prepare docs site configuration # The environment we use for linting the docs differs from the one we # use for the live docs site in that we only test a single version of # the content. # - # To do this, we replace the three submodules we use for building the - # live docs site with a single submodule, pointing to the - # gravitational/teleport branch we are linting. - # + # To do this, we delete the three submodules we use for building the + # live docs site and copy a gravitational/teleport clone into the + # content directory. + # # The docs engine expects a config.json file at the root of the # gravitational/docs clone that associates directories with git # submodules. By default, these directories represent versioned branches @@ -79,21 +128,23 @@ jobs: echo "" > .gitmodules rm -rf content/* cd content - # Add a submodule at docs/content/teleport - git submodule add --force -b $BRANCH -- https://github.com/gravitational/teleport + # Rather than using a submodule, copy the teleport source into the + # content directory. + cp -r $GITHUB_WORKSPACE/teleport $GITHUB_WORKSPACE/docs/content/teleport cd $GITHUB_WORKSPACE/docs - echo "{\"versions\": [{\"name\": \"teleport\", \"branch\": \"$BRANCH\", \"deprecated\": false}]}" > $GITHUB_WORKSPACE/docs/config.json - yarn install - yarn build-node + jq -nr --arg version $BRANCH '{"versions": [{"name": $version,"branch": $version, "deprecated": false, "latest": true, "current": true }]}' > config.json + cat <<< "$(jq '.scripts."git-update" = "echo Skipping submodule update"' package.json)" > package.json - name: Check spelling run: cd $GITHUB_WORKSPACE/docs && yarn spellcheck content/teleport - - name: Lint the docs - run: cd $GITHUB_WORKSPACE/docs && yarn markdown-lint + - name: Lint docs formatting + working-directory: 'docs' + run: yarn markdown-lint - name: Test the docs build - run: cd $GITHUB_WORKSPACE/docs && yarn install && yarn build + working-directory: docs + run: yarn build stylecheck: name: Lint docs prose style @@ -109,7 +160,7 @@ jobs: repository: "gravitational/teleport" - name: Run the linter - uses: errata-ai/vale-action@38bf078c328061f59879b347ca344a718a736018 # v2.1.0 + uses: errata-ai/vale-action@d89dee975228ae261d22c15adcd03578634d429c # v2.1.1 with: version: 2.30.0 # Take the comma-separated list of files returned by the "Check for @@ -120,4 +171,5 @@ jobs: # changed files. filter_mode: added fail_on_error: true + vale_flags: "--config=docs/.vale.ini"