Skip to content

Commit

Permalink
Replace Tugboat webhook integration with Tugboat API in GHA workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
JunTaoLuo committed Dec 9, 2023
1 parent 0c0d6fe commit a12ee32
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/tugboat-pr-closed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Delete Tugboat Preview
on:
pull_request:
types:
- closed
paths-ignore:
- '**.md'

jobs:
tugboat_delete_preview:
runs-on: self-hosted
env:
NODE_EXTRA_CA_CERTS: /etc/ssl/certs/ca-certificates.crt
name: Delete Tugboat Preview
steps:
- name: Restore Preview ID
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
run: |
if ! [ -f .tugboat_preview.txt ]; then
echo "Preview ID not found, please manually delete Tugboat Preview."
exit 1
fi
PREVIEW_ID=$(cat .tugboat_preview.txt)
echo "Preview ID: ${PREVIEW_ID}"
echo "PREVIEW_ID=$PREVIEW_ID" >> $GITHUB_ENV
- name: Cleanup temporary file
run: rm .tugboat_preview.txt
- name: Delete Tugboat Preview
run: |
curl -H "Authorization: Bearer ${{ secrets.TUGBOAT_API_TOKEN }}" \
-H "Content-Type: application/json" \
-X DELETE \
-d '{ "force": "false" }' \
https://api.tugboat.vfs.va.gov/v3/previews/${{ env.PREVIEW_ID }}
41 changes: 41 additions & 0 deletions .github/workflows/tugboat-pr-opened.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Create Tugboat Preview
on:
pull_request:
types:
- opened
- reopened
paths-ignore:
- '**.md'

jobs:
tugboat_create_preview:
runs-on: self-hosted
env:
NODE_EXTRA_CA_CERTS: /etc/ssl/certs/ca-certificates.crt
name: Create Tugboat Preview
steps:
- name: Create Tugboat Preview
id: tugboat_pr_preview
run: |
curl -H "Authorization: Bearer ${{ secrets.TUGBOAT_API_TOKEN }}" \
-H "Content-Type: application/json" \
-X POST \
-d '{ "repo": "${{ secrets.TUGBOAT_REPOSITORY }}", "ref": "${{ github.event.pull_request.number }}", "name": "${{ github.event.pull_request.title }}", "type": "pullrequest" }' \
-o .tugboat_response.json \
https://api.tugboat.vfs.va.gov/v3/previews
- name: Diagnostics
run: cat .tugboat_response.json
- name: Extract Preview ID
run: jq -r .preview .tugboat_response.json > .tugboat_preview.txt
- name: Delete Previous Preview ID
continue-on-error: true
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
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
run: rm .tugboat_preview.txt
38 changes: 38 additions & 0 deletions .github/workflows/tugboat-pr-updated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Rebuild Tugboat Preview
on:
pull_request:
types:
- synchronize
paths-ignore:
- '**.md'

jobs:
tugboat_rebuild_preview:
runs-on: self-hosted
env:
NODE_EXTRA_CA_CERTS: /etc/ssl/certs/ca-certificates.crt
name: Rebuild Tugboat Preview
steps:
- name: Restore Preview ID
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
run: |
if ! [ -f .tugboat_preview.txt ]; then
echo "Preview ID not found, please manually rebuild Tugboat Preview."
exit 1
fi
PREVIEW_ID=$(cat .tugboat_preview.txt)
echo "Preview ID: ${PREVIEW_ID}"
echo "PREVIEW_ID=$PREVIEW_ID" >> $GITHUB_ENV
- name: Cleanup temporary file
run: rm .tugboat_preview.txt
- name: Rebuild Tugboat Preview
run: |
curl -H "Authorization: Bearer ${{ secrets.TUGBOAT_API_TOKEN }}" \
-H "Content-Type: application/json" \
-X POST \
-d '{ "children": "false", "force": "false" }' \
https://api.tugboat.vfs.va.gov/v3/previews/${{ env.PREVIEW_ID }}/rebuild

0 comments on commit a12ee32

Please sign in to comment.