Skip to content

Commit

Permalink
Feature/demrum 439 ios dsyms upload (#60)
Browse files Browse the repository at this point in the history
* DEMRUM-439: add initial iOSInputValidations

* DEMRUM-439: add node_modules.local to .gitignore

* DEMRUM-439: implement iOS dSYMs upload

* DEMRUM-439: scoped name for env variable

* DEMRUM-439: fix case for iOS

* DEMRUM-439: fix case in program.addCommand(iOSCommand)

* DEMRUM-439: fix lint errors

* DEMRUM-439: remove unused validations

* DEMRUM-439: remove unused fields

* DEMRUM: 439: remove trailing comma

* DEMRUM-439: update message and restore missing terminator

* DEMRUM-439: make inputValidations shared

* DEMRUM-439: improve messages

* DEMRUM-439: update import and filename to reflect new shared filename of inputValidations file
  • Loading branch information
carlosmcevilly authored Jan 10, 2025
1 parent 0a206b1 commit 3a716df
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Node modules
node_modules/
node_modules.local/

# Logs
logs
Expand Down
2 changes: 1 addition & 1 deletion src/commands/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
isValidAppId,
isValidVersionCode,
isValidUUID
} from '../utils/androidInputValidations';
} from '../utils/inputValidations';
import { UserFriendlyError } from '../utils/userFriendlyErrors';
import { createLogger, LogLevel } from '../utils/logger';
import axios from 'axios';
Expand Down
85 changes: 79 additions & 6 deletions src/commands/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,86 @@
*/

import { Command } from 'commander';
import {
isValidFile,
hasValidExtension,
} from '../utils/inputValidations';
import { UserFriendlyError } from '../utils/userFriendlyErrors';
import { createLogger, LogLevel } from '../utils/logger';
import { uploadFile } from '../utils/httpUtils';

export const iosCommand = new Command('ios');
// Constants
const DEFAULT_REALM = 'us0';
const DSYM_FIELD_NAME = 'dSYM';
const API_BASE_URL = process.env.O11Y_API_BASE_URL || 'https://api.splunk.com';
const API_VERSION_STRING = 'v1';
const API_PATH = 'dsyms';

iosCommand
export const iOSCommand = new Command('iOS');

const iOSUploadDescription = `This subcommand uploads the specified zipped dSYMs file.
`;

interface UploadiOSOptions {
'file': string,
'debug'?: boolean
}

const generateUrl = (): string => {
const realm = process.env.O11Y_REALM || DEFAULT_REALM;
return `${API_BASE_URL}/${realm}/${API_VERSION_STRING}/${API_PATH}`;
};

iOSCommand
.name('ios')
.description('Upload and list zipped iOS symbolication files (dSYMs)');

iOSCommand
.command('upload')
.description('Upload an iOS dSYM file')
.requiredOption('--file <file>', 'Path to the dSYM file')
.action((options) => {
console.log(`Uploading iOS dSYM file from: ${options.file}`);
.showHelpAfterError(true)
.usage('--file <path>')
.description(iOSUploadDescription)
.summary('Upload a dSYMs .zip file to the symbolication service')
.requiredOption('--file <path>', 'Path to the dSYMs .zip file')
.option('--debug', 'Enable debug logs')
.action(async (options: UploadiOSOptions) => {
const logger = createLogger(options.debug ? LogLevel.DEBUG : LogLevel.INFO);

try {
if (!isValidFile(options.file)) {
throw new UserFriendlyError(null, `Invalid dSYMs file path: ${options.file}.`);
}

if (!hasValidExtension(options.file, '.zip')) {
throw new UserFriendlyError(null, `dSYMs file does not have .zip extension: ${options.file}.`);
}

const fileData = {
filePath: options.file,
fieldName: DSYM_FIELD_NAME,
};

const url = generateUrl();

logger.info(`url: ${url}`);

logger.info(`Preparing to upload dSYMs file: ${options.file}`);

await uploadFile({
url,
file: fileData,
parameters: {}
});

logger.info('\nUpload complete!');
} catch (error) {
if (error instanceof Error) {
logger.error('Failed to upload the dSYMs file:', error.message);
throw error;
} else {
const errorMessage = `Unexpected error type: ${JSON.stringify(error)}`;
logger.error('Failed to upload the dSYMs file:', errorMessage);
throw new Error(errorMessage);
}
}
});
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

import { Command } from 'commander';
import { iosCommand } from './commands/ios';
import { iOSCommand } from './commands/ios';
import { androidCommand } from './commands/android';
import { sourcemapsCommand } from './commands/sourcemaps';

Expand All @@ -36,7 +36,7 @@ program
.description(helpDescription)
.usage('[ios|android|sourcemaps] [sub-command] [options]');

program.addCommand(iosCommand);
program.addCommand(iOSCommand);
program.addCommand(androidCommand);
program.addCommand(sourcemapsCommand);

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import fs from 'fs';
import * as utils from '../../src/utils/androidInputValidations';
import * as utils from '../../src/utils/inputValidations';

describe('Utility functions', () => {

Expand Down

0 comments on commit 3a716df

Please sign in to comment.