Skip to content

Commit

Permalink
fix(sentry): bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Airkro committed Oct 20, 2023
1 parent e4d1649 commit 8819d3e
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 41 deletions.
39 changes: 38 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/sentry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ bring-it sentry
"url": "...",
"org": "...",
"project": "...",
"authToken": "..."
"token": "..."
}
```
113 changes: 76 additions & 37 deletions packages/sentry/lib/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { execFile, execFileSync } from 'node:child_process';
import { execFileSync } from 'node:child_process';
import { rm } from 'node:fs/promises';

import { ignore, Logger, readJSON } from '@bring-it/utils';
import spawn from '@npmcli/promise-spawn';
import { globby } from 'globby';

const logger = new Logger('sentry');
Expand All @@ -19,14 +20,33 @@ function readConfig(configName) {
function scan({ include }) {
return globby(include, {
ignore,
gitignore: true,
onlyFiles: true,
dot: true,
})
.then((list) => list.filter((item) => /\.map$/.test(item)))
.then((list) => list.sort());
}

function createCli({ url, org, project, token }) {
return function cli(...args) {
return spawn('sentry-cli', ['releases', ...args], {
stdio: 'inherit',
env: {
...process.env,
SENTRY_AUTH_TOKEN: token,
SENTRY_URL: url,
SENTRY_ORG: org,
SENTRY_PROJECT: project,
SENTRY_LOG_LEVEL: 'info',
},
}).then((io) => {
if (io.stderr) {
throw new Error('Command failed');
}
});
};
}

export async function action({ mode }) {
try {
const { [mode]: current, ...all } = await readConfig(
Expand All @@ -37,55 +57,74 @@ export async function action({ mode }) {
url,
org,
project,
authToken,
token,
include = 'dist/**',
} = {
...all,
...current,
};

const version = commitHash();

// eslint-disable-next-line no-inner-declarations
function cli(...args) {
return execFile(
'sentry-cli',
['releases', ...args, '--url', url, '--org', org, '--project', project],
{
env: {
SENTRY_AUTH_TOKEN: authToken,
SENTRY_LOG_LEVEL: 'debug',
},
},
);
logger.task('scanning...');

const list = await scan({ include });

logger.info('found', list.length, 'files');

for (const item of list) {
logger.file(item);
}

await cli('finalize', version);
if (list.length > 0) {
const version = commitHash();

logger.info('uploading...');
logger.info('git commit hash', version);

await cli(
'files',
version,
'upload-sourcemaps',
include,
'--no-sourcemap-reference',
);
const cli = createCli({ url, org, project, token });

await cli('deploys', version, 'new', '-e', mode);
logger.task('create release...');

const list = await scan({ include });
await cli('new', version);

for (const item of list) {
rm(item, { force: true })
.then(() => {
logger.okay('[delete]', item);
})
.catch((error) => {
logger.fail('[delete]', item, error.message);
});
logger.okay('release created');

logger.task('uploading...');

await cli(
'files',
version,
'upload-sourcemaps',
include,
'--no-sourcemap-reference',
'--no-rewrite',
);

logger.okay('uploaded');

logger.task('deploys', mode);

await cli('deploys', version, 'new', '-e', mode);

logger.task('finalize...');

await cli('finalize', version);

logger.okay('finalized');

logger.task('delete files...');

for (const item of list) {
await rm(item, { force: true })
.then(() => {
logger.okay('[delete]', item);
})
.catch((error) => {
logger.fail('[delete]', item, error.message);
});
}

logger.okay('done');
}
} catch (error) {
logger.fail(error);
logger.fail(error.message);
}
}
3 changes: 2 additions & 1 deletion packages/sentry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/sentry",
"version": "0.2.0",
"version": "0.2.1",
"description": "Update sentry artifacts",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -42,6 +42,7 @@
},
"devDependencies": {
"@bring-it/utils": "*",
"@npmcli/promise-spawn": "^7.0.0",
"cheetor": "^0.13.0",
"globby": "^13.2.2"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/utils/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export class Logger {
this.log('[task]', ...message);
}

file(...message) {
this.log('[file]', ...message);
}

info(...message) {
this.log('[info]', ...message);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"name": "@bring-it/utils",
"version": "0.0.0",
"main": "index.mjs",
"type": "module",
"dependencies": {
"chalk": "^5.2.0",
"globby": "^13.1.3"
}
}
}

0 comments on commit 8819d3e

Please sign in to comment.