Skip to content

Commit

Permalink
Basic function is working
Browse files Browse the repository at this point in the history
Needs more error management
  • Loading branch information
Demmonius committed Nov 26, 2020
1 parent 252b763 commit 1b76d2e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/pages/api/deployToProduction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,30 @@ const logger = createLogger({

export default async (req: NextApiRequest, res: NextApiResponse): Promise<void> => {
const PRODUCTION_CI_FILE = '.github/workflows/deploy-vercel-production.yml';
const deploymentRef = 'master'; //TODO
const deployRef = req.query.ref || process.env.NEXT_PUBLIC_NRN_PRESET;

try {
configureReq(req);

console.log('Github token: ', process.env.GITHUB_DISPATCH_TOKEN);
console.log('Customer: ', process.env.NEXT_PUBLIC_CUSTOMER_REF);
console.log('ref: ', deploymentRef);

fetch('https://api.github.com/repos/UnlyEd/next-right-now/actions/workflows').then((plainData) => plainData.json()).then((data) => {
const [productionWorkflow] = data.workflows.filter((workflow) => workflow.path === PRODUCTION_CI_FILE);
console.log(`Fetching ${productionWorkflow.url}/dispatches`);
fetch(`${productionWorkflow.url}/dispatches`, {
method: 'POST',
headers: {
Authorization: `token ${process.env.GITHUB_DISPATCH_TOKEN}`,
Accept: 'application/vnd.github.v3+json'
},
body: JSON.stringify({
ref: deploymentRef,
inputs: {
customer: process.env.NEXT_PUBLIC_CUSTOMER_REF
}
},
ref: deployRef
})
}).then((response) => {
console.log('response: ', response);
console.log('responseStatus: ', response.status);
}).then(async (response) => {
console.log('response: ', response.status);
});
});

Expand Down

1 comment on commit 1b76d2e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.