Skip to content

Commit

Permalink
Only interact with Tugboat for non-doc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JunTaoLuo committed Dec 7, 2023
1 parent bd7c396 commit 8f00239
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 31 deletions.
33 changes: 33 additions & 0 deletions .github/actions/docs-only/action.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 4 additions & 29 deletions .github/workflows/set-tests-statuses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/tugboat-pr-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" \
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/tugboat-pr-opened.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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
18 changes: 16 additions & 2 deletions .github/workflows/tugboat-pr-updated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down

0 comments on commit 8f00239

Please sign in to comment.