Skip to content

Commit 85a57fc

Browse files
committed
feat: simplify action to minimal timestamp updater for testing GitHub API permissions
1 parent 7339210 commit 85a57fc

File tree

4 files changed

+34
-64
lines changed

4 files changed

+34
-64
lines changed

action.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
name: Hugo Updater v2
2-
description: Update Hugo sites with RSS feed content
2+
description: Update README sections
33
inputs:
4-
feed-url:
5-
required: true
6-
description: RSS feed URL
74
readme-section:
85
required: true
9-
description: README section
10-
max:
11-
default: 5
12-
description: RSS feed items
13-
template:
14-
default: '* [{{ title }}]({{ link }})'
15-
description: Markdown list item
6+
description: README section name to update (between START_SECTION and END_SECTION comments)
167
github_token:
178
description: GitHub token for authentication
189
required: false
@@ -22,7 +13,7 @@ inputs:
2213
description: Target branch to update.
2314
message:
2415
default: 'docs: update'
25-
description: Commit
16+
description: Commit message
2617
runs:
2718
using: node20
2819
main: dist/index.js

dist/index.js

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@
1111
"license": "",
1212
"dependencies": {
1313
"actions-toolkit": "^6.0.1",
14-
"mustache": "^4.2.0",
15-
"readme-box": "^1.0.0",
16-
"rss-parser": "^3.13.0"
14+
"readme-box": "^1.0.0"
1715
},
1816
"devDependencies": {
19-
"@types/mustache": "^4.2.6",
2017
"@vercel/ncc": "^0.38.3",
2118
"typescript": "^5.9.2"
2219
}

src/index.ts

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,57 @@
11
import { Toolkit } from 'actions-toolkit'
22
import { ReadmeBox } from 'readme-box'
3-
import Parser from 'rss-parser'
4-
import mustache from 'mustache'
5-
6-
const parser = new Parser()
73

84
interface Inputs {
9-
'feed-url': string
105
'readme-section': string
11-
max: string
12-
template: string
136
github_token: string
147
branch: string
158
message: string
169
[key: string]: string
1710
}
1811

1912
Toolkit.run<Inputs>(async tools => {
13+
console.log('🚀 Hugo Updater v2 - Starting update');
14+
2015
// Check if we have a valid token
2116
if (!tools.token) {
2217
throw new Error('GitHub token is required but not provided. Please ensure GITHUB_TOKEN is available or pass it explicitly as github_token input.')
2318
}
2419

25-
console.log('=== DEBUG INFO ===');
26-
console.log('Environment check - start of action');
27-
console.log('Repository:', tools.context.repo.owner + '/' + tools.context.repo.repo);
28-
29-
// Fetch feed
30-
const feed = await parser.parseURL(tools.inputs['feed-url'])
31-
console.log('RSS feed fetched successfully, items:', feed.items?.length || 0);
32-
33-
if (!feed.items) {
34-
throw new Error('feed.items was not found!')
35-
}
36-
37-
// Create our new list
38-
// const timestamp = new Date().getTime().toString();
39-
const newString = feed.items
40-
.slice(0, parseInt(tools.inputs.max, 10))
41-
.map(item => mustache.render(tools.inputs.template, item))
42-
.join('\n')
43-
// .concat(`<!--Updated at ${timestamp}-->\n`)
44-
4520
// Use the token from inputs if provided, otherwise fall back to tools.token
4621
const token = tools.inputs.github_token || tools.token;
22+
const repository = tools.context.repo.owner + '/' + tools.context.repo.repo;
23+
const branch = tools.inputs.branch || tools.context.payload.repository?.default_branch;
24+
const section = tools.inputs['readme-section'];
25+
26+
console.log('📊 Configuration:');
27+
console.log(` Repository: ${repository}`);
28+
console.log(` Branch: ${branch}`);
29+
console.log(` Section: ${section}`);
30+
console.log(` Token source: ${tools.inputs.github_token ? 'from input' : 'from tools.token'}`);
4731

48-
// Debug logging (token will be masked in logs automatically)
49-
console.log('Token source:', tools.inputs.github_token ? 'from input' : 'from tools.token');
50-
console.log('Token exists:', !!token);
51-
console.log('Repository:', tools.context.repo.owner + '/' + tools.context.repo.repo);
52-
console.log('Branch:', tools.inputs.branch || tools.context.payload.repository?.default_branch);
32+
// Create timestamp comment
33+
const timestamp = new Date().toISOString();
34+
const timestampComment = `<!--Updated at ${timestamp}-->`;
5335

54-
console.log('About to call ReadmeBox.updateSection...');
36+
console.log('⏰ Generated timestamp:', timestamp);
37+
console.log('📝 Updating README section with timestamp comment...');
5538

5639
try {
5740
// Update the section of our README
58-
await ReadmeBox.updateSection(newString, {
41+
await ReadmeBox.updateSection(timestampComment, {
5942
...tools.context.repo,
6043
token: token,
61-
section: tools.inputs['readme-section'],
62-
branch: tools.inputs.branch || tools.context.payload.repository?.default_branch,
44+
section: section,
45+
branch: branch,
6346
message: tools.inputs.message
64-
})
65-
console.log('ReadmeBox.updateSection completed successfully');
47+
});
48+
49+
console.log('✅ README section updated successfully!');
50+
console.log(` Section '${section}' now contains: ${timestampComment}`);
51+
console.log(` Committed with message: "${tools.inputs.message}"`);
52+
6653
} catch (error) {
67-
console.error('ReadmeBox.updateSection failed:', error);
54+
console.error('❌ Failed to update README section:', error);
6855
throw error;
6956
}
7057
})

0 commit comments

Comments
 (0)