From c551efc4d8e6700887cff8642b5e962ac8344b89 Mon Sep 17 00:00:00 2001 From: Nathan Melehan Date: Fri, 7 May 2021 13:55:07 -0400 Subject: [PATCH 1/4] Integrate workaround for "head commit not ahead of base commit" Workaround proposed here: https://github.com/jitterbit/get-changed-files/issues/11#issuecomment-718254652 --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 554aa32380e..33ac3e24299 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -39,6 +39,7 @@ jobs: - name: Get Changed Files id: get_changed_files uses: jitterbit/get-changed-files@v1 + continue-on-error: true with: format: 'json' - name: Vale From 569895f07580b66d5dbed0f1a357e55fe306ffcd Mon Sep 17 00:00:00 2001 From: Nathan Melehan Date: Fri, 23 Apr 2021 15:57:44 -0400 Subject: [PATCH 2/4] Vale GHA: filter out files that aren't inside docs/ directory - This helps avoid Vale running on non-content markdown files, like our typography test page. - A new select_docs_dir_files step is added. This step parses and filters the JSON added_modified output from the get_changed_files step. It then sets a new output for this filtered file list that the Vale step later reads from. - The jq command is used to filter the JSON list of files: https://stedolan.github.io/jq/ - This Stack Overflow served as inspiration: https://stackoverflow.com/questions/64482190/edit-the-value-inside-the-json-array-with-github-actions --- .github/workflows/test.yaml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 33ac3e24299..cb798cb1fb5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -42,10 +42,21 @@ jobs: continue-on-error: true with: format: 'json' + - name: Install more-utils + run: sudo apt-get install moreutils + - name: Select Files in Docs Dir + id: select_docs_dir_files + run: | + docs_dir_files=$(echo $added_modified | jq -c '[.[] | select(.|test("^docs/"))]') + echo "::set-output name=added_modified::$docs_dir_files" + echo "Added or modified files located within docs/ directory:" + echo $docs_dir_files | jq '.' + env: + added_modified: ${{ steps.get_changed_files.outputs.added_modified }} - name: Vale uses: errata-ai/vale-action@v1.3.0 with: - files: '${{ steps.get_changed_files.outputs.added_modified }}' + files: '${{ steps.select_docs_dir_files.outputs.added_modified }}' env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} From a1b3bf4a9b590c94bf5aafffefb8c2fbb620dc8f Mon Sep 17 00:00:00 2001 From: Nathan Melehan Date: Mon, 10 May 2021 12:36:40 -0400 Subject: [PATCH 3/4] Only run the Vale step if list of files in docs/ is not empty When the list of files was empty after the select_docs_dir_files step ran, the action would hang at the Vale step: https://github.com/linode/docs/pull/4304/checks?check_run_id=2546802169 --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index cb798cb1fb5..348cc731241 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -55,6 +55,7 @@ jobs: added_modified: ${{ steps.get_changed_files.outputs.added_modified }} - name: Vale uses: errata-ai/vale-action@v1.3.0 + if: ${{ '[]' != steps.select_docs_dir_files.outputs.added_modified }} with: files: '${{ steps.select_docs_dir_files.outputs.added_modified }}' env: From c5155f16f2c63f49178f5d10d43eb66218b68f44 Mon Sep 17 00:00:00 2001 From: Nathan Melehan Date: Mon, 10 May 2021 14:38:24 -0400 Subject: [PATCH 4/4] Vale GHA: add comments --- .github/workflows/test.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 348cc731241..eb29493a415 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -39,12 +39,18 @@ jobs: - name: Get Changed Files id: get_changed_files uses: jitterbit/get-changed-files@v1 + # The continue-on-error parameter is set to true as a + # workaround for the `head commit is not ahead of base + # commit` error that can appear when the PR branch is + # out of date. continue-on-error: true with: format: 'json' - name: Install more-utils run: sudo apt-get install moreutils - name: Select Files in Docs Dir + # This action filters the list of added and modified + # files to only the files that are in the docs/ directory id: select_docs_dir_files run: | docs_dir_files=$(echo $added_modified | jq -c '[.[] | select(.|test("^docs/"))]') @@ -55,6 +61,10 @@ jobs: added_modified: ${{ steps.get_changed_files.outputs.added_modified }} - name: Vale uses: errata-ai/vale-action@v1.3.0 + # Only run the Vale step if the list of added and modified + # files inside the docs directory is not empty. If we don't + # add this conditional, the Vale step hangs and never + # completes when it is passed the empty array. if: ${{ '[]' != steps.select_docs_dir_files.outputs.added_modified }} with: files: '${{ steps.select_docs_dir_files.outputs.added_modified }}'