Skip to content

Clean up branch deployment #1260

Clean up branch deployment

Clean up branch deployment #1260

name: Clean up branch deployment
on:
delete
jobs:
delete_latest_deployment_for_branch:
name: Delete latest deployment for branch
if: github.event.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- name: Get deployments for branch
id: get_branch_deployments
uses: octokit/request-action@v2.x
with:
route: GET /repos/:repository/deployments
repository: ${{ github.repository }}
ref: ${{ startsWith(github.event.ref, 'refs/heads/') && '' || 'refs/heads/' }}${{ github.event.ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Get latest deployment"
id: get_latest_deployment
if: fromJson(steps.get_branch_deployments.outputs.data)[0] != null
run: echo "::set-output name=id::${{ fromJson(steps.get_branch_deployments.outputs.data)[0].id }}"
- name: Set deployment status to inactive
if: steps.get_latest_deployment.outputs.id != null
uses: octokit/request-action@v2.x
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ steps.get_latest_deployment.outputs.id }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: inactive
mediaType: '{"previews": ["ant-man"]}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Delete deployment
if: steps.get_latest_deployment.outputs.id != null
uses: octokit/request-action@v2.x
with:
route: DELETE /repos/:repository/deployments/:deployment
repository: ${{ github.repository }}
deployment: ${{ steps.get_latest_deployment.outputs.id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}