Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit 1c5e78f

Browse files
authored
Generate docs and push to gh-pages automatically (#3443)
* Generate docs and push to gh-pages * Move to workflows * Fix workflow * Add support for unreleased linter versions * Keep preexisting files
1 parent 9cbc24e commit 1c5e78f

File tree

2 files changed

+79
-11
lines changed

2 files changed

+79
-11
lines changed

.github/workflows/gh-pages.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Deploy to GitHub Pages
2+
3+
# Declare default permissions as read only.
4+
permissions: read-all
5+
6+
on:
7+
push:
8+
branches:
9+
- master
10+
jobs:
11+
build-and-deploy-docs:
12+
permissions:
13+
contents: write
14+
runs-on: ubuntu-latest
15+
if: github.repository == 'dart-lang/linter'
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@d171c3b028d844f2bf14e9fdec0c58114451e4bf
20+
- name: Setup Dart
21+
uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d
22+
with:
23+
sdk: stable
24+
- name: Get dependencies
25+
run: dart pub get
26+
- name: Generate docs
27+
run: dart run tool/doc.dart --create-dirs --no-markdown --out lints --token ${{ secrets.GITHUB_TOKEN }}
28+
- name: Deploy docs
29+
uses: peaceiris/actions-gh-pages@068dc23d9710f1ba62e86896f84735d869951305
30+
with:
31+
github_token: ${{ secrets.GITHUB_TOKEN }}
32+
publish_branch: gh-pages
33+
publish_dir: lints
34+
destination_dir: lints
35+
keep_files: true

tool/doc.dart

+44-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ import 'since.dart';
2121
void main(List<String> args) async {
2222
var parser = ArgParser()
2323
..addOption('out', abbr: 'o', help: 'Specifies output directory.')
24-
..addOption('token', abbr: 't', help: 'Specifies a github auth token.');
24+
..addOption('token', abbr: 't', help: 'Specifies a github auth token.')
25+
..addFlag('create-dirs',
26+
abbr: 'd', help: 'Enables creation of necessary directories.')
27+
..addFlag('markdown',
28+
abbr: 'm',
29+
help: 'Enables generation of the markdown docs.',
30+
defaultsTo: true);
2531

2632
ArgResults options;
2733
try {
@@ -36,7 +42,14 @@ void main(List<String> args) async {
3642
var token = options['token'];
3743
var auth = token is String ? Authentication.withToken(token) : null;
3844

39-
await generateDocs(outDir, auth: auth);
45+
var createDirectories = options['create-dirs'] == true;
46+
47+
var enableMarkdown = options['markdown'] == true;
48+
49+
await generateDocs(outDir,
50+
auth: auth,
51+
createDirectories: createDirectories,
52+
enableMarkdown: enableMarkdown);
4053
}
4154

4255
const ruleFootMatter = '''
@@ -155,20 +168,33 @@ Future<void> fetchSinceInfo(Authentication? auth) async {
155168
sinceInfo = await getSinceMap(auth);
156169
}
157170

158-
Future<void> generateDocs(String? dir, {Authentication? auth}) async {
171+
Future<void> generateDocs(String? dir,
172+
{Authentication? auth,
173+
bool createDirectories = false,
174+
bool enableMarkdown = true}) async {
159175
var outDir = dir;
160176
if (outDir != null) {
161177
var d = Directory(outDir);
178+
if (createDirectories) {
179+
d.createSync();
180+
}
181+
162182
if (!d.existsSync()) {
163183
print("Directory '${d.path}' does not exist");
164184
return;
165185
}
186+
166187
if (!File('$outDir/options').existsSync()) {
167188
var lintsChildDir = Directory('$outDir/lints');
168189
if (lintsChildDir.existsSync()) {
169190
outDir = lintsChildDir.path;
170191
}
171192
}
193+
194+
if (createDirectories) {
195+
Directory('$outDir/options').createSync();
196+
Directory('$outDir/machine').createSync();
197+
}
172198
}
173199

174200
registerLintRules();
@@ -185,12 +211,17 @@ Future<void> generateDocs(String? dir, {Authentication? auth}) async {
185211
// Generate rule files.
186212
for (var l in rules) {
187213
RuleHtmlGenerator(l).generate(outDir);
188-
RuleMarkdownGenerator(l).generate(filePath: outDir);
214+
if (enableMarkdown) {
215+
RuleMarkdownGenerator(l).generate(filePath: outDir);
216+
}
189217
}
190218

191219
// Generate index.
192220
HtmlIndexer(Registry.ruleRegistry).generate(outDir);
193-
MarkdownIndexer(Registry.ruleRegistry).generate(filePath: outDir);
221+
222+
if (enableMarkdown) {
223+
MarkdownIndexer(Registry.ruleRegistry).generate(filePath: outDir);
224+
}
194225

195226
// Generate options samples.
196227
OptionsSample(rules).generate(outDir);
@@ -562,13 +593,14 @@ class RuleHtmlGenerator {
562593
String get name => rule.name;
563594

564595
String get since {
565-
var info = sinceInfo[name]!;
566596
// See: https://github.com/dart-lang/linter/issues/2824
597+
// var info = sinceInfo[name]!;
567598
// var version = info.sinceDartSdk != null
568599
// ? '>= ${info.sinceDartSdk}'
569600
// : '<strong>unreleased</strong>';
570601
//return 'Dart SDK: $version • <small>(Linter v${info.sinceLinter})</small>';
571-
return 'Linter v${info.sinceLinter}';
602+
var sinceLinter = sinceInfo[name]!.sinceLinter;
603+
return sinceLinter != null ? 'Linter v$sinceLinter' : 'Unreleased';
572604
}
573605

574606
void generate([String? filePath]) {
@@ -641,13 +673,14 @@ class RuleMarkdownGenerator {
641673
String get name => rule.name;
642674

643675
String get since {
644-
var info = sinceInfo[name]!;
645676
// See: https://github.com/dart-lang/linter/issues/2824
677+
// var info = sinceInfo[name]!;
646678
// var version = info.sinceDartSdk != null
647679
// ? '>= ${info.sinceDartSdk}'
648-
// : '**unreleased**';
649-
// return 'Dart SDK: $version • (Linter v${info.sinceLinter})';
650-
return 'Linter v${info.sinceLinter}';
680+
// : '<strong>unreleased</strong>';
681+
//return 'Dart SDK: $version • <small>(Linter v${info.sinceLinter})</small>';
682+
var sinceLinter = sinceInfo[name]!.sinceLinter;
683+
return sinceLinter != null ? 'Linter v$sinceLinter' : 'Unreleased';
651684
}
652685

653686
void generate({String? filePath}) {

0 commit comments

Comments
 (0)