Skip to content

Commit 0bc4307

Browse files
heiskrCopilot
andauthored
Improve the GHES deprecation runbook and tooling (#61619)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 02ed657 commit 0bc4307

8 files changed

Lines changed: 258 additions & 236 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"deleted-assets-pr-comment": "tsx src/assets/scripts/deleted-assets-pr-comment.ts",
3636
"deleted-features-pr-comment": "tsx src/data-directory/scripts/deleted-features-pr-comment.ts",
3737
"deprecate-ghes": "tsx src/ghes-releases/scripts/deprecate/index.ts",
38-
"deprecate-ghes-archive": "cross-env NODE_OPTIONS=--max-old-space-size=16384 tsx src/ghes-releases/scripts/deprecate/archive-version.ts",
38+
"deprecate-ghes-archive": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=16384 tsx src/ghes-releases/scripts/deprecate/archive-version.ts",
3939
"dev": "cross-env npm start",
4040
"dev-toc": "tsx src/dev-toc/generate.ts",
4141
"enable-automerge": "tsx src/workflows/enable-automerge.ts",

src/ghes-releases/lib/deprecation-steps.md

Lines changed: 151 additions & 223 deletions
Large diffs are not rendered by default.
-322 KB
Binary file not shown.

src/ghes-releases/scripts/create-enterprise-issue.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ async function createDeprecationIssue() {
103103
const issueTemplate = readFileSync('src/ghes-releases/lib/deprecation-steps.md', 'utf8')
104104
const { data, content } = matter(issueTemplate)
105105
const { title, labels } = data
106+
const renderedContent = content.replaceAll('{{ release-number }}', oldestSupported)
106107
const body = `GHES ${oldestSupported} deprecation occurs on ${deprecationDate}.
107-
\n${content}
108-
'/cc @github/docs-engineering'`
108+
109+
${renderedContent}`
109110
await createIssue(
110111
repo,
111-
title.replace('{{ release-number }}', oldestSupported),
112+
title.replaceAll('{{ release-number }}', oldestSupported),
112113
body,
113114
labels,
114115
oldestSupported,

src/ghes-releases/scripts/deprecate/archive-version.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ async function main() {
112112
} catch (err) {
113113
console.error('scraping error')
114114
console.error(err)
115+
server.close(() => process.exit(1))
116+
return
115117
}
116118

117119
fs.renameSync(
@@ -127,11 +129,11 @@ async function main() {
127129
} else {
128130
console.log('🏁 Scraping a single page is complete')
129131
}
130-
server.close()
132+
server.close(() => process.exit(0))
131133
})
132134
.on('error', (err) => {
133135
console.log('error listening to port ', port, err)
134-
server.close()
136+
server.close(() => process.exit(1))
135137
})
136138
}
137139

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import fs from 'fs'
2+
import { execSync } from 'child_process'
3+
4+
// Removing deprecated Liquid conditionals leaves behind extra blank lines.
5+
// The content team flags these every deprecation, and the MD012 linter rule
6+
// is off so nothing catches them automatically. This collapses any run of
7+
// two or more consecutive blank lines down to one, but only in the markdown
8+
// files the deprecation actually changed. Single blank lines are left alone:
9+
// removed Liquid can introduce one in a place where it doesn't belong, so a
10+
// human still reviews each removal site one at a time.
11+
12+
function getChangedMarkdownFiles(): string[] {
13+
const commands = [
14+
'git diff --name-only HEAD',
15+
'git diff --name-only --cached',
16+
'git diff --name-only origin/main...HEAD',
17+
]
18+
const files = new Set<string>()
19+
for (const command of commands) {
20+
let output = ''
21+
try {
22+
output = execSync(command, { encoding: 'utf8' })
23+
} catch {
24+
// origin/main may not be fetched locally; skip that source.
25+
continue
26+
}
27+
for (const line of output.split('\n')) {
28+
const file = line.trim()
29+
if (!file) continue
30+
if (!file.endsWith('.md')) continue
31+
if (!file.startsWith('content/') && !file.startsWith('data/')) continue
32+
if (fs.existsSync(file)) files.add(file)
33+
}
34+
}
35+
return [...files].sort()
36+
}
37+
38+
// Collapses any run of 2+ blank lines into a single blank line.
39+
function collapse(contents: string): string {
40+
const lines = contents.split('\n')
41+
const result: string[] = []
42+
let blankRun = 0
43+
for (const line of lines) {
44+
if (line.trim() === '') {
45+
blankRun += 1
46+
if (blankRun <= 1) result.push('')
47+
} else {
48+
blankRun = 0
49+
result.push(line)
50+
}
51+
}
52+
return result.join('\n')
53+
}
54+
55+
export function collapseBlankLines(options: { check?: boolean } = {}) {
56+
const files = getChangedMarkdownFiles()
57+
const offenders: string[] = []
58+
59+
for (const file of files) {
60+
const contents = fs.readFileSync(file, 'utf8')
61+
const collapsed = collapse(contents)
62+
if (collapsed === contents) continue
63+
offenders.push(file)
64+
if (!options.check) {
65+
fs.writeFileSync(file, collapsed)
66+
console.log('Collapsed blank lines in: ', file)
67+
}
68+
}
69+
70+
if (options.check) {
71+
if (offenders.length) {
72+
console.error('Found 2+ consecutive blank lines in:')
73+
for (const file of offenders) console.error(` ${file}`)
74+
console.error('Run `npm run deprecate-ghes -- collapse-blank-lines` to fix.')
75+
process.exit(1)
76+
}
77+
console.log('No double blank lines found in changed markdown files.')
78+
return
79+
}
80+
81+
if (!offenders.length) {
82+
console.log('No double blank lines found in changed markdown files.')
83+
}
84+
}

src/ghes-releases/scripts/deprecate/create-docs-ghes-version-repo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ mutation($repositoryId:ID!,$branch:String!,$requiredReviews:Int!) {
4646
}' -f repositoryId="$repositoryId" -f branch=main -F requiredReviews=1 --silent
4747
echo "--- Enable GitHub Pages, set source to main in root directory, and make the pages site public"
4848
gh api -X POST "/repos/github/docs-ghes-$version/pages" \
49-
-f "source[branch]=main" -f "source[path]=/" -f "public=true" --silent
49+
-f "source[branch]=main" -f "source[path]=/" -F "public=true" --silent
5050
echo "--- Update custom properties"
5151
gh api --method PATCH /repos/github/docs-ghes-$version/properties/values \
5252
-f "properties[][property_name]=ownership-name" \

src/ghes-releases/scripts/deprecate/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,38 @@ import { execSync } from 'child_process'
33
import { updateContentFiles } from '@/ghes-releases/scripts/deprecate/update-content'
44
import { updateDataFiles } from '@/ghes-releases/scripts/deprecate/update-data'
55
import { updateAutomatedConfigFiles } from '@/ghes-releases/scripts/deprecate/update-automated-pipelines'
6-
7-
program.option('-f, --foo', 'enable some foo')
6+
import { collapseBlankLines } from '@/ghes-releases/scripts/deprecate/collapse-blank-lines'
87

98
program
10-
.description('Update deprecated versions frontmatter and remove deprecated content files.')
119
.command('content')
10+
.description('Update deprecated versions frontmatter and remove deprecated content files.')
1211
.action(updateContentFiles)
1312

1413
program
14+
.command('data')
1515
.description(
1616
'Update deprecated versions in data files, remove empty data files, and remove deleted reusables from content files.',
1717
)
18-
.command('data')
1918
.action(updateDataFiles)
2019

2120
program
21+
.command('pipelines')
2222
.description(
2323
'Removes automated pipeline data files and updates the automated pipeline config files.',
2424
)
25-
.command('pipelines')
2625
.action(updateAutomatedConfigFiles)
2726

2827
program
28+
.command('collapse-blank-lines')
29+
.description(
30+
'Collapse 2+ consecutive blank lines left by removed Liquid into one, in changed markdown files only. Pass --check to report without writing.',
31+
)
32+
.option('--check', 'Report files with double blank lines and exit non-zero instead of fixing.')
33+
.action((options) => collapseBlankLines({ check: options.check }))
34+
35+
program
36+
.command('create-repo')
2937
.description('Create new `github/docs-ghes-<RELEASE>` repository.')
30-
.command('repo')
3138
.option('-v, --version <version>', 'The GHES version to create the repo for.')
3239
.action((options) => {
3340
if (!options.version) {

0 commit comments

Comments
 (0)