Skip to content

Commit a3b8a8c

Browse files
committed
Add caching for Telegraph mappings in workflows and README. Update documentation for caching strategy and one-entry mode features.
1 parent 98537dd commit a3b8a8c

File tree

2 files changed

+98
-22
lines changed

2 files changed

+98
-22
lines changed

.github/workflows/example.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ jobs:
1919
- name: Checkout repository
2020
uses: actions/checkout@v4
2121

22+
- name: Cache Telegraph mappings
23+
uses: actions/cache@v3
24+
with:
25+
path: telegraph-pages.json
26+
key: telegraph-mappings-${{ hashFiles('docs/**/*.md', 'README.md') }}
27+
restore-keys: |
28+
telegraph-mappings-
29+
2230
- name: Convert markdown to Telegraph
2331
uses: cyanxiao/md-to-telegraph-action@release
2432
with:
@@ -33,11 +41,3 @@ jobs:
3341
replace-existing-pages: "true"
3442
env:
3543
GITHUB_TOKEN: ${{ secrets.REPO_LINK_TOKEN }}
36-
37-
- name: Commit updated mappings
38-
run: |
39-
git config --local user.email "[email protected]"
40-
git config --local user.name "GitHub Action"
41-
git add telegraph-pages.json
42-
git diff --staged --quiet || git commit -m "Update Telegraph page mappings"
43-
git push

README.md

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ jobs:
3434
- name: Checkout repository
3535
uses: actions/checkout@v4
3636

37+
- name: Cache Telegraph mappings
38+
uses: actions/cache@v3
39+
with:
40+
path: telegraph-pages.json
41+
key: telegraph-mappings-${{ hashFiles('docs/**/*.md', 'README.md') }}
42+
restore-keys: |
43+
telegraph-mappings-
44+
3745
- name: Convert markdown to Telegraph
3846
uses: cyanxiao/md-to-telegraph-action@release
3947
with:
@@ -54,6 +62,14 @@ jobs:
5462
- name: Checkout repository
5563
uses: actions/checkout@v4
5664

65+
- name: Cache Telegraph mappings
66+
uses: actions/cache@v3
67+
with:
68+
path: my-telegraph-pages.json
69+
key: telegraph-mappings-${{ hashFiles('docs/**/*.md', 'guides/**/*.md', 'README.md') }}
70+
restore-keys: |
71+
telegraph-mappings-
72+
5773
- name: Convert markdown to Telegraph
5874
uses: cyanxiao/md-to-telegraph-action@release
5975
with:
@@ -68,14 +84,6 @@ jobs:
6884
replace-existing-pages: "true"
6985
env:
7086
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71-
72-
- name: Commit updated mappings
73-
run: |
74-
git config --local user.email "[email protected]"
75-
git config --local user.name "GitHub Action"
76-
git add my-telegraph-pages.json
77-
git diff --staged --quiet || git commit -m "Update Telegraph page mappings"
78-
git push
7987
```
8088
8189
## Inputs
@@ -103,16 +111,24 @@ jobs:
103111

104112
When enabled with `one-entry-mode: "true"`, this feature automatically updates your repository description with the Telegraph URL when exactly one markdown file is processed. This is perfect for single-page documentation repositories, personal profiles, or project showcases.
105113
106-
### How it works
114+
### How One Entry Mode Works
107115
108116
1. **Enable the feature**: Set `one-entry-mode: "true"` in your workflow
109117
2. **Single page detection**: When exactly one markdown file is processed, the action detects this scenario
110118
3. **Repository update**: The GitHub repository description is automatically updated with the Telegraph page URL
111119
4. **Permission handling**: Gracefully handles cases where the GitHub token lacks repository write permissions
112120

113-
### Example
121+
### One Entry Mode Example
114122

115123
```yaml
124+
- name: Cache Telegraph mappings
125+
uses: actions/cache@v3
126+
with:
127+
path: telegraph-pages.json
128+
key: telegraph-mappings-${{ hashFiles('README.md') }}
129+
restore-keys: |
130+
telegraph-mappings-
131+
116132
- name: Convert README to Telegraph
117133
uses: cyanxiao/md-to-telegraph-action@release
118134
with:
@@ -126,7 +142,7 @@ When enabled with `one-entry-mode: "true"`, this feature automatically updates y
126142

127143
**Result**: If only `README.md` is processed, your repository description will be automatically updated to point to the Telegraph page (e.g., `https://telegra.ph/My-Profile-12-15`).
128144

129-
### Requirements
145+
### One Entry Mode Requirements
130146

131147
- **GITHUB_TOKEN**: Must be provided via `env` for repository description updates
132148
- The GitHub token must have `metadata: write` or `contents: write` permissions
@@ -137,17 +153,25 @@ When enabled with `one-entry-mode: "true"`, this feature automatically updates y
137153

138154
When enabled with `replace-existing-pages: "true"`, this feature prevents the creation of duplicate Telegraph pages by reusing existing pages with the same title. This is perfect for documentation that gets updated regularly, as it maintains consistent URLs for bookmarks and external links.
139155
140-
### How it works
156+
### How Page Replacement Works
141157
142158
1. **Enable the feature**: Set `replace-existing-pages: "true"` in your workflow
143159
2. **Provide consistent token**: A `telegraph-token` is **required** for this feature to work
144160
3. **Title matching**: The action searches for existing pages with matching titles
145161
4. **Content replacement**: If a match is found, the existing page content is replaced
146162
5. **URL preservation**: The Telegraph page URL remains the same (e.g., `https://telegra.ph/My-Guide-12-15`)
147163

148-
### Example
164+
### Page Replacement Example
149165

150166
```yaml
167+
- name: Cache Telegraph mappings
168+
uses: actions/cache@v3
169+
with:
170+
path: telegraph-pages.json
171+
key: telegraph-mappings-${{ hashFiles('docs/**/*.md') }}
172+
restore-keys: |
173+
telegraph-mappings-
174+
151175
- name: Update Documentation
152176
uses: cyanxiao/md-to-telegraph-action@release
153177
with:
@@ -162,7 +186,7 @@ When enabled with `replace-existing-pages: "true"`, this feature prevents the cr
162186

163187
**Result**: Each time the action runs, it will update the existing Telegraph pages instead of creating new ones, preserving URLs and preventing duplicates.
164188

165-
### Requirements
189+
### Page Replacement Requirements
166190

167191
- **Telegraph token is mandatory**: This feature requires a consistent `telegraph-token` to access your existing pages
168192
- **Title-based matching**: Pages are matched by title (case-insensitive)
@@ -228,6 +252,58 @@ The action creates a JSON file (default: `telegraph-pages.json`) that maps your
228252
]
229253
```
230254

255+
### Caching Strategy
256+
257+
**⚠️ Important**: The mapping file should **not** be committed to your repository as it can cause git conflicts in CI/CD workflows. Instead, use GitHub Actions cache to persist the mapping file between workflow runs.
258+
259+
#### Recommended Setup with GitHub Actions Cache
260+
261+
Using cache provides several benefits:
262+
263+
- ✅ **Avoids git conflicts** - No need to commit mapping files
264+
- ✅ **Faster builds** - Skips unchanged files on subsequent runs
265+
- ✅ **Preserves functionality** - Internal links and page replacement still work
266+
- ✅ **Automatic cleanup** - Old cache entries expire automatically
267+
268+
The cache key should include a hash of your markdown files to ensure the cache is invalidated when content changes:
269+
270+
```yaml
271+
- name: Cache Telegraph mappings
272+
uses: actions/cache@v3
273+
with:
274+
path: telegraph-pages.json # or your custom output-file
275+
key: telegraph-mappings-${{ hashFiles('**/*.md') }}
276+
restore-keys: |
277+
telegraph-mappings-
278+
```
279+
280+
#### Alternative Storage Options
281+
282+
If you can't use GitHub Actions cache, consider these alternatives:
283+
284+
1. **Temporary directory** (loses incremental update benefits):
285+
286+
```yaml
287+
with:
288+
output-file: "/tmp/telegraph-pages.json"
289+
```
290+
291+
2. **Artifacts** (for cross-job persistence):
292+
293+
```yaml
294+
- name: Upload mappings
295+
uses: actions/upload-artifact@v3
296+
with:
297+
name: telegraph-mappings
298+
path: telegraph-pages.json
299+
```
300+
301+
3. **Add to .gitignore** (if you don't mind the file in workspace):
302+
303+
```gitignore
304+
telegraph-pages.json
305+
```
306+
231307
## Markdown Support
232308

233309
The action supports most standard markdown features:

0 commit comments

Comments
 (0)