diff --git a/.github/workflows/delete_deployments.yaml b/.github/workflows/delete_deployments.yaml new file mode 100644 index 0000000..e153327 --- /dev/null +++ b/.github/workflows/delete_deployments.yaml @@ -0,0 +1,40 @@ +name: Delete Deployments + +on: + workflow_dispatch: + +jobs: + find-old-deployments: + name: Get deployments for this PR + runs-on: ubuntu-latest + outputs: + items: ${{ steps.list_deployments.outputs.data }} + steps: + - name: list deployments + id: list_deployments + uses: octokit/request-action@v2.x + with: + route: GET /repos/:repository/deployments + repository: ${{ github.repository }} + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + + delete-old-deployments: + name: Inactivate deployment + runs-on: ubuntu-latest + needs: + - find-old-deployments + strategy: + fail-fast: false + matrix: + item: ${{ fromJSON(needs.find-old-deployments.outputs.items) }} + steps: + - name: set deployments inactive + id: inactivate_deployments + uses: octokit/request-action@v2.x + with: + route: DELETE /repos/:repository/deployments/:deployment_id + repository: ${{ github.repository }} + deployment_id: ${{ matrix.item.id }} + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" \ No newline at end of file diff --git a/.github/workflows/test-deploy.yaml b/.github/workflows/test-deploy.yaml index ebd3c74..5e81a86 100644 --- a/.github/workflows/test-deploy.yaml +++ b/.github/workflows/test-deploy.yaml @@ -9,7 +9,7 @@ jobs: name: Get deployments for this PR runs-on: ubuntu-latest outputs: - items: ${{ steps.list_deployments.outputs.data }} + items: ${{ fromJSON(steps.list_deployments.outputs.data) }} steps: - name: list deployments id: list_deployments @@ -24,13 +24,13 @@ jobs: delete-old-deployments: name: Inactivate deployment runs-on: ubuntu-latest - if: ${{ github.event.action == 'closed' }} + if: steps.find-old-deployments.outputs.items[0] != null needs: - find-old-deployments strategy: fail-fast: false matrix: - item: ${{ fromJSON(needs.find-old-deployments.outputs.items) }} + item: ${{ needs.find-old-deployments.outputs.items }} steps: - name: set deployments inactive id: inactivate_deployments