FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SlayerLegendWiki/scripts/triggerCacheUpdates.js at main · BenDol/SlayerLegendWiki · GitHub
BenDol
/
SlayerLegendWiki
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
2
Code
Issues
210
Pull requests
0
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
SlayerLegendWiki
/
scripts
/
triggerCacheUpdates.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
111 lines (96 loc) · 3.14 KB
Breadcrumbs
SlayerLegendWiki
/
scripts
/
triggerCacheUpdates.js
Copy path
File metadata and controls
111 lines (96 loc) · 3.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env node
/**
* Manual Cache Update Trigger Script
*
* This script manually triggers the GitHub Actions workflow to update
* the highscore cache without waiting for the scheduled run.
*
* Usage:
* node scripts/triggerCacheUpdates.js
*
* Requirements:
* - GITHUB_TOKEN environment variable with repo scope
* - Or run from GitHub Actions (uses GITHUB_TOKEN automatically)
*/
const
https
=
require
(
'https'
)
;
// Configuration
const
owner
=
process
.
env
.
VITE_WIKI_REPO_OWNER
||
'BenDol'
;
const
repo
=
process
.
env
.
VITE_WIKI_REPO_NAME
||
'SlayerLegendWiki'
;
const
token
=
process
.
env
.
GITHUB_TOKEN
;
// Workflow file name
const
WORKFLOW_FILE
=
'update-highscore-cache.yml'
;
/**
* Trigger a GitHub Actions workflow via workflow_dispatch
*/
async
function
triggerWorkflow
(
workflowFile
)
{
return
new
Promise
(
(
resolve
,
reject
)
=>
{
if
(
!
token
)
{
reject
(
new
Error
(
'GITHUB_TOKEN environment variable not set'
)
)
;
return
;
}
const
data
=
JSON
.
stringify
(
{
ref
:
'main'
,
// Branch to run the workflow on
}
)
;
const
options
=
{
hostname
:
'api.github.com'
,
path
:
`/repos/
${
owner
}
/
${
repo
}
/actions/workflows/
${
workflowFile
}
/dispatches`
,
method
:
'POST'
,
headers
:
{
'User-Agent'
:
'Wiki-Cache-Trigger-Script'
,
'Authorization'
:
`token
${
token
}
`
,
'Accept'
:
'application/vnd.github.v3+json'
,
'Content-Type'
:
'application/json'
,
'Content-Length'
:
data
.
length
,
}
,
}
;
const
req
=
https
.
request
(
options
,
(
res
)
=>
{
let
body
=
''
;
res
.
on
(
'data'
,
(
chunk
)
=>
body
+=
chunk
)
;
res
.
on
(
'end'
,
(
)
=>
{
if
(
res
.
statusCode
===
204
)
{
resolve
(
{
success
:
true
,
workflow
:
workflowFile
}
)
;
}
else
{
reject
(
new
Error
(
`Failed to trigger
${
workflowFile
}
:
${
res
.
statusCode
}
${
body
}
`
)
)
;
}
}
)
;
}
)
;
req
.
on
(
'error'
,
reject
)
;
req
.
write
(
data
)
;
req
.
end
(
)
;
}
)
;
}
/**
* Main execution
*/
async
function
main
(
)
{
console
.
log
(
'🚀 Manual Cache Update Trigger\n'
)
;
console
.
log
(
`Repository:
${
owner
}
/
${
repo
}
\n`
)
;
if
(
!
token
)
{
console
.
error
(
'❌ Error: GITHUB_TOKEN environment variable not set'
)
;
console
.
error
(
'\nTo use this script, you need a GitHub Personal Access Token with repo scope.'
)
;
console
.
error
(
'Set it as an environment variable:'
)
;
console
.
error
(
' export GITHUB_TOKEN=your_token_here'
)
;
console
.
error
(
'\nOr trigger workflows manually via GitHub UI:'
)
;
console
.
error
(
' https://github.com/'
+
owner
+
'/'
+
repo
+
'/actions'
)
;
process
.
exit
(
1
)
;
}
try
{
console
.
log
(
'⏳ Triggering Highscore Cache workflow...'
)
;
await
triggerWorkflow
(
WORKFLOW_FILE
)
;
console
.
log
(
'✅ Highscore Cache workflow triggered successfully!'
)
;
}
catch
(
error
)
{
console
.
error
(
'❌ Failed to trigger workflow:'
,
error
.
message
)
;
process
.
exit
(
1
)
;
}
console
.
log
(
'\n✨ Done!'
)
;
console
.
log
(
'\nCheck workflow status at:'
)
;
console
.
log
(
`https://github.com/
${
owner
}
/
${
repo
}
/actions`
)
;
}
// Run if executed directly
if
(
require
.
main
===
module
)
{
main
(
)
.
catch
(
error
=>
{
console
.
error
(
'Fatal error:'
,
error
)
;
process
.
exit
(
1
)
;
}
)
;
}
module
.
exports
=
{
triggerWorkflow
}
;
Back
|
FazBrowse Home
|
New Git URL