summaryrefslogtreecommitdiff
path: root/.github/workflows/pr-preview-destroy.yml
blob: 8967eb2f94a4de7f93d19b39c68e33fe1a12e83b (plain)
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
53
54
# file: .github/workflows/preview-closed.yaml
on:
  pull_request:
    types:
      - closed

name: Destroy preview environment

jobs:
  destroy-preview-environment:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/github-script@v7.0.1
        id: check-conclusion
        env:
          number: ${{ github.event.number }}
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          result-encoding: string
          script: |
            const { data: pull } = await github.rest.pulls.get({
              ...context.repo,
              pull_number: process.env.number
            });
            const ref = pull.head.sha;

            const { data: checks } = await github.rest.checks.listForRef({
              ...context.repo,
              ref
            });

            const check = checks.check_runs.filter(c => c.name === 'deploy-preview-environment');

            if (check.length === 0) {
              return;
            }

            const { data: result } = await github.rest.checks.get({
              ...context.repo,
              check_run_id: check[0].id,
            });

            return result.conclusion;
      - name: Context
        if: steps.check-conclusion.outputs.result == 'success'
        uses: okteto/context@latest
        with:
          token: ${{ secrets.OKTETO_TOKEN }}

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