Skip to content

Instantly share code, notes, and snippets.

@xjasonlyu
Last active January 28, 2024 12:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xjasonlyu/d5d67b230d4676d499b567c6f1a0c4f8 to your computer and use it in GitHub Desktop.
Save xjasonlyu/d5d67b230d4676d499b567c6f1a0c4f8 to your computer and use it in GitHub Desktop.
Cloudflare Worker Snippets
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));
}
@xjasonlyu
Copy link
Author

Required ENV for github-actions-workflow-dispatcher.js

  • OWNER: GitHub user/org name
  • REPO: GitHub repo name
  • WORKFLOW_ID: yaml file of the workflow
  • TOKEN: GitHub personal access token
  • REF: tag or branch name of the git repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment