From 8f00239ee216129e780c5548ba3e73cf07c8a87d Mon Sep 17 00:00:00 2001 From: John Luo Date: Thu, 7 Dec 2023 15:51:39 -0500 Subject: [PATCH] Only interact with Tugboat for non-doc changes --- .github/actions/docs-only/action.yml | 33 ++++++++++++++++++++++++ .github/workflows/set-tests-statuses.yml | 33 +++--------------------- .github/workflows/tugboat-pr-closed.yml | 9 +++++++ .github/workflows/tugboat-pr-opened.yml | 9 +++++++ .github/workflows/tugboat-pr-updated.yml | 18 +++++++++++-- 5 files changed, 71 insertions(+), 31 deletions(-) create mode 100644 .github/actions/docs-only/action.yml diff --git a/.github/actions/docs-only/action.yml b/.github/actions/docs-only/action.yml new file mode 100644 index 000000000..99ebde24b --- /dev/null +++ b/.github/actions/docs-only/action.yml @@ -0,0 +1,33 @@ +name: "VA.gov CMS Documentation Only PR Check" +description: "Checks if the current PR contains only documentation changes" +inputs: {} +outputs: + docs-only: + description: "'true' if the PR contains only documentation changes, otherwise 'false'" + value: ${{ steps.docs-only.outputs.result }} + +runs: + using: "composite" + steps: + + - name: Check for documentation only changes + id: docs-only + uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 + with: + script: | + const opts = github.rest.pulls.listFiles.endpoint.merge({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + }) + const files = await github.paginate(opts, (response) => + response.data.map((file) => file.filename)) + for (const file of files) { + console.log(`Checking PR file: ${file}`) + if (!file.endsWith('.md')) { + console.log(`Code changes found in: ${file}`) + return "false" + } + } + return "true" + result-encoding: string \ No newline at end of file diff --git a/.github/workflows/set-tests-statuses.yml b/.github/workflows/set-tests-statuses.yml index 10781062d..81f06a8f1 100644 --- a/.github/workflows/set-tests-statuses.yml +++ b/.github/workflows/set-tests-statuses.yml @@ -29,36 +29,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - name: Check for documentation only changes + - name: Documentation Only PR Check + uses: ./.github/actions/docs-only id: docs-only - uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 - with: - script: | - const opts = github.rest.pulls.listFiles.endpoint.merge({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.payload.pull_request.number, - }) - const files = await github.paginate( - opts, - (response) => response.data.map( - (file) => file.filename - ) - ) - - for (const file of files) { - console.log(`Checking PR file: ${file}`) - if (!file.endsWith('.md')) { - console.log(`Code change found in: ${file}`) - return "false" - } - } - - console.log(`No code change found.`) - return "true" - result-encoding: string - name: Set status for documentation changes. - if: ${{ steps.docs-only.outputs.result == 'true' }} + if: ${{ steps.docs-only.outputs.docs-only == 'true' }} run: | test_names=( va/tests/cypress @@ -86,7 +61,7 @@ jobs: SHA: ${{ github.event.pull_request.head.sha }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Set status for code changes. - if: ${{ steps.docs-only.outputs.result == 'false' }} + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} run: | test_names=( va/tests/cypress diff --git a/.github/workflows/tugboat-pr-closed.yml b/.github/workflows/tugboat-pr-closed.yml index d0f8aa9b2..e80db4432 100644 --- a/.github/workflows/tugboat-pr-closed.yml +++ b/.github/workflows/tugboat-pr-closed.yml @@ -9,12 +9,17 @@ jobs: runs-on: self-hosted name: Delete Tugboat Preview steps: + - name: Documentation Only PR Check + uses: ./.github/actions/docs-only + id: docs-only - name: Restore Preview ID + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 with: path: .tugboat_preview.txt key: ${{ runner.os }}-tugboat-preview-id-pr-${{ github.event.pull_request.number }} - name: Set Preview ID + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} run: | PREVIEW_ID=$(cat .tugboat_preview.txt) if [ -z "$PREVIEW_ID" ]; then @@ -24,7 +29,11 @@ jobs: echo $PREVIEW_ID echo "PREVIEW_ID=$PREVIEW_ID" >> $GITHUB_ENV fi + - name: Cleanup temporary file + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} + run: rm .tugboat_preview.txt - name: Delete Tugboat Preview + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} run: | curl -H "Authorization: Bearer ${{ secrets.TUGBOAT_API_TOKEN }}" \ -H "Content-Type: application/json" \ diff --git a/.github/workflows/tugboat-pr-opened.yml b/.github/workflows/tugboat-pr-opened.yml index 7cf78c0b0..2416ea9f6 100644 --- a/.github/workflows/tugboat-pr-opened.yml +++ b/.github/workflows/tugboat-pr-opened.yml @@ -10,8 +10,12 @@ jobs: runs-on: self-hosted name: Create Tugboat Preview steps: + - name: Documentation Only PR Check + uses: ./.github/actions/docs-only + id: docs-only - name: Create Tugboat Preview id: tugboat_pr_preview + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} run: | curl -H "Authorization: Bearer ${{ secrets.TUGBOAT_API_TOKEN }}" \ -H "Content-Type: application/json" \ @@ -20,18 +24,23 @@ jobs: -o .tugboat_response.json \ https://api.tugboat.vfs.va.gov/v3/previews - name: Diagnostics + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} run: cat .tugboat_response.json - name: Extract Preview ID + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} run: jq -r .preview .tugboat_response.json > .tugboat_preview.txt - name: Delete Previous Preview ID continue-on-error: true + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} run: | gh extension install actions/gh-actions-cache gh actions-cache delete "${{ runner.os }}-tugboat-preview-id-pr-${{ github.event.pull_request.number }}" --confirm - name: Save Preview ID + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 with: path: .tugboat_preview.txt key: ${{ runner.os }}-tugboat-preview-id-pr-${{ github.event.pull_request.number }} - name: Cleanup temporary file + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} run: rm .tugboat_preview.txt \ No newline at end of file diff --git a/.github/workflows/tugboat-pr-updated.yml b/.github/workflows/tugboat-pr-updated.yml index 2095dfdbb..444d19654 100644 --- a/.github/workflows/tugboat-pr-updated.yml +++ b/.github/workflows/tugboat-pr-updated.yml @@ -9,17 +9,31 @@ jobs: runs-on: self-hosted name: Rebuild Tugboat Preview steps: + - name: Documentation Only PR Check + uses: ./.github/actions/docs-only + id: docs-only - name: Restore Preview ID + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 with: path: .tugboat_preview.txt key: ${{ runner.os }}-tugboat-preview-id-pr-${{ github.event.pull_request.number }} - name: Set Preview ID + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} run: | PREVIEW_ID=$(cat .tugboat_preview.txt) - echo $PREVIEW_ID - echo "PREVIEW_ID=$PREVIEW_ID" >> $GITHUB_ENV + if [ -z "$PREVIEW_ID" ]; then + echo "Preview ID not found, please manually rebuild Tugboat Preview." + exit 1 + else + echo $PREVIEW_ID + echo "PREVIEW_ID=$PREVIEW_ID" >> $GITHUB_ENV + fi + - name: Cleanup temporary file + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} + run: rm .tugboat_preview.txt - name: Rebuild Tugboat Preview + if: ${{ steps.docs-only.outputs.docs-only == 'false' }} run: | curl -H "Authorization: Bearer ${{ secrets.TUGBOAT_API_TOKEN }}" \ -H "Content-Type: application/json" \