Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/cleanup-preview-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Cleanup preview environment

on:
pull_request:
types: [closed]

permissions:
deployments: write

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Delete preview environment
uses: actions/github-script@v8
with:
script: |
const environment = `preview-pr-${context.payload.pull_request.number}`;

// Deactivate all deployments for this environment first
const deployments = await github.rest.repos.listDeployments({
owner: context.repo.owner,
repo: context.repo.repo,
environment
});

for (const deployment of deployments.data) {
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.id,
state: 'inactive'
});
}

// Delete the environment
await github.rest.repos.deleteAnEnvironment({
owner: context.repo.owner,
repo: context.repo.repo,
environment_name: environment
});
5 changes: 3 additions & 2 deletions .github/workflows/cloudflare-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
script: |
const isPR = context.eventName === 'pull_request';
const sha = isPR ? context.payload.pull_request.head.sha : context.sha;
const environment = isPR ? 'preview' : 'production';
const environment = isPR ? `preview-pr-${context.payload.pull_request.number}` : 'production';
const deploymentUrl = '${{ steps.deploy.outputs.deployment-url }}';

// GitHub deployment (shows in PR UI)
Expand All @@ -58,7 +58,8 @@ jobs:
ref: sha,
environment,
auto_merge: false,
required_contexts: []
required_contexts: [],
transient_environment: isPR
});
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
Expand Down
Loading