-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
6,421 additions
and
5,950 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import fetch from 'node-fetch'; | ||
import { logger } from './logger'; | ||
|
||
// Function to trigger GitHub Actions workflow | ||
export async function triggerWorkflow() { | ||
const repoOwner = 'manafasif'; | ||
const repoName = 'hans-wehr-cloud-logger'; | ||
const workflowName = 'build_push_docker.yml'; // Replace with the actual name of your workflow | ||
|
||
const apiUrl = `https://api.github.com/repos/${repoOwner}/${repoName}/actions/workflows/${workflowName}/dispatches`; | ||
|
||
const githubToken = 'your-github-token'; // Replace with a valid GitHub token with workflow scope | ||
|
||
const headers = { | ||
'Content-Type': 'application/json', | ||
'Authorization': `Bearer ${githubToken}`, | ||
}; | ||
|
||
const requestBody = { | ||
ref: 'main', // Replace with the branch where your workflow is defined | ||
inputs: { | ||
// Add any additional inputs that your workflow might need | ||
}, | ||
}; | ||
|
||
try { | ||
const response = await fetch(apiUrl, { | ||
method: 'POST', | ||
headers, | ||
body: JSON.stringify(requestBody), | ||
}); | ||
|
||
if (response.ok) { | ||
logger.info('Workflow triggered successfully.'); | ||
} else { | ||
logger.error('Failed to trigger workflow:', await response.text()); | ||
} | ||
} catch (error: any) { | ||
logger.error('Error triggering workflow:', error.message); | ||
} | ||
} | ||
|
||
// // Call the function to trigger the workflow | ||
// triggerWorkflow(); |
Oops, something went wrong.