# https://github.com/orgs/community/discussions/36919 name: Delete github deployments on: workflow_call: inputs: ref: type: string required: true permissions: deployments: write jobs: delete_github_deployments: runs-on: ubuntu-latest if: ${{ always() }} steps: - name: Delete Previous deployments uses: actions/github-script@v8 env: REF: ${{ inputs.ref }} with: script: | const { REF } = process.env; console.log(REF); const deployments = await github.rest.repos.listDeployments({ owner: context.repo.owner, repo: context.repo.repo, ref: REF, per_page: 100 }); console.log(deployments); await Promise.allSettled( deployments.data.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 }); }) );