@alwaysmeticulous/cli 2.7.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +0,0 @@
1
- import { AxiosInstance } from "axios";
2
- export declare const getProjectBuild: (client: AxiosInstance, projectBuildId: string) => Promise<any>;
3
- export declare const createProjectBuild: (client: AxiosInstance, commitSha: string) => Promise<any>;
4
- export interface ProjectBuildPushUrlOutput {
5
- projectBuildId: string;
6
- pushUrl: string;
7
- }
8
- export declare const getProjectBuildPushUrl: (client: AxiosInstance, projectBuildId: string) => Promise<ProjectBuildPushUrlOutput | null>;
9
- export declare const putProjectBuildPushedStatus: (client: AxiosInstance, projectBuildId: string, status: "success" | "failure") => Promise<any>;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.putProjectBuildPushedStatus = exports.getProjectBuildPushUrl = exports.createProjectBuild = exports.getProjectBuild = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const getProjectBuild = async (client, projectBuildId) => {
9
- const { data } = await client
10
- .get(`project-builds/${projectBuildId}`)
11
- .catch((error) => {
12
- var _a;
13
- if (axios_1.default.isAxiosError(error)) {
14
- if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
15
- return { data: null };
16
- }
17
- }
18
- throw error;
19
- });
20
- return data;
21
- };
22
- exports.getProjectBuild = getProjectBuild;
23
- const createProjectBuild = async (client, commitSha) => {
24
- const { data } = await client.post("project-builds", {
25
- commitSha,
26
- });
27
- return data;
28
- };
29
- exports.createProjectBuild = createProjectBuild;
30
- const getProjectBuildPushUrl = async (client, projectBuildId) => {
31
- const { data } = await client
32
- .get(`project-builds/${projectBuildId}/push-url`)
33
- .catch((error) => {
34
- var _a;
35
- if (axios_1.default.isAxiosError(error)) {
36
- if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
37
- return { data: null };
38
- }
39
- }
40
- throw error;
41
- });
42
- return data;
43
- };
44
- exports.getProjectBuildPushUrl = getProjectBuildPushUrl;
45
- const putProjectBuildPushedStatus = async (client, projectBuildId, status) => {
46
- const { data } = await client.put(`project-builds/${projectBuildId}/pushed`, {
47
- status,
48
- });
49
- return data;
50
- };
51
- exports.putProjectBuildPushedStatus = putProjectBuildPushedStatus;
@@ -1,13 +0,0 @@
1
- /// <reference types="yargs" />
2
- export declare const uploadBuild: import("yargs").CommandModule<unknown, import("yargs").InferredOptionTypes<{
3
- apiToken: {
4
- string: true;
5
- };
6
- commitSha: {
7
- string: true;
8
- };
9
- dist: {
10
- string: true;
11
- demandOption: true;
12
- };
13
- }>>;
@@ -1,88 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.uploadBuild = void 0;
7
- const common_1 = require("@alwaysmeticulous/common");
8
- const loglevel_1 = __importDefault(require("loglevel"));
9
- const client_1 = require("../../api/client");
10
- const project_build_api_1 = require("../../api/project-build.api");
11
- const project_api_1 = require("../../api/project.api");
12
- const upload_1 = require("../../api/upload");
13
- const archive_1 = require("../../archive/archive");
14
- const command_builder_1 = require("../../command-utils/command-builder");
15
- const commit_sha_utils_1 = require("../../utils/commit-sha.utils");
16
- const handler = async ({ apiToken, commitSha: commitSha_, dist, }) => {
17
- const logger = loglevel_1.default.getLogger(common_1.METICULOUS_LOGGER_NAME);
18
- // 1. Print project name
19
- const client = (0, client_1.createClient)({ apiToken });
20
- const project = await (0, project_api_1.getProject)(client);
21
- if (!project) {
22
- logger.error("Error: Could not retrieve project data. Is the API token correct?");
23
- process.exit(1);
24
- }
25
- const projectName = `${project.organization.name}/${project.name}`;
26
- logger.info(`Project: ${projectName}`);
27
- // 2. Guess commit SHA1
28
- const commitSha = await (0, commit_sha_utils_1.getCommitSha)(commitSha_);
29
- if (!commitSha) {
30
- logger.error("Error: Could not guess commit SHA1, aborting");
31
- process.exit(1);
32
- }
33
- logger.info(`Commit: ${commitSha}`);
34
- // 3. Create zip archive of build artifacts
35
- logger.info(`Uploading build artifacts from: ${dist}`);
36
- try {
37
- await (0, archive_1.checkDistFolder)(dist);
38
- }
39
- catch (error) {
40
- if (error instanceof Error) {
41
- logger.error(`Error: ${error.message}`);
42
- }
43
- else {
44
- logger.error(`Error: ${error}`);
45
- }
46
- process.exit(1);
47
- }
48
- const archivePath = await (0, archive_1.createArchive)(dist);
49
- // 4. Get upload URL
50
- const projectBuild = await (0, project_build_api_1.createProjectBuild)(client, commitSha);
51
- const uploadUrlData = await (0, project_build_api_1.getProjectBuildPushUrl)(client, projectBuild.id);
52
- if (!uploadUrlData) {
53
- logger.error("Error: Could not get a push URL from the Meticulous API");
54
- process.exit(1);
55
- }
56
- const uploadUrl = uploadUrlData.pushUrl;
57
- // 5. Send archive to S3
58
- try {
59
- await (0, upload_1.uploadArchive)(uploadUrl, archivePath);
60
- }
61
- catch (error) {
62
- await (0, project_build_api_1.putProjectBuildPushedStatus)(client, projectBuild.id, "failure").catch((updateError) => logger.error(updateError));
63
- logger.error(error);
64
- process.exit(1);
65
- }
66
- // 6. Report successful upload to Meticulous
67
- const updatedProjectBuild = await (0, project_build_api_1.putProjectBuildPushedStatus)(client, projectBuild.id, "success");
68
- logger.info("Build artifacts successfully sent to Meticulous");
69
- logger.debug(updatedProjectBuild);
70
- await (0, archive_1.deleteArchive)(archivePath);
71
- };
72
- exports.uploadBuild = (0, command_builder_1.buildCommand)("upload-build")
73
- .details({
74
- describe: "Upload build artifacts to Meticulous",
75
- })
76
- .options({
77
- apiToken: {
78
- string: true,
79
- },
80
- commitSha: {
81
- string: true,
82
- },
83
- dist: {
84
- string: true,
85
- demandOption: true,
86
- },
87
- })
88
- .handler(handler);