Last active
January 28, 2024 12:50
-
-
Save xjasonlyu/d5d67b230d4676d499b567c6f1a0c4f8 to your computer and use it in GitHub Desktop.
Cloudflare Worker Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addEventListener('scheduled', event => { | |
event.waitUntil(handleSchedule(event.scheduledTime)) | |
}) | |
async function handleSchedule(scheduledDate) { | |
const url = `https://api.github.com/repos/${OWNER}/${REPO}/actions/workflows/${WORKFLOW_ID}/dispatches` | |
await fetch(url, { | |
method: 'POST', | |
headers: { | |
'Accept': 'application/vnd.github+json', | |
'Authorization': `Bearer ${TOKEN}`, | |
'X-GitHub-Api-Version': '2022-11-28', | |
'Content-Type': 'application/json', | |
'User-Agent': `Cloudflare-Workers/${scheduledDate}`, | |
}, | |
body: JSON.stringify({ | |
// The git reference for the workflow. | |
'ref': `${REF}` | |
}), | |
}).then(resp => console.log(resp.status)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Required ENV for github-actions-workflow-dispatcher.js
OWNER
: GitHub user/org nameREPO
: GitHub repo nameWORKFLOW_ID
: yaml file of the workflowTOKEN
: GitHub personal access tokenREF
: tag or branch name of the git repo