diff --git a/.github/workflows/tugboat-pr-closed.yml b/.github/workflows/tugboat-pr-closed.yml new file mode 100644 index 000000000..65b661e3c --- /dev/null +++ b/.github/workflows/tugboat-pr-closed.yml @@ -0,0 +1,27 @@ +name: Delete Tugboat Preview +on: + pull_request: + types: + - closed + +jobs: + tugboat_delete_preview: + runs-on: self-hosted + 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: | + PREVIEW_ID=$(cat .tugboat_preview.txt) + echo $PREVIEW_ID + echo "PREVIEW_ID=$PREVIEW_ID" >> $GITHUB_ENV + - name: Delete Tugboat Preview + run: | + curl -H "Authorization: Bearer ${{ secrets.TUGBOAT_API_TOKEN }}" \ + -H "Content-Type: application/json" \ + -X DELETE \ + https://api.tugboat.vfs.va.gov/v3/previews/${{ env.PREVIEW_ID }} \ No newline at end of file diff --git a/.github/workflows/tugboat-pr-opened.yml b/.github/workflows/tugboat-pr-opened.yml index e64f352c4..606a8dac5 100644 --- a/.github/workflows/tugboat-pr-opened.yml +++ b/.github/workflows/tugboat-pr-opened.yml @@ -3,6 +3,7 @@ on: pull_request: types: - opened + - reopened jobs: tugboat_create_preview: @@ -22,7 +23,12 @@ jobs: run: cat .tugboat_response.json - name: Extract Preview ID run: jq -r .preview .tugboat_response.json > .tugboat_preview.txt - - name: Save Preview ID + - 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 diff --git a/.github/workflows/tugboat-pr-updated.yml b/.github/workflows/tugboat-pr-updated.yml new file mode 100644 index 000000000..2095dfdbb --- /dev/null +++ b/.github/workflows/tugboat-pr-updated.yml @@ -0,0 +1,27 @@ +name: Rebuild Tugboat Preview +on: + pull_request: + types: + - synchronize + +jobs: + tugboat_rebuild_preview: + runs-on: self-hosted + 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: | + PREVIEW_ID=$(cat .tugboat_preview.txt) + echo $PREVIEW_ID + echo "PREVIEW_ID=$PREVIEW_ID" >> $GITHUB_ENV + - name: Rebuild Tugboat Preview + run: | + curl -H "Authorization: Bearer ${{ secrets.TUGBOAT_API_TOKEN }}" \ + -H "Content-Type: application/json" \ + -X POST \ + https://api.tugboat.vfs.va.gov/v3/previews/${{ env.PREVIEW_ID }}/rebuild \ No newline at end of file