diff --git a/.github/workflows/purge-old-deployment-environments.yml b/.github/workflows/purge-old-deployment-environments.yml deleted file mode 100644 index 3feece3b5f..0000000000 --- a/.github/workflows/purge-old-deployment-environments.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Purge old deployment environments - -# **What it does**: -# Deletes old deployment environments. A deployment environment exists -# for the sake of a Azure Preview environment. Those Azure Preview environments -# and cleaned up by a separate process. -# **Why we have it**: To keep things neat and tidy. -# **Who does it impact**: Docs engineering. - -on: - workflow_dispatch: - schedule: - - cron: '20 16 * * *' # Run every day at 16:20 UTC / 8:20 PST - -permissions: - contents: write - -jobs: - purge-old-deployment-environments: - if: ${{ github.repository == 'github/docs-internal' || github.repository == 'github/docs' }} - runs-on: ubuntu-latest - steps: - - name: Checkout out repo - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - - uses: ./.github/actions/node-npm-setup - - - name: Run purge script - env: - # Necessary to be able to delete deployment environments - GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WORKFLOW_READORG }} - run: npm run purge-old-deployment-environments - - - uses: ./.github/actions/slack-alert - if: ${{ failure() && github.event_name != 'workflow_dispatch' }} - with: - slack_channel_id: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }} - slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} diff --git a/package.json b/package.json index be6e6ba2a1..efb2b3b728 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,6 @@ "prevent-pushes-to-main": "tsx src/workflows/prevent-pushes-to-main.ts", "purge-fastly-edge-cache": "tsx src/workflows/purge-fastly-edge-cache.ts", "purge-fastly-edge-cache-per-language": "tsx src/languages/scripts/purge-fastly-edge-cache-per-language.js", - "purge-old-deployment-environments": "tsx src/workflows/purge-old-deployment-environments.ts", "purge-old-workflow-runs": "tsx src/workflows/purge-old-workflow-runs.js", "ready-for-docs-review": "tsx src/workflows/ready-for-docs-review.ts", "release-banner": "tsx src/ghes-releases/scripts/release-banner.js", diff --git a/src/workflows/purge-old-deployment-environments.ts b/src/workflows/purge-old-deployment-environments.ts deleted file mode 100755 index 9c1726247c..0000000000 --- a/src/workflows/purge-old-deployment-environments.ts +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env node - -import assert from 'node:assert/strict' - -import { getOctokit } from '@actions/github' - -main() -async function main() { - const DRY_RUN = Boolean(JSON.parse(process.env.DRY_RUN || 'false')) - const MAX_DELETIONS = parseInt(JSON.parse(process.env.MAX_DELETIONS || '10')) - const MIN_AGE_DAYS = parseInt(process.env.MIN_AGE_DAYS || '90', 10) - - const [owner, repo] = (process.env.GITHUB_REPOSITORY || '').split('/') || [] - if (!owner || !repo) { - throw new Error('GITHUB_REPOSITORY environment variable not set') - } - const token = process.env.GITHUB_TOKEN - if (!token) { - throw new Error(`GITHUB_TOKEN environment variable not set`) - } - const github = getOctokit(token) - - // The sort order is not explicitly listed for this API endpoint. - // In practice it appears to list those that are oldest first. - // But to guarantee that it reaches the oldest, we paginate over - // all of them. - const environments = await github.paginate('GET /repos/{owner}/{repo}/environments', { - owner, - repo, - }) - - console.log(`Found ${environments.length.toLocaleString()} environments in total`) - - let countDeletions = 0 - for (const environment of environments) { - const ageDays = (Date.now() - Date.parse(environment.created_at)) / 1000 / 60 / 60 / 24 - if (ageDays > MIN_AGE_DAYS) { - console.log( - `Deleting environment ${environment.name} created ${Math.ceil(ageDays)} days ago`, - DRY_RUN ? '(DRY RUN)' : '', - ) - if (!DRY_RUN) { - const { status } = await github.request( - 'DELETE /repos/{owner}/{repo}/environments/{name}', - { - owner, - repo, - name: environment.name, - }, - ) - assert(status === 204, `Expected status 204, got ${status}`) - } - countDeletions++ - if (MAX_DELETIONS && countDeletions >= MAX_DELETIONS) { - console.log(`Reached max number of deletions: ${MAX_DELETIONS}`) - break - } - } else { - console.log( - `Environment ${environment.name} (${environment.id}) created ${Math.ceil( - ageDays, - )} days ago, is *not* old enough`, - ) - } - } - console.log(`Deleted ${countDeletions} environments`, DRY_RUN ? '(DRY RUN)' : '') -}