Skip to content

Commit

Permalink
Fix API startVercelDeployment (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadorequest authored Nov 27, 2020
1 parent 4423f93 commit 02ab0ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/pages/api/startVercelDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ const GITHUB_ACTION_WORKFLOW_FILE_PATH_STAGING = '.github/workflows/deploy-verce
const startVercelDeployment = async (req: EndpointRequest, res: NextApiResponse): Promise<void> => {
try {
configureReq(req, { fileLabel });
Sentry.captureEvent({
message: 'API endpoint "startVercelDeployment" invoked.',
level: Sentry.Severity.Log,
});

const {
customerAuthToken,
Expand All @@ -115,7 +119,7 @@ const startVercelDeployment = async (req: EndpointRequest, res: NextApiResponse)
// XXX For the sake of simplicity, our "customerAuthToken" is the same as the customer ref.
// This is better than using no token at all, but it's still a rather weak security check.
// Feel free to implement your own authentication protocol.
if(customerAuthToken !== process.env.NEXT_PUBLIC_CUSTOMER_REF){
if (customerAuthToken !== process.env.NEXT_PUBLIC_CUSTOMER_REF) {
const errorMessage = `Query parameter "customerAuthToken" is not valid (using "${customerAuthToken}"). Access refused.`;
Sentry.captureException(new Error(errorMessage));
logger.error(errorMessage);
Expand Down Expand Up @@ -150,8 +154,7 @@ const startVercelDeployment = async (req: EndpointRequest, res: NextApiResponse)
}

// Dispatch the GitHub Actions workflow, which will then trigger the Vercel deployment
// XXX We don't await for the processing to be done
dispatchWorkflowByPath(platformReleaseRef, process.env.NEXT_PUBLIC_APP_STAGE === 'production' ? GITHUB_ACTION_WORKFLOW_FILE_PATH_PRODUCTION : GITHUB_ACTION_WORKFLOW_FILE_PATH_STAGING);
await dispatchWorkflowByPath(platformReleaseRef, process.env.NEXT_PUBLIC_APP_STAGE === 'production' ? GITHUB_ACTION_WORKFLOW_FILE_PATH_PRODUCTION : GITHUB_ACTION_WORKFLOW_FILE_PATH_STAGING);

// Redirect the end-user
redirect(res, redirectTo, statusCode);
Expand Down
9 changes: 8 additions & 1 deletion src/utils/gitHubActions/dispatchWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@ export const dispatchWorkflow = async (workflowsList: WorkflowsAPIResponse, plat
const url = `${workflowDetails?.url}/dispatches`;

Sentry.configureScope((scope): void => {
scope.setExtra('workflowFilePath', workflowFilePath);
scope.setExtra('workflowDispatchRequestUrl', url);
scope.setContext('workflowDispatchRequestBody', body);
scope.setContext('workflowDetails', workflowDetails);
scope.setContext('requestBody', body);
});

Sentry.captureEvent({
message: 'Triggering Vercel deployment.',
level: Sentry.Severity.Log,
});

logger.debug(`Fetching "${url}", using workflow path: "${workflowFilePath}", with request body: ${JSON.stringify(body, null, 2)}`);
Expand Down

3 comments on commit 02ab0ed

@github-actions
Copy link

Choose a reason for hiding this comment

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

@github-actions
Copy link

Choose a reason for hiding this comment

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

@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.