Skip to content

Commit

Permalink
Merge pull request #4952 from material-components:auto-pr-docs-action
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 566852780
  • Loading branch information
copybara-github committed Sep 20, 2023
2 parents 9f3e55d + a8f20c7 commit e1a04a1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 7 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/update-docs-on-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Update API Docs

on:
push:
branches: main
workflow_dispatch:
# allows triggering from the gihub UI
jobs:
check-for-doc-changes:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
cache: npm
- uses: google/wireit@setup-github-actions-caching/v1

- name: Install Dependencies
run: npm ci

- name: Update Docs
run: npm run update-docs

- name: Check if update-docs produces git diff
id: ifChange
run: git diff --exit-code || echo "::set-output name=changed::yes"

- name: Create PR
if: steps.ifChange.outputs.changed == 'yes'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.LIT_ROBOT_ACCESS_TOKEN }}
commit-message: 'docs: update API docs'
author: lit-robot <[email protected]>
committer: lit-robot <[email protected]>
title: 'docs: update API docs'
body: This PR was auto generated by the update-docs-on-main GitHub action.
reviewers: e111077,asyncliz,AndrewJakubowicz
branch: auto-update-docs
labels: |
Ready for Google
preview-catalog
30 changes: 30 additions & 0 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"dependencies": ["./catalog:build:prod"]
},
"build:analyzer": {
"command": "tsc -b scripts/analyzer/tsconfig.json --pretty",
"command": "tsc -b scripts/tsconfig.json --pretty",
"files": [
"scripts/tsconfig.json",
"scripts/analyzer/**/*.ts",
Expand Down
10 changes: 4 additions & 6 deletions scripts/analyzer/update-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
*/

import {AbsolutePath, Analyzer, createPackageAnalyzer,} from '@lit-labs/analyzer/package-analyzer.js';
import * as fs from 'fs/promises.js';
import * as fs from 'fs/promises';
import * as path from 'path';

import {analyzeElementApi, MdModuleInfo, MdPropertyInfo,} from './analyze-element.js';
import {analyzeElementApi, MdMethodParameterInfo, MdModuleInfo, MdPropertyInfo,} from './analyze-element.js';
import {docsToElementMapping} from './element-docs-map.js';
import {MarkdownTable} from './markdown-tree-builder.js';

type DocFileName = keyof typeof docsToElementMapping;

interface MarkdownTableSection {
name: string;
table: MarkdownTable;
Expand All @@ -40,7 +38,7 @@ async function updateApiDocs() {
// Analyzes the entire material-web repository.
const analyzer = createPackageAnalyzer(packagePath as AbsolutePath);
const documentationFileNames =
Object.keys(docsToElementMapping) as DocFileName[];
Object.keys(docsToElementMapping);

const filesWritten: Array<Promise<void>> = [];

Expand All @@ -66,7 +64,7 @@ async function updateApiDocs() {
* @returns A promise that resolves when the file has been updated.
*/
async function updateDocFileApiSection(
docFileName: DocFileName, analyzer: Analyzer, packagePath: string) {
docFileName: string, analyzer: Analyzer, packagePath: string) {
const elementEntrypoints = docsToElementMapping[docFileName];
// This is a data structure that describes an element and its associated API
// tables. e.g. a single section for MdFilledButton represents MdFilledButton
Expand Down

0 comments on commit e1a04a1

Please sign in to comment.