@argos-ci/core 2.5.0 → 2.5.2-alpha.1

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.
package/dist/index.d.ts CHANGED
@@ -50,7 +50,7 @@ interface UploadParameters {
50
50
  /** Unique build ID for this parallel build */
51
51
  nonce: string;
52
52
  /** The number of parallel nodes being ran */
53
- total: number;
53
+ total?: number;
54
54
  /** The index of the parallel node */
55
55
  index?: number;
56
56
  } | false;
@@ -75,7 +75,19 @@ interface UploadParameters {
75
75
  declare function upload(params: UploadParameters): Promise<{
76
76
  build: {
77
77
  id: string;
78
+ number: number;
79
+ status: "accepted" | "rejected" | "stable" | "diffDetected" | "expired" | "pending" | "progress" | "error" | "aborted";
78
80
  url: string;
81
+ notification: {
82
+ description: string;
83
+ context: string;
84
+ github: {
85
+ state: "pending" | "error" | "success" | "failure";
86
+ };
87
+ gitlab: {
88
+ state: "pending" | "success" | "running" | "failed" | "canceled";
89
+ };
90
+ } | null;
79
91
  };
80
92
  screenshots: {
81
93
  hash: string;
@@ -91,6 +103,32 @@ declare function upload(params: UploadParameters): Promise<{
91
103
  path: string;
92
104
  }[];
93
105
  }>;
106
+ type FinalizeParameters = {
107
+ parallel?: {
108
+ nonce: string;
109
+ };
110
+ };
111
+ /**
112
+ * Finalize pending builds.
113
+ */
114
+ declare function finalize(params: FinalizeParameters): Promise<{
115
+ builds: {
116
+ id: string;
117
+ number: number;
118
+ status: "accepted" | "rejected" | "stable" | "diffDetected" | "expired" | "pending" | "progress" | "error" | "aborted";
119
+ url: string;
120
+ notification: {
121
+ description: string;
122
+ context: string;
123
+ github: {
124
+ state: "pending" | "error" | "success" | "failure";
125
+ };
126
+ gitlab: {
127
+ state: "pending" | "success" | "running" | "failed" | "canceled";
128
+ };
129
+ } | null;
130
+ }[];
131
+ }>;
94
132
  interface Config {
95
133
  apiBaseUrl: string;
96
134
  commit: string;
@@ -115,4 +153,4 @@ interface Config {
115
153
  threshold: number | null;
116
154
  }
117
155
  declare function readConfig(options?: Partial<Config>): Promise<Config>;
118
- export { UploadParameters, upload, Config, readConfig };
156
+ export { UploadParameters, upload, FinalizeParameters, finalize, Config, readConfig };
package/dist/index.mjs CHANGED
@@ -46,11 +46,10 @@ import { createRequire } from 'node:module';
46
46
  }
47
47
  }
48
48
  function getMergeBaseCommitShaWithDepth(input) {
49
- const head = input.head || `HEAD`;
50
49
  try {
51
- execSync(`git fetch origin ${head}:${head} --depth ${input.depth}`);
52
- execSync(`git fetch origin ${input.base}:${input.base} --depth ${input.depth}`);
53
- const mergeBase = execSync(`git merge-base ${head} ${input.base}`).toString().trim();
50
+ execSync(`git fetch --update-head-ok --depth ${input.depth} origin ${input.head}:${input.head}`);
51
+ execSync(`git fetch --update-head-ok --depth ${input.depth} origin ${input.base}:${input.base}`);
52
+ const mergeBase = execSync(`git merge-base ${input.head} ${input.base}`).toString().trim();
54
53
  return mergeBase || null;
55
54
  } catch {
56
55
  return null;
@@ -537,7 +536,7 @@ const schema = {
537
536
  },
538
537
  parallelTotal: {
539
538
  env: "ARGOS_PARALLEL_TOTAL",
540
- format: "nat",
539
+ format: "int",
541
540
  default: null,
542
541
  nullable: true
543
542
  },
@@ -615,8 +614,8 @@ async function readConfig(options = {}) {
615
614
  runAttempt: ciEnv?.runAttempt || null,
616
615
  parallel: options.parallel ?? config.get("parallel") ?? false,
617
616
  parallelNonce: options.parallelNonce || config.get("parallelNonce") || ciEnv?.nonce || null,
618
- parallelTotal: options.parallelTotal || config.get("parallelTotal") || null,
619
- parallelIndex: options.parallelIndex || config.get("parallelIndex") || null,
617
+ parallelTotal: options.parallelTotal ?? config.get("parallelTotal") ?? null,
618
+ parallelIndex: options.parallelIndex ?? config.get("parallelIndex") ?? null,
620
619
  mode: options.mode || config.get("mode") || null,
621
620
  ciProvider: ciEnv?.key || null
622
621
  });
@@ -673,7 +672,9 @@ const hashFile = async (filepath)=>{
673
672
  };
674
673
 
675
674
  const base64Encode = (obj)=>Buffer.from(JSON.stringify(obj), "utf8").toString("base64");
676
- function getAuthToken({ token, ciProvider, owner, repository, jobId, runId, prNumber }) {
675
+ /**
676
+ * Get the authentication token.
677
+ */ function getAuthToken({ token, ciProvider, owner, repository, jobId, runId, prNumber }) {
677
678
  if (token) {
678
679
  return token;
679
680
  }
@@ -695,52 +696,6 @@ function getAuthToken({ token, ciProvider, owner, repository, jobId, runId, prNu
695
696
  throw new Error("Missing Argos repository token 'ARGOS_TOKEN'");
696
697
  }
697
698
  }
698
- const createArgosLegacyAPIClient = (options)=>{
699
- const axiosInstance = axios.create({
700
- baseURL: options.baseUrl,
701
- headers: {
702
- Authorization: options.bearerToken,
703
- "Content-Type": "application/json",
704
- Accept: "application/json"
705
- }
706
- });
707
- const call = async (method, path, data)=>{
708
- try {
709
- debug("Sending request", {
710
- method,
711
- path,
712
- data
713
- });
714
- const response = await axiosInstance.request({
715
- method,
716
- url: path,
717
- data
718
- });
719
- debug("Getting response", {
720
- status: response.status,
721
- data: response.data
722
- });
723
- return response.data;
724
- } catch (error) {
725
- if (error?.response?.data?.error?.message) {
726
- // @ts-ignore
727
- throw new Error(error.response.data.error.message, {
728
- cause: error
729
- });
730
- }
731
- throw error;
732
- }
733
- };
734
- return {
735
- createBuild: async (input)=>{
736
- return call("POST", "/builds", input);
737
- },
738
- updateBuild: async (input)=>{
739
- const { buildId, ...body } = input;
740
- return call("PUT", `/builds/${buildId}`, body);
741
- }
742
- };
743
- };
744
699
 
745
700
  const upload$1 = async (input)=>{
746
701
  const file = await readFile(input.path);
@@ -829,10 +784,6 @@ async function uploadFilesToS3(files) {
829
784
  baseUrl: config.apiBaseUrl,
830
785
  authToken
831
786
  });
832
- const legacyApiClient = createArgosLegacyAPIClient({
833
- baseUrl: config.apiBaseUrl,
834
- bearerToken: `Bearer ${authToken}`
835
- });
836
787
  // Collect screenshots
837
788
  const foundScreenshots = await discoverScreenshots(files, {
838
789
  root: params.root,
@@ -869,11 +820,11 @@ async function uploadFilesToS3(files) {
869
820
  };
870
821
  }));
871
822
  debug("Fetch project");
872
- const { data: project, error } = await apiClient.GET("/project");
873
- if (error) {
874
- throw new Error(error.error);
823
+ const projectResponse = await apiClient.GET("/project");
824
+ if (projectResponse.error) {
825
+ throw new Error(projectResponse.error.error);
875
826
  }
876
- const { defaultBaseBranch, hasRemoteContentAccess } = project;
827
+ const { defaultBaseBranch, hasRemoteContentAccess } = projectResponse.data;
877
828
  const referenceBranch = config.referenceBranch || defaultBaseBranch;
878
829
  const referenceCommit = (()=>{
879
830
  if (config.referenceCommit) {
@@ -911,24 +862,30 @@ async function uploadFilesToS3(files) {
911
862
  [],
912
863
  []
913
864
  ]);
914
- const result = await legacyApiClient.createBuild({
915
- commit: config.commit,
916
- branch: config.branch,
917
- name: config.buildName,
918
- mode: config.mode,
919
- parallel: config.parallel,
920
- parallelNonce: config.parallelNonce,
921
- screenshotKeys,
922
- pwTraceKeys,
923
- prNumber: config.prNumber,
924
- prHeadCommit: config.prHeadCommit,
925
- referenceBranch,
926
- referenceCommit,
927
- argosSdk,
928
- ciProvider: config.ciProvider,
929
- runId: config.runId,
930
- runAttempt: config.runAttempt
865
+ const createBuildResponse = await apiClient.POST("/builds", {
866
+ body: {
867
+ commit: config.commit,
868
+ branch: config.branch,
869
+ name: config.buildName,
870
+ mode: config.mode,
871
+ parallel: config.parallel,
872
+ parallelNonce: config.parallelNonce,
873
+ screenshotKeys,
874
+ pwTraceKeys,
875
+ prNumber: config.prNumber,
876
+ prHeadCommit: config.prHeadCommit,
877
+ referenceBranch,
878
+ referenceCommit,
879
+ argosSdk,
880
+ ciProvider: config.ciProvider,
881
+ runId: config.runId,
882
+ runAttempt: config.runAttempt
883
+ }
931
884
  });
885
+ if (createBuildResponse.error) {
886
+ throw new Error(createBuildResponse.error.error);
887
+ }
888
+ const result = createBuildResponse.data;
932
889
  debug("Got uploads url", result);
933
890
  const uploadFiles = [
934
891
  ...result.screenshots.map(({ key, putUrl })=>{
@@ -957,24 +914,58 @@ async function uploadFilesToS3(files) {
957
914
  await uploadFilesToS3(uploadFiles);
958
915
  // Update build
959
916
  debug("Updating build");
960
- await legacyApiClient.updateBuild({
961
- buildId: result.build.id,
962
- screenshots: screenshots.map((screenshot)=>({
963
- key: screenshot.hash,
964
- name: screenshot.name,
965
- metadata: screenshot.metadata,
966
- pwTraceKey: screenshot.pwTrace?.hash ?? null,
967
- threshold: screenshot.threshold ?? config?.threshold ?? null,
968
- baseName: screenshot.baseName
969
- })),
970
- parallel: config.parallel,
971
- parallelTotal: config.parallelTotal,
972
- parallelIndex: config.parallelIndex
917
+ const uploadBuildResponse = await apiClient.PUT("/builds/{buildId}", {
918
+ params: {
919
+ path: {
920
+ buildId: result.build.id
921
+ }
922
+ },
923
+ body: {
924
+ screenshots: screenshots.map((screenshot)=>({
925
+ key: screenshot.hash,
926
+ name: screenshot.name,
927
+ metadata: screenshot.metadata,
928
+ pwTraceKey: screenshot.pwTrace?.hash ?? null,
929
+ threshold: screenshot.threshold ?? config?.threshold ?? null,
930
+ baseName: screenshot.baseName
931
+ })),
932
+ parallel: config.parallel,
933
+ parallelTotal: config.parallelTotal,
934
+ parallelIndex: config.parallelIndex
935
+ }
973
936
  });
937
+ if (uploadBuildResponse.error) {
938
+ throw new Error(uploadBuildResponse.error.error);
939
+ }
974
940
  return {
975
- build: result.build,
941
+ build: uploadBuildResponse.data.build,
976
942
  screenshots
977
943
  };
978
944
  }
979
945
 
980
- export { readConfig, upload };
946
+ /**
947
+ * Finalize pending builds.
948
+ */ async function finalize(params) {
949
+ const config = await readConfig({
950
+ parallelNonce: params.parallel?.nonce ?? null
951
+ });
952
+ const authToken = getAuthToken(config);
953
+ const apiClient = createClient({
954
+ baseUrl: config.apiBaseUrl,
955
+ authToken
956
+ });
957
+ if (!config.parallelNonce) {
958
+ throw new Error("parallel.nonce is required to finalize the build");
959
+ }
960
+ const finalizeBuildsResult = await apiClient.POST("/builds/finalize", {
961
+ body: {
962
+ parallelNonce: config.parallelNonce
963
+ }
964
+ });
965
+ if (finalizeBuildsResult.error) {
966
+ throw new Error(finalizeBuildsResult.error.error);
967
+ }
968
+ return finalizeBuildsResult.data;
969
+ }
970
+
971
+ export { finalize, readConfig, upload };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/core",
3
3
  "description": "Visual testing solution to avoid visual regression. The core component of Argos SDK that handles build creation.",
4
- "version": "2.5.0",
4
+ "version": "2.5.2-alpha.1+fe38977",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "types": "./dist/index.d.ts",
@@ -40,8 +40,8 @@
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
- "@argos-ci/api-client": "0.2.0",
44
- "@argos-ci/util": "2.1.1",
43
+ "@argos-ci/api-client": "0.2.1-alpha.5+fe38977",
44
+ "@argos-ci/util": "2.1.2-alpha.5+fe38977",
45
45
  "axios": "^1.7.4",
46
46
  "convict": "^6.2.4",
47
47
  "debug": "^4.3.6",
@@ -60,5 +60,5 @@
60
60
  "build": "rollup -c",
61
61
  "e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
62
62
  },
63
- "gitHead": "4ca78028dd9d50f8c076ca498ea3a0b284ff4934"
63
+ "gitHead": "fe389774403ee2b9857c38c02531ed0e79d6a4fd"
64
64
  }