|
| 1 | +name: Automated test for PRs |
| 2 | + |
| 3 | +# Run any time a PR is created or modified |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + types: [opened, reopened, synchronize] |
| 7 | + |
| 8 | +env: |
| 9 | + # The folder with the doc files |
| 10 | + DOCS_FOLDER: 'docs' |
| 11 | + # The folder that Docusaurus hosts static files (images) from |
| 12 | + STATIC_FOLDER: 'static' |
| 13 | + # Images to ignore for image use checks |
| 14 | + IGNORE_IMAGES: 'img/site' |
| 15 | + # The folder that the tests repo is cloned to |
| 16 | + TEST_REPO: 'doclib' |
| 17 | + |
| 18 | +jobs: |
| 19 | + |
| 20 | + # Get files that are added or changed in this PR |
| 21 | + # Provides the files as a comma-separated list |
| 22 | + getChangedFiles: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + outputs: |
| 25 | + files: ${{ steps.changed-markdown-files.outputs.all_changed_files }} |
| 26 | + steps: |
| 27 | + # https://github.com/marketplace/actions/changed-files |
| 28 | + - name: Get all changed MD/MDX files |
| 29 | + id: changed-markdown-files |
| 30 | + uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47 |
| 31 | + with: |
| 32 | + separator: ',' |
| 33 | + files: | |
| 34 | + docs/**/*.md |
| 35 | + docs/**/*.mdx |
| 36 | +
|
| 37 | + # Test the changed files |
| 38 | + test: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + needs: [getChangedFiles] |
| 41 | + if: ${{ needs.getChangedFiles.outputs.files != '' }} |
| 42 | + steps: |
| 43 | + # Clone the repo |
| 44 | + - uses: actions/checkout@v2 |
| 45 | + - uses: actions/setup-node@v1 |
| 46 | + with: |
| 47 | + node-version: 20 |
| 48 | + # Dependencies may not be necessary |
| 49 | + # - run: npm ci |
| 50 | + |
| 51 | + # Clone tests from https://gitlab.com/nomadic-labs/doclib |
| 52 | + # Uses https://github.com/marketplace/actions/any-clone-repo |
| 53 | + - name: Clone test repo |
| 54 | + uses: chihqiang/checkout-action@main |
| 55 | + with: |
| 56 | + repo: https://gitlab.com/nomadic-labs/doclib.git |
| 57 | + branch: main |
| 58 | + dest: ${{ env.TEST_REPO }} |
| 59 | + - name: Install test repo dependencies |
| 60 | + working-directory: ${{ env.TEST_REPO }} |
| 61 | + run : npm ci |
| 62 | + |
| 63 | + # Run tests |
| 64 | + - name: Run image link check |
| 65 | + working-directory: ${{ env.TEST_REPO }} |
| 66 | + # Here, --docFiles is the list of changed files so the test checks the links to images in only those files |
| 67 | + run: npm run imageLinks -- --baseFolder=${{ github.workspace }} --docFiles=${{ needs.getChangedFiles.outputs.files }} --imageFolder=${{ env.STATIC_FOLDER }} |
| 68 | + |
| 69 | + - name: Run unused image check |
| 70 | + working-directory: ${{ env.TEST_REPO }} |
| 71 | + # Here, --docFiles is the folder where all of the doc files are so the test can check that no images have become abandoned |
| 72 | + run: npm run usedImages -- --baseFolder=${{ github.workspace }} --docFiles=${{ env.DOCS_FOLDER }} --imageFolder=${{ env.STATIC_FOLDER }} --ignoreImages=${{ env.IGNORE_IMAGES }} |
0 commit comments