Skip to content

Commit bdb4d9b

Browse files
authored
Add deployment option to CI workflow (codesandbox#2945)
* Add deployment option to CI workflow * Auto retry for integration tests * New deploy script * Change deploy script * Update executor * Change step order * Fix builds * Fix fetch * Force new deploy * Filter more errors from sentry * Remove the update notification message * Filter another error * Add staging deployment option * Duplicate branches logic * Revert "Duplicate branches logic" This reverts commit 7c715a6. * Fix filter for branches
1 parent 5718fad commit bdb4d9b

File tree

6 files changed

+120
-36
lines changed

6 files changed

+120
-36
lines changed

.circleci/config.yml

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ commands:
168168
- run:
169169
name: Build Application
170170
command: yarn build:prod
171-
- run:
172-
name: Mark Sentry release
173-
command: |
174-
if [ "${CIRCLE_BRANCH}" == "master" ]; then
175-
node packages/app/scripts/sentry-create-release.js
176-
fi
177171
- save_cache: *save_prod_build_cache
178172
- save_cache: *save_prod_result
179173
- run:
@@ -302,6 +296,34 @@ jobs:
302296
executor: docker_machine
303297
steps:
304298
- docker_cache
299+
deploy-to-production:
300+
executor: node
301+
environment:
302+
ENVIRONMENT: production
303+
steps:
304+
- checkout_with_cache
305+
- restore_cache: *restore_deps_cache
306+
- attach_workspace: *attach_deps_workspace
307+
- run:
308+
name: Mark Sentry release
309+
command: node packages/app/scripts/sentry-create-release.js
310+
- run:
311+
name: Deploy Image
312+
command: node packages/app/scripts/deploy.js
313+
- run:
314+
name: Deploy Sentry release
315+
command: node packages/app/scripts/sentry-deploy-release.js
316+
deploy-to-staging:
317+
executor: node
318+
environment:
319+
ENVIRONMENT: staging
320+
steps:
321+
- checkout_with_cache
322+
- restore_cache: *restore_deps_cache
323+
- attach_workspace: *attach_deps_workspace
324+
- run:
325+
name: Deploy Image
326+
command: node packages/app/scripts/deploy.js
305327

306328
################################
307329
# Workflows
@@ -334,3 +356,21 @@ workflows:
334356
- typecheck
335357
# - test-integrations
336358
- test-jest
359+
- deploy-production-approval:
360+
type: approval
361+
requires:
362+
- create-docker-image
363+
filters:
364+
branches:
365+
only:
366+
- master
367+
- deploy-to-production:
368+
requires:
369+
- deploy-production-approval
370+
- deploy-staging-approval:
371+
type: approval
372+
requires:
373+
- create-docker-image
374+
- deploy-to-staging:
375+
requires:
376+
- deploy-staging-approval

packages/app/integration-tests/browser-tests/browsers.test.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ const hash = require('child_process')
44
.execSync('git rev-parse --short HEAD')
55
.toString();
66

7+
const delay = ms =>
8+
new Promise(resolve => {
9+
setTimeout(() => {
10+
resolve();
11+
}, ms);
12+
});
13+
714
function getCapabilities(browserInfo) {
815
return {
916
...browserInfo,
@@ -77,8 +84,13 @@ usedDescribe('browser-tests', () => {
7784
os_version: '10',
7885
resolution: '1024x768',
7986
};
80-
81-
await testPageWitCapabilities(capabilities);
87+
try {
88+
await testPageWitCapabilities(capabilities);
89+
} catch (e) {
90+
await delay(10000);
91+
// Retry
92+
await testPageWitCapabilities(capabilities);
93+
}
8294
}, 130000);
8395

8496
test('safari', async () => {
@@ -90,8 +102,13 @@ usedDescribe('browser-tests', () => {
90102
os_version: 'High Sierra',
91103
resolution: '1024x768',
92104
};
93-
94-
await testPageWitCapabilities(capabilities);
105+
try {
106+
await testPageWitCapabilities(capabilities);
107+
} catch (e) {
108+
await delay(10000);
109+
// Retry
110+
await testPageWitCapabilities(capabilities);
111+
}
95112
}, 130000);
96113

97114
test.skip('android', async () => {

packages/app/scripts/deploy.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const fetch = require('cross-fetch');
2+
3+
fetch('https://deployment-api.lbogdan.ro/image', {
4+
method: 'POST',
5+
headers: {
6+
'Content-Type': 'application/json',
7+
Authorization: `Bearer ${process.env.DEPLOY_TOKEN}`,
8+
},
9+
body: JSON.stringify({
10+
env: process.env.ENVIRONMENT,
11+
image: 'client',
12+
tag: process.env.CIRCLE_SHA1.substr(0, 7),
13+
deploy: true,
14+
}),
15+
})
16+
.then(x => {
17+
if (!x.ok) {
18+
throw new Error('Request failed');
19+
}
20+
21+
return x.json();
22+
})
23+
.then(res => {
24+
// eslint-disable-next-line
25+
console.log(res);
26+
process.exit(0);
27+
})
28+
.catch(e => {
29+
console.error(e);
30+
process.exit(1);
31+
});

packages/app/scripts/sentry-create-release.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ try {
1212
`yarn sentry-cli releases --org=codesandbox -p frontend new "${VERSION}"`
1313
);
1414
childProcess.execSync(
15-
`yarn sentry-cli releases --org=codesandbox set-commits "${VERSION}" --commit "CompuIves/codesandbox-client@${COMMIT_HASH}"`
15+
`yarn sentry-cli releases --org=codesandbox set-commits "${VERSION}" --commit "codesandbox/codesandbox-client@${COMMIT_HASH}"`
1616
);
1717
console.log('Marked release');
1818
} catch (e) {

packages/app/src/app/index.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
notificationState,
2020
convertTypeToStatus,
2121
} from '@codesandbox/common/lib/utils/notifications';
22-
import { NotificationStatus } from '@codesandbox/notifications';
2322
import 'normalize.css';
2423
import theme from '@codesandbox/common/lib/theme';
2524
import { isSafari } from '@codesandbox/common/lib/utils/platform';
@@ -90,22 +89,6 @@ async function boot(overmind) {
9089
onUpdated: () => {
9190
debug('Updated SW');
9291
getSignal('setUpdateStatus')({ status: 'available' });
93-
94-
notificationState.addNotification({
95-
title: 'CodeSandbox Update Available',
96-
message:
97-
'We just installed a new version of CodeSandbox, refresh to update!',
98-
status: NotificationStatus.SUCCESS,
99-
sticky: true,
100-
actions: {
101-
primary: [
102-
{
103-
run: () => document.location.reload(),
104-
label: 'Reload Page',
105-
},
106-
],
107-
},
108-
});
10992
},
11093
onInstalled: () => {
11194
debug('Installed SW');

packages/common/src/utils/analytics.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,28 @@ export async function initializeSentry(dsn: string) {
102102
if (
103103
event.stacktrace &&
104104
event.stacktrace.frames &&
105-
event.stacktrace.frames[0] &&
106-
event.stacktrace.frames[0].filename.endsWith(
107-
'codesandbox.editor.main.js'
108-
)
105+
event.stacktrace.frames[0]
109106
) {
110-
// This is the spammy event that doesn't do anything: https://sentry.io/organizations/codesandbox/issues/1054971728/?project=155188&query=is%3Aunresolved
111-
// Don't do anything with it right now, I can't seem to reproduce it for some reason.
112-
// We need to add sourcemaps
113-
return undefined;
107+
const { filename } = event.stacktrace.frames[0];
108+
109+
if (
110+
filename.includes('typescript-worker') &&
111+
event.message &&
112+
event.message.includes('too much recursion')
113+
) {
114+
// https://sentry.io/organizations/codesandbox/issues/1293123855/events/b01ee0feb7e3415a8bb81b6a9df19152/?project=155188&query=is%3Aunresolved&statsPeriod=14d
115+
return undefined;
116+
}
117+
118+
if (
119+
filename.endsWith('codesandbox.editor.main.js') ||
120+
filename.startsWith('/extensions/')
121+
) {
122+
// This is the spammy event that doesn't do anything: https://sentry.io/organizations/codesandbox/issues/1054971728/?project=155188&query=is%3Aunresolved
123+
// Don't do anything with it right now, I can't seem to reproduce it for some reason.
124+
// We need to add sourcemaps
125+
return undefined;
126+
}
114127
}
115128

116129
const customError = ((hint && (hint.originalException as any)) || {})

0 commit comments

Comments
 (0)