Skip to content

Commit 68afe61

Browse files
committed
feat: enhance TOC workflow with reusability and flexibility
1 parent df5be4e commit 68afe61

File tree

3 files changed

+67
-24
lines changed

3 files changed

+67
-24
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: TOC Generator
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
toc-title:
7+
description: 'TOC Title'
8+
required: false
9+
type: string
10+
default: 'Details'
11+
target-paths:
12+
description: 'Target file path. (Comma separated, Detail)'
13+
required: false
14+
type: string
15+
default: 'README*.md'
16+
folding:
17+
description: 'Whether to make TOC foldable'
18+
required: false
19+
type: boolean
20+
default: true
21+
secrets:
22+
BOT_APP_ID:
23+
required: false
24+
BOT_PRIVATE_KEY:
25+
required: false
26+
27+
jobs:
28+
generate-toc:
29+
runs-on: ubuntu-22.04
30+
timeout-minutes: 5
31+
steps:
32+
- name: Check secrets availability
33+
id: check-secrets
34+
run: |
35+
if [ -n "${{ secrets.BOT_APP_ID }}" ] && [ -n "${{ secrets.BOT_PRIVATE_KEY }}" ]; then
36+
echo "available=1" >> "$GITHUB_OUTPUT"
37+
fi
38+
39+
- name: Generate Token
40+
id: app-token
41+
if: ${{ steps.check-secrets.outputs.available == '1' }}
42+
uses: actions/create-github-app-token@v1
43+
with:
44+
app-id: ${{ secrets.BOT_APP_ID }}
45+
private-key: ${{ secrets.BOT_PRIVATE_KEY }}
46+
47+
- uses: technote-space/toc-generator@v4
48+
with:
49+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token || secrets.ACCESS_TOKEN }}
50+
TOC_TITLE: ${{ inputs.toc-title }}
51+
TARGET_PATHS: ${{ inputs.target-paths }}
52+
FOLDING: ${{ inputs.folding }}

.github/workflows/toc-generator.yaml

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: TOC Generator via push
2+
3+
on: push
4+
5+
permissions:
6+
contents: write
7+
8+
jobs:
9+
toc-generator:
10+
uses: IShix-g/Unity-GitHubActions/.github/workflows/reusable-toc-generator.yaml@main
11+
secrets:
12+
BOT_APP_ID: ${{ secrets.BOT_APP_ID }}
13+
BOT_PRIVATE_KEY: ${{ secrets.BOT_PRIVATE_KEY }}
14+
with:
15+
target-paths: 'README*.md,Docs/README*.md'

0 commit comments

Comments
 (0)