|
1 | 1 | name: "Delete deployment(s)"
|
2 |
| -description: "Action to delete some deployment(s) for the current ref. It also deletes the associated environment(s) if it is a review-app" |
| 2 | +description: "Action to delete some deployment(s) for the current ref. It also deletes the associated review apps environment(s) if any." |
3 | 3 | author: Hoverkraft
|
4 | 4 | branding:
|
5 | 5 | icon: trash-2
|
6 | 6 | color: gray-dark
|
7 | 7 |
|
8 | 8 | inputs:
|
9 | 9 | token:
|
10 |
| - description: "The token to use to delete the environment(s)" |
| 10 | + description: "The token to use to delete the review apps environment(s). It needs the `repo` scope." |
11 | 11 | required: false
|
12 | 12 |
|
13 | 13 | outputs:
|
14 | 14 | deployment-ids:
|
15 |
| - description: "The id(s) of the deleted deployment(s). Json array format" |
| 15 | + description: "The id(s) of the deleted deployment(s). Json array format." |
16 | 16 | value: ${{ steps.delete-deployments.outputs.deployment-ids }}
|
17 | 17 | environments:
|
18 |
| - description: "The name(s) of the environment(s) related to deleted deployment(s). Json array format" |
| 18 | + description: "The name(s) of the environment(s) related to deleted deployment(s). Json array format." |
19 | 19 | value: ${{ steps.delete-deployments.outputs.environments }}
|
20 | 20 |
|
21 | 21 | runs:
|
@@ -66,23 +66,23 @@ runs:
|
66 | 66 | environments.add(deployment.environment);
|
67 | 67 | }
|
68 | 68 |
|
| 69 | + const reviewAppsEnvironments = Array.from(environments).filter((environment) => environment.startsWith('review-apps')); |
| 70 | +
|
69 | 71 | core.setOutput('deployment-ids', JSON.stringify(deploymentIds));
|
70 | 72 | core.setOutput('environments', JSON.stringify(Array.from(environments)));
|
| 73 | + core.setOutput('review-apps-environments', JSON.stringify(reviewAppsEnvironments)); |
71 | 74 |
|
72 |
| - - id: delete-environments |
| 75 | + - id: delete-review-apps-environments |
| 76 | + if: steps.delete-deployments.outputs.review-apps-environments != '[]' |
73 | 77 | uses: actions/github-script@v7
|
74 | 78 | with:
|
75 | 79 | github-token: ${{ inputs.token }}
|
76 | 80 | script: |
|
77 |
| - const environments = JSON.parse(core.getInput('environments')); |
78 |
| -
|
79 |
| - // Clean up the environment if it is a review-app |
80 |
| - for (const environment of environments) { |
81 |
| - if (environment.startsWith('review-apps')) { |
82 |
| - await github.rest.repos.deleteAnEnvironment({ |
83 |
| - owner: context.repo.owner, |
84 |
| - repo: context.repo.repo, |
85 |
| - environment_name: environment, |
86 |
| - }); |
87 |
| - } |
| 81 | + const reviewAppsEnvironments = JSON.parse(`${{ steps.delete-deployments.outputs.review-apps-environments }}`); |
| 82 | + for (const environment of reviewAppsEnvironments) { |
| 83 | + await github.rest.repos.deleteAnEnvironment({ |
| 84 | + owner: context.repo.owner, |
| 85 | + repo: context.repo.repo, |
| 86 | + environment_name: environment, |
| 87 | + }); |
88 | 88 | }
|
0 commit comments