Skip to content

Commit 4722906

Browse files
committed
ci: simplify publish-docs workflow
1 parent 284be17 commit 4722906

File tree

2 files changed

+4
-111
lines changed

2 files changed

+4
-111
lines changed

scripts/docs/ci-publish-docs.ts

Lines changed: 4 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { execa } from 'execa'
2-
import glob from 'fast-glob'
32
import { green } from 'kleur/colors'
43
import mri from 'mri'
54
import fs from 'node:fs/promises'
@@ -98,23 +97,11 @@ async function main() {
9897
}
9998
}
10099

101-
/** This is the identifier used by URLs. */
102-
let newReleaseId = 'v' + String(newReleaseMajor)
103-
if (newReleaseParts.length > 3) {
104-
if (newReleaseMajor === lastReleaseMajor) {
105-
newReleaseId += '.' + newReleaseMinor
106-
if (newReleaseMinor === lastReleaseMinor) {
107-
newReleaseId += '.' + newReleaseParts[2]
108-
}
109-
}
110-
newReleaseId += '-' + newReleaseParts[3]
111-
}
112-
113100
if (process.env.DOCS_DEPLOY_KEY) {
114101
await installDeployKey(process.env.DOCS_DEPLOY_KEY)
115102
}
116103

117-
log('Publishing docs for version:', newReleaseId)
104+
log('Publishing docs for version:', newVersion)
118105

119106
log('Cloning main branch of radashi-org.github.io')
120107
await execa(
@@ -169,73 +156,8 @@ async function main() {
169156
log('Symlinking radashi to ./www/radashi')
170157
await fs.symlink('..', './www/radashi')
171158

172-
const removedVersions = new Set<string>()
173-
const cleanVersions = (oldVersions: string[]) =>
174-
oldVersions.filter(oldVersion => {
175-
if (newVersion === oldVersion) {
176-
return true
177-
}
178-
const oldRawVersion = toRawVersion(oldVersion)
179-
if (newVersion === oldRawVersion) {
180-
// Avoid having a beta, RC, or stable with the same raw version.
181-
removedVersions.add(oldVersion)
182-
return false
183-
}
184-
// Beta versions are reserved for non-breaking changes that have
185-
// been merged into the "main" branch and don't have a stable
186-
// version yet.
187-
if (oldVersion.includes('beta')) {
188-
if (newVersion.includes('beta')) {
189-
// Only one beta version is made available at a time.
190-
removedVersions.add(oldVersion)
191-
return false
192-
}
193-
}
194-
// Alpha versions are reserved for breaking changes that have
195-
// been merged into the "next" branch.
196-
else if (oldVersion.includes('alpha')) {
197-
if (newVersion.includes('alpha')) {
198-
// Only one alpha version is made available at a time.
199-
removedVersions.add(oldVersion)
200-
return false
201-
}
202-
}
203-
// Only a stable version should be left to handle.
204-
else {
205-
const oldMajorVersion = +oldRawVersion.split('.')[0]
206-
if (newReleaseMajor - oldMajorVersion > 2) {
207-
// Only 3 major versions are made available at a time.
208-
removedVersions.add(oldVersion)
209-
return false
210-
}
211-
}
212-
return true
213-
})
214-
215-
log('Updating ./www/public/versions.json')
216-
const versions = new Set(
217-
cleanVersions(
218-
JSON.parse(await fs.readFile('./www/public/versions.json', 'utf8')),
219-
),
220-
)
221-
versions.add(newReleaseId)
222-
await fs.writeFile(
223-
'./www/public/versions.json',
224-
JSON.stringify([...versions]),
225-
)
226-
227-
if (removedVersions.size > 0) {
228-
log('Removing docs for unmaintained versions')
229-
for (const removedVersion of removedVersions) {
230-
await fs.rm(`./www/dist/${removedVersion}`, { recursive: true })
231-
}
232-
}
233-
234-
log('Removing docs that will be overwritten')
235-
await fs.rm(`./www/dist/${newReleaseId}`, { recursive: true }).catch(() => {})
236-
237-
log('Building docs with version-specific --outDir')
238-
await execa('pnpm', ['build', '--outDir', `./dist/${newReleaseId}`], {
159+
log('Building docs')
160+
await execa('pnpm', ['build'], {
239161
cwd: './www',
240162
stdio: 'inherit',
241163
extendEnv: false,
@@ -249,15 +171,6 @@ async function main() {
249171
},
250172
}).catch(exit)
251173

252-
if (newReleaseParts.length === 3) {
253-
log('Copying build into root folder')
254-
const cwd = `www/dist/${newReleaseId}`
255-
const files = await glob('**/*', { cwd })
256-
for (const file of files) {
257-
await fs.cp(`${cwd}/${file}`, `www/dist/${file}`)
258-
}
259-
}
260-
261174
// Set up git user in CI environment
262175
if (process.env.CI) {
263176
if (process.env.GITHUB_ACTOR) {
@@ -283,7 +196,7 @@ async function main() {
283196

284197
log('Pushing to gh-pages branch')
285198
await execa('git', ['add', '-A'], { cwd: './www/dist' })
286-
await execa('git', ['commit', '-m', `chore: ${newReleaseId}`], {
199+
await execa('git', ['commit', '-m', `chore: ${newVersion}`], {
287200
cwd: './www/dist',
288201
stdio: 'inherit',
289202
})
@@ -301,25 +214,6 @@ function exit() {
301214
process.exit(1)
302215
}
303216

304-
/**
305-
* Extracts the raw version from a version string that may not have
306-
* its minor or patch version set. It also removes any suffix like
307-
* "-rc" or "-beta".
308-
*
309-
* @example
310-
* ```ts
311-
* toRawVersion('1') // '1.0.0'
312-
* toRawVersion('1.1.0-rc') // '1.1.0'
313-
* ```
314-
*/
315-
function toRawVersion(version: string) {
316-
let [, rawVersion] = version.match(/^v?(\d+(?:\.\d+(?:\.\d+)?)?)/)!
317-
for (let i = rawVersion.split('.').length; i < 3; i++) {
318-
rawVersion += '.0'
319-
}
320-
return rawVersion
321-
}
322-
323217
async function coerceTagToVersion(tag: string) {
324218
let version: string
325219
let metaId: string

scripts/docs/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"dependencies": {
55
"@types/node": "^22.3.0",
66
"execa": "^9.3.1",
7-
"fast-glob": "^3.3.2",
87
"git-cliff": "2.4.0",
98
"kleur": "^4.1.5",
109
"mri": "^1.2.0",

0 commit comments

Comments
 (0)