Skip to content

Commit a7943dc

Browse files
authored
デプロイされているプレビュー環境がない場合はプレビュー環境を削除しないようにする (#10062)
* デプロイされているプレビュー環境がない場合はDestroy preview environmentを実行しないようにする * CIがない場合の処理追加
1 parent c4429ca commit a7943dc

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

.github/workflows/pr-preview-destroy.yml

+33-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,46 @@ name: Destroy preview environment
99
jobs:
1010
destroy-preview-environment:
1111
runs-on: ubuntu-latest
12-
if: github.repository == github.event.pull_request.head.repo.full_name
1312
steps:
13+
- uses: actions/[email protected]
14+
id: check-conclusion
15+
env:
16+
number: ${{ github.event.number }}
17+
with:
18+
github-token: ${{ secrets.GITHUB_TOKEN }}
19+
result-encoding: string
20+
script: |
21+
const { data: pull } = await github.rest.pulls.get({
22+
...context.repo,
23+
pull_number: process.env.number
24+
});
25+
const ref = pull.head.sha;
26+
27+
const { data: checks } = await github.rest.checks.listForRef({
28+
...context.repo,
29+
ref
30+
});
31+
32+
const check = checks.check_runs.filter(c => c.name === 'deploy-preview-environment');
33+
34+
if (check.length === 0) {
35+
return;
36+
}
37+
38+
const { data: result } = await github.rest.checks.get({
39+
...context.repo,
40+
check_run_id: check[0].id,
41+
});
42+
43+
return result.conclusion;
1444
- name: Context
45+
if: steps.check-conclusion.outputs.result == 'success'
1546
uses: okteto/context@latest
1647
with:
1748
token: ${{ secrets.OKTETO_TOKEN }}
1849

1950
- name: Destroy preview environment
51+
if: steps.check-conclusion.outputs.result == 'success'
2052
uses: okteto/destroy-preview@latest
2153
with:
2254
name: pr-${{ github.event.number }}-syuilo

0 commit comments

Comments
 (0)