Skip to content

Commit

Permalink
feat: Build for release
Browse files Browse the repository at this point in the history
  • Loading branch information
technote-space committed Sep 10, 2019
1 parent 9ea0db7 commit 8590b01
Show file tree
Hide file tree
Showing 25 changed files with 700 additions and 577 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![CodeFactor](https://www.codefactor.io/repository/github/technote-space/toc-generator/badge)](https://www.codefactor.io/repository/github/technote-space/toc-generator)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/technote-space/toc-generator/blob/master/LICENSE)

GitHub Action to generate TOC.
GitHub Action to generate TOC (Table of Contents).
Just run [DocToc](https://github.com/thlorenz/doctoc) and commit to branch if changed.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
Expand All @@ -14,6 +14,7 @@ Just run [DocToc](https://github.com/thlorenz/doctoc) and commit to branch if ch

- [Screenshot](#screenshot)
- [Installation](#installation)
- [For private repository](#for-private-repository)
- [Options](#options)
- [TARGET_PATHS](#target_paths)
- [TOC_TITLE](#toc_title)
Expand Down Expand Up @@ -48,6 +49,24 @@ Just run [DocToc](https://github.com/thlorenz/doctoc) and commit to branch if ch
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
### For private repository
Use [actions/checkout](https://github.com/actions/checkout) to checkout before TOC Generator step.
e.g. `.github/workflows/toc.yml`
```yaml
on: push
name: TOC Generator
jobs:
assignAuthor:
name: TOC Generator
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: TOC Generator
uses: technote-space/toc-generator@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

## Options
### TARGET_PATHS
Target file path. (Comma separated, [Detail](https://github.com/thlorenz/doctoc#adding-toc-to-individual-files))
Expand Down
2 changes: 1 addition & 1 deletion build.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"tagName":"v1.1.0","branch":"gh-actions","tags":["v1.1.0","v1","v1.1"],"updated_at":"2019-08-31T06:02:05.442Z"}
{"tagName":"v1.2.0","branch":"gh-actions","tags":["v1.2.0","v1","v1.2"],"updated_at":"2019-09-10T08:22:19.757Z"}
7 changes: 7 additions & 0 deletions lib/utils/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ exports.getChangedFiles = (context) => __awaiter(void 0, void 0, void 0, functio
return getDiff(workDir);
});
const clone = (workDir, context) => __awaiter(void 0, void 0, void 0, function* () {
if (misc_1.isCloned()) {
return true;
}
const branch = misc_1.getBranch(context);
const url = misc_1.getGitUrl(context);
yield execAsync(`git -C ${workDir} clone --quiet --branch=${branch} --depth=1 ${url} .`, false, null, true);
Expand All @@ -47,6 +50,10 @@ const getCurrentBranchName = (workDir) => __awaiter(void 0, void 0, void 0, func
});
const runDocToc = (workDir) => __awaiter(void 0, void 0, void 0, function* () {
const args = misc_1.getDocTocArgs();
if (false === args) {
signale_1.default.warn('There is no valid target. Please check if [TARGET_PATHS] is set correctly.');
return false;
}
const doctoc = path_1.default.resolve(workDir, 'node_modules/.bin/doctoc');
yield execAsync(`yarn --cwd ${workDir} add doctoc`, false, null, false, true);
yield execAsync(`${doctoc} ${args} --github`);
Expand Down
7 changes: 6 additions & 1 deletion lib/utils/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ const getTargetPaths = () => [...new Set((core_1.getInput('TARGET_PATHS') || con
exports.getDocTocArgs = () => {
const workDir = exports.getWorkDir();
const title = getTocTitle().replace('\'', '\\\'').replace('"', '\\"');
const paths = getTargetPaths();
if (!paths.length) {
return false;
}
return getTargetPaths().map(item => path_1.default.resolve(workDir, item)).join(' ') + (title ? ` --title '${title}'` : ' --notitle');
};
const getTocTitle = () => core_1.getInput('TOC_TITLE') || '';
const getWorkspace = () => process.env.GITHUB_WORKSPACE || '';
exports.getWorkDir = () => path_1.default.resolve(getWorkspace(), '.work');
exports.isCloned = () => fs_1.default.existsSync(path_1.default.resolve(getWorkspace(), '.git'));
exports.getWorkDir = () => exports.isCloned() ? path_1.default.resolve(getWorkspace()) : path_1.default.resolve(getWorkspace(), '.work');
exports.getGitUrl = (context) => `https://github.com/${context.repo.owner}/${context.repo.repo}.git`;
exports.getRef = (context) => context.ref;
exports.getRefForUpdate = (context) => encodeURIComponent(exports.getRef(context).replace(/^refs\//, ''));
Expand Down
25 changes: 9 additions & 16 deletions node_modules/.yarn-integrity

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

12 changes: 6 additions & 6 deletions node_modules/@actions/core/LICENSE.md

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

Loading

0 comments on commit 8590b01

Please sign in to comment.