Skip to content

Commit

Permalink
chore: refactor automatic deployments deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Bizzonium committed Nov 9, 2023
1 parent 0708232 commit c999804
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,34 +116,6 @@ jobs:
production-environment: true
initial-status: "in_progress"

- name: Delete previous automatic deployments
uses: actions/github-script@v6
env:
GITHUB_SHA_HEAD: ${{ github.sha }}
with:
script: |
const { GITHUB_SHA_HEAD } = process.env
const deployments = await github.rest.repos.listDeployments({
owner: context.repo.owner,
repo: context.repo.repo,
sha: GITHUB_SHA_HEAD
});
await Promise.all(
deployments.data.filter((d) => d.performed_via_github_app).map(async (deployment) => {
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.id,
state: 'inactive'
});
return github.rest.repos.deleteDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.id
});
})
);
- name: Update and Build Paradise Main
if: matrix.environment == 'Main' && inputs.perform_deploy_main
uses: appleboy/ssh-action@master
Expand Down Expand Up @@ -260,3 +232,37 @@ jobs:
log-url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
state: "failure"

delete_automatic_deployments:
runs-on: ubuntu-latest
needs: [deploy]
if: always()

steps:
- name: Delete previous automatic deployments
uses: actions/github-script@v6
env:
GITHUB_SHA_HEAD: ${{ github.sha }}
with:
script: |
const { GITHUB_SHA_HEAD } = process.env
const deployments = await github.rest.repos.listDeployments({
owner: context.repo.owner,
repo: context.repo.repo,
sha: GITHUB_SHA_HEAD
});
await Promise.all(
deployments.data.filter((d) => d.performed_via_github_app).map(async (deployment) => {
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.id,
state: 'inactive'
});
return github.rest.repos.deleteDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.id
});
})
);

0 comments on commit c999804

Please sign in to comment.