ci: Upload README.md files (#11342)

* feat: upload README.md files

* ci: build actions

* fix: build action

* chore: force rename
This commit is contained in:
Jiralite
2025-12-09 02:22:39 +00:00
committed by GitHub
parent ec3ef7b1bd
commit 2c3bf5c817
4 changed files with 107 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
name: 'Upload README.md files'
description: 'Uploads the README.md files for packages that have api-extractor.json to the website.'
runs:
using: node24
main: ../../dist/uploadReadmeFiles/index.js

View File

@@ -0,0 +1,59 @@
import { readFile } from 'node:fs/promises';
import process from 'node:process';
import { info, setFailed } from '@actions/core';
import { create } from '@actions/glob';
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
if (
!process.env.CF_R2_READMES_ACCESS_KEY_ID ||
!process.env.CF_R2_READMES_SECRET_ACCESS_KEY ||
!process.env.CF_R2_READMES_BUCKET ||
!process.env.CF_R2_READMES_URL
) {
setFailed('Missing environment variables.');
process.exit(1);
}
const S3READMEFiles = new S3Client({
region: 'auto',
endpoint: process.env.CF_R2_READMES_URL,
credentials: {
accessKeyId: process.env.CF_R2_READMES_ACCESS_KEY_ID,
secretAccessKey: process.env.CF_R2_READMES_SECRET_ACCESS_KEY,
},
requestChecksumCalculation: 'WHEN_REQUIRED',
responseChecksumValidation: 'WHEN_REQUIRED',
});
const promises = [];
// Find all packages with an api-extractor.json file.
const globber = await create('packages/*/api-extractor.json');
for await (const apiExtractorFile of globber.globGenerator()) {
const readmePath = apiExtractorFile.replace('/api-extractor.json', '/README.md');
const packageName = apiExtractorFile.split('/').at(-2)!;
const readmeKey = `${packageName}/home-README.md`;
info(`Uploading ${readmePath}...`);
promises.push(
// eslint-disable-next-line promise/prefer-await-to-then
readFile(readmePath, 'utf8').then(async (readmeData) =>
S3READMEFiles.send(
new PutObjectCommand({
Bucket: process.env.CF_R2_READMES_BUCKET,
Key: readmeKey,
Body: readmeData,
}),
),
),
);
}
try {
await Promise.all(promises);
info('All README.md files uploaded successfully!');
} catch (error) {
setFailed(`Failed to upload README files: ${error}`);
process.exit(1);
}

View File

@@ -6,6 +6,7 @@ export default createTsupConfig({
'src/formatTag/index.ts',
'src/releasePackages/index.ts',
'src/uploadDocumentation/index.ts',
'src/uploadReadmeFiles/index.ts',
'src/uploadSearchIndices/index.ts',
'src/uploadSplitDocumentation/index.ts',
],