Skip to content

Commit deb92c1

Browse files
authored
Merge branch 'main' into rc-ghes-3.10
2 parents 053fe9e + 3bda0ac commit deb92c1

File tree

167 files changed

+1572
-292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+1572
-292
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env node
2+
3+
import assert from 'node:assert/strict'
4+
5+
import { getOctokit } from '@actions/github'
6+
7+
main()
8+
async function main() {
9+
const DRY_RUN = Boolean(JSON.parse(process.env.DRY_RUN || 'false'))
10+
const MAX_DELETIONS = parseInt(JSON.parse(process.env.MAX_DELETIONS || '10'))
11+
const MIN_AGE_DAYS = parseInt(process.env.MIN_AGE_DAYS || '90', 10)
12+
13+
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/')
14+
if (!owner || !repo) {
15+
throw new Error('GITHUB_REPOSITORY environment variable not set')
16+
}
17+
const token = process.env.GITHUB_TOKEN
18+
if (!token) {
19+
throw new Error(`GITHUB_TOKEN environment variable not set`)
20+
}
21+
const github = getOctokit(token)
22+
23+
// The sort order is not explicitly listed for this API endpoint.
24+
// In practice it appears to list those that are oldest first.
25+
// But to guarantee that it reaches the oldest, we paginate over
26+
// all of them.
27+
const environments = await github.paginate('GET /repos/{owner}/{repo}/environments', {
28+
owner,
29+
repo,
30+
})
31+
32+
let countDeletions = 0
33+
for (const environment of environments) {
34+
const ageDays = (Date.now() - Date.parse(environment.created_at)) / 1000 / 60 / 60 / 24
35+
if (ageDays > MIN_AGE_DAYS) {
36+
console.log(
37+
`Deleting environment ${environment.name} created ${Math.ceil(ageDays)} days ago`,
38+
DRY_RUN ? '(DRY RUN)' : '',
39+
)
40+
if (!DRY_RUN) {
41+
const { status } = await github.request(
42+
'DELETE /repos/{owner}/{repo}/environments/{name}',
43+
{
44+
owner,
45+
repo,
46+
name: environment.name,
47+
},
48+
)
49+
assert(status === 204, `Expected status 204, got ${status}`)
50+
}
51+
countDeletions++
52+
if (MAX_DELETIONS && countDeletions >= MAX_DELETIONS) {
53+
console.log(`Reached max number of deletions: ${MAX_DELETIONS}`)
54+
break
55+
}
56+
} else {
57+
console.log(
58+
`Environment ${environment.name} (${environment.id}) created ${Math.ceil(
59+
ageDays,
60+
)} days ago, is *not* old enough`,
61+
)
62+
}
63+
}
64+
console.log(`Deleted ${countDeletions} environments`, DRY_RUN ? '(DRY RUN)' : '')
65+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Purge old deployment environments
2+
3+
# **What it does**:
4+
# Deletes old deployment environments. A deployment environment exists
5+
# for the sake of a Azure Preview environment. Those Azure Preview environments
6+
# and cleaned up by a separate process.
7+
# **Why we have it**: To keep things neat and tidy.
8+
# **Who does it impact**: Docs engineering.
9+
10+
on:
11+
workflow_dispatch:
12+
schedule:
13+
- cron: '20 16 * * *' # Run every day at 16:20 UTC / 8:20 PST
14+
15+
permissions:
16+
contents: write
17+
18+
jobs:
19+
purge-old-deployment-environments:
20+
if: ${{ github.repository == 'github/docs-internal' || github.repository == 'github/docs' }}
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout out repo
24+
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
25+
26+
- uses: ./.github/actions/node-npm-setup
27+
28+
- name: Run purge script
29+
if: ${{ env.FREEZE != 'true' }}
30+
env:
31+
GITHUB_REPOSITORY: ${{ github.repository }}
32+
# Necessary to be able to delete deployment environments
33+
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_WORKFLOW_READORG }}
34+
run: .github/actions-scripts/purge-old-deployment-environments.js
35+
36+
- name: Send Slack notification if workflow fails
37+
uses: someimportantcompany/github-actions-slack-message@1d367080235edfa53df415bd8e0bbab480f29bad
38+
if: ${{ failure() && env.FREEZE != 'true' }}
39+
with:
40+
channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }}
41+
bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
42+
color: failure
43+
text: The last "Purge old deployment environments" run for ${{github.repository}} failed. See https://github.com/${{github.repository}}/actions/workflows/purge-old-deployment-environments.yml

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
context.payload.repository.full_name === 'github/docs-internal' &&
6363
{ name: 'translations', path: 'tests/translations', },
6464
{ name: 'unit', path: 'tests/unit', },
65+
// { name: 'tools', path: 'src/tools/tests', }
6566
{ name: 'webhooks', path: 'src/webhooks/tests', },
6667
].filter(Boolean)
6768
73.7 KB
Loading
28.4 KB
Loading
79.2 KB
Loading
7.68 KB
Loading
12.3 KB
Loading
10.3 KB
Loading
149 KB
Loading

0 commit comments

Comments
 (0)