Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps-dev): bump js-yaml and @types/js-yaml #18

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions misc/generate-docs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fs from 'fs';
import * as fs from 'fs/promises';
import * as os from 'os';
import * as path from 'path';
import * as yaml from 'js-yaml';
Expand Down Expand Up @@ -36,19 +36,25 @@ import { version } from '../package.json';
//
// This script rebuilds the usage section in the README.md to be consistent with the action.yml

function updateUsage(
async function updateUsage(
actionReference: string,
actionYamlPath = 'action.yml',
readmePath = 'README.md',
startToken = '<!-- start usage -->',
endToken = '<!-- end usage -->'
): void {
): Promise<void> {
if (!actionReference) {
throw new Error('Parameter actionReference must not be empty');
}

// Load the action.yml
const actionYaml = yaml.safeLoad(fs.readFileSync(actionYamlPath).toString()) as {
// load files
const [action, readme] = await Promise.all([
fs.readFile(actionYamlPath).then((f) => f.toString()),
fs.readFile(readmePath).then((f) => f.toString()),
]);

// parse the action.yml
const actionYaml = yaml.load(action) as {
inputs: Record<string, {
description: string;
default?: string;
Expand All @@ -58,17 +64,14 @@ function updateUsage(
}>;
};

// Load the README
const originalReadme = fs.readFileSync(readmePath).toString();

// Find the start token
const startTokenIndex = originalReadme.indexOf(startToken);
const startTokenIndex = readme.indexOf(startToken);
if (startTokenIndex < 0) {
throw new Error(`Start token '${startToken}' not found`);
}

// Find the end token
const endTokenIndex = originalReadme.indexOf(endToken);
const endTokenIndex = readme.indexOf(endToken);
if (endTokenIndex < 0) {
throw new Error(`End token '${endToken}' not found`);
} else if (endTokenIndex < startTokenIndex) {
Expand All @@ -79,7 +82,7 @@ function updateUsage(
const newReadme: string[] = [];

// Append the beginning
newReadme.push(originalReadme.substr(0, startTokenIndex + startToken.length));
newReadme.push(readme.substring(0, startTokenIndex + startToken.length));

// Build the new usage section
newReadme.push('```yaml', `- uses: ${actionReference}`, ' with:');
Expand Down Expand Up @@ -158,10 +161,10 @@ function updateUsage(
newReadme.push('```');

// Append the end
newReadme.push(originalReadme.substr(endTokenIndex));
newReadme.push(readme.substr(endTokenIndex));

// Write the new README
fs.writeFileSync(readmePath, newReadme.join(os.EOL));
await fs.writeFile(readmePath, newReadme.join(os.EOL));
}

updateUsage(
Expand Down
141 changes: 37 additions & 104 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@semantic-release/release-notes-generator": "^14.0.1",
"@tsconfig/node20": "^20.1.4",
"@types/chai": "^4.3.5",
"@types/js-yaml": "^3.12.7",
"@types/js-yaml": "^4.0.9",
"@types/mocha": "^10.0.7",
"@types/node": "^20.14.14",
"@types/sinon": "^17.0.3",
Expand All @@ -45,7 +45,7 @@
"@vercel/ncc": "^0.38.1",
"chai": "^4.5.0",
"eslint": "^8.47.0",
"js-yaml": "^3.14.1",
"js-yaml": "^4.1.0",
"mocha": "^10.7.0",
"nyc": "^17.0.0",
"sinon": "^18.0.0",
Expand Down
Loading