Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

chore: Add deployments cleanup workflow (#4014)

Ivan Starkov829e11c41003
diff --git a/.github/workflows/delete-github-deployments.yml b/.github/workflows/delete-github-deployments.yml
new file mode 100644
index 0000000000..a03b73e1bc
--- /dev/null
+++ b/.github/workflows/delete-github-deployments.yml
@@ -0,0 +1,46 @@
+# https://github.com/orgs/community/discussions/36919
+name: Delete github deployments
+
+on:
+ workflow_call:
+ inputs:
+ sha:
+ 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:
+ SHA_HEAD: ${{ inputs.sha }}
+ with:
+ script: |
+ const { SHA_HEAD } = process.env
+
+ const deployments = await github.rest.repos.listDeployments({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ sha: SHA_HEAD
+ });
+ await Promise.all(
+ 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
+ });
+ })
+ );