-
Notifications
You must be signed in to change notification settings - Fork 1.5k
52 lines (45 loc) · 1.37 KB
/
delete-github-deployments.yml
File metadata and controls
52 lines (45 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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@v7
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
});
})
);