@argos-ci/core 2.5.1 → 2.6.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.
- package/dist/index.d.ts +39 -1
- package/dist/index.mjs +82 -90
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -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
|
@@ -536,7 +536,7 @@ const schema = {
|
|
|
536
536
|
},
|
|
537
537
|
parallelTotal: {
|
|
538
538
|
env: "ARGOS_PARALLEL_TOTAL",
|
|
539
|
-
format: "
|
|
539
|
+
format: "int",
|
|
540
540
|
default: null,
|
|
541
541
|
nullable: true
|
|
542
542
|
},
|
|
@@ -614,8 +614,8 @@ async function readConfig(options = {}) {
|
|
|
614
614
|
runAttempt: ciEnv?.runAttempt || null,
|
|
615
615
|
parallel: options.parallel ?? config.get("parallel") ?? false,
|
|
616
616
|
parallelNonce: options.parallelNonce || config.get("parallelNonce") || ciEnv?.nonce || null,
|
|
617
|
-
parallelTotal: options.parallelTotal
|
|
618
|
-
parallelIndex: options.parallelIndex
|
|
617
|
+
parallelTotal: options.parallelTotal ?? config.get("parallelTotal") ?? null,
|
|
618
|
+
parallelIndex: options.parallelIndex ?? config.get("parallelIndex") ?? null,
|
|
619
619
|
mode: options.mode || config.get("mode") || null,
|
|
620
620
|
ciProvider: ciEnv?.key || null
|
|
621
621
|
});
|
|
@@ -672,7 +672,9 @@ const hashFile = async (filepath)=>{
|
|
|
672
672
|
};
|
|
673
673
|
|
|
674
674
|
const base64Encode = (obj)=>Buffer.from(JSON.stringify(obj), "utf8").toString("base64");
|
|
675
|
-
|
|
675
|
+
/**
|
|
676
|
+
* Get the authentication token.
|
|
677
|
+
*/ function getAuthToken({ token, ciProvider, owner, repository, jobId, runId, prNumber }) {
|
|
676
678
|
if (token) {
|
|
677
679
|
return token;
|
|
678
680
|
}
|
|
@@ -694,52 +696,6 @@ function getAuthToken({ token, ciProvider, owner, repository, jobId, runId, prNu
|
|
|
694
696
|
throw new Error("Missing Argos repository token 'ARGOS_TOKEN'");
|
|
695
697
|
}
|
|
696
698
|
}
|
|
697
|
-
const createArgosLegacyAPIClient = (options)=>{
|
|
698
|
-
const axiosInstance = axios.create({
|
|
699
|
-
baseURL: options.baseUrl,
|
|
700
|
-
headers: {
|
|
701
|
-
Authorization: options.bearerToken,
|
|
702
|
-
"Content-Type": "application/json",
|
|
703
|
-
Accept: "application/json"
|
|
704
|
-
}
|
|
705
|
-
});
|
|
706
|
-
const call = async (method, path, data)=>{
|
|
707
|
-
try {
|
|
708
|
-
debug("Sending request", {
|
|
709
|
-
method,
|
|
710
|
-
path,
|
|
711
|
-
data
|
|
712
|
-
});
|
|
713
|
-
const response = await axiosInstance.request({
|
|
714
|
-
method,
|
|
715
|
-
url: path,
|
|
716
|
-
data
|
|
717
|
-
});
|
|
718
|
-
debug("Getting response", {
|
|
719
|
-
status: response.status,
|
|
720
|
-
data: response.data
|
|
721
|
-
});
|
|
722
|
-
return response.data;
|
|
723
|
-
} catch (error) {
|
|
724
|
-
if (error?.response?.data?.error?.message) {
|
|
725
|
-
// @ts-ignore
|
|
726
|
-
throw new Error(error.response.data.error.message, {
|
|
727
|
-
cause: error
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
throw error;
|
|
731
|
-
}
|
|
732
|
-
};
|
|
733
|
-
return {
|
|
734
|
-
createBuild: async (input)=>{
|
|
735
|
-
return call("POST", "/builds", input);
|
|
736
|
-
},
|
|
737
|
-
updateBuild: async (input)=>{
|
|
738
|
-
const { buildId, ...body } = input;
|
|
739
|
-
return call("PUT", `/builds/${buildId}`, body);
|
|
740
|
-
}
|
|
741
|
-
};
|
|
742
|
-
};
|
|
743
699
|
|
|
744
700
|
const upload$1 = async (input)=>{
|
|
745
701
|
const file = await readFile(input.path);
|
|
@@ -828,10 +784,6 @@ async function uploadFilesToS3(files) {
|
|
|
828
784
|
baseUrl: config.apiBaseUrl,
|
|
829
785
|
authToken
|
|
830
786
|
});
|
|
831
|
-
const legacyApiClient = createArgosLegacyAPIClient({
|
|
832
|
-
baseUrl: config.apiBaseUrl,
|
|
833
|
-
bearerToken: `Bearer ${authToken}`
|
|
834
|
-
});
|
|
835
787
|
// Collect screenshots
|
|
836
788
|
const foundScreenshots = await discoverScreenshots(files, {
|
|
837
789
|
root: params.root,
|
|
@@ -868,11 +820,11 @@ async function uploadFilesToS3(files) {
|
|
|
868
820
|
};
|
|
869
821
|
}));
|
|
870
822
|
debug("Fetch project");
|
|
871
|
-
const
|
|
872
|
-
if (error) {
|
|
873
|
-
throw new Error(error.error);
|
|
823
|
+
const projectResponse = await apiClient.GET("/project");
|
|
824
|
+
if (projectResponse.error) {
|
|
825
|
+
throw new Error(projectResponse.error.error);
|
|
874
826
|
}
|
|
875
|
-
const { defaultBaseBranch, hasRemoteContentAccess } =
|
|
827
|
+
const { defaultBaseBranch, hasRemoteContentAccess } = projectResponse.data;
|
|
876
828
|
const referenceBranch = config.referenceBranch || defaultBaseBranch;
|
|
877
829
|
const referenceCommit = (()=>{
|
|
878
830
|
if (config.referenceCommit) {
|
|
@@ -910,24 +862,30 @@ async function uploadFilesToS3(files) {
|
|
|
910
862
|
[],
|
|
911
863
|
[]
|
|
912
864
|
]);
|
|
913
|
-
const
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
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
|
+
}
|
|
930
884
|
});
|
|
885
|
+
if (createBuildResponse.error) {
|
|
886
|
+
throw new Error(createBuildResponse.error.error);
|
|
887
|
+
}
|
|
888
|
+
const result = createBuildResponse.data;
|
|
931
889
|
debug("Got uploads url", result);
|
|
932
890
|
const uploadFiles = [
|
|
933
891
|
...result.screenshots.map(({ key, putUrl })=>{
|
|
@@ -956,24 +914,58 @@ async function uploadFilesToS3(files) {
|
|
|
956
914
|
await uploadFilesToS3(uploadFiles);
|
|
957
915
|
// Update build
|
|
958
916
|
debug("Updating build");
|
|
959
|
-
await
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
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
|
+
}
|
|
972
936
|
});
|
|
937
|
+
if (uploadBuildResponse.error) {
|
|
938
|
+
throw new Error(uploadBuildResponse.error.error);
|
|
939
|
+
}
|
|
973
940
|
return {
|
|
974
|
-
build:
|
|
941
|
+
build: uploadBuildResponse.data.build,
|
|
975
942
|
screenshots
|
|
976
943
|
};
|
|
977
944
|
}
|
|
978
945
|
|
|
979
|
-
|
|
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.
|
|
4
|
+
"version": "2.6.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@argos-ci/api-client": "0.
|
|
43
|
+
"@argos-ci/api-client": "0.3.0",
|
|
44
44
|
"@argos-ci/util": "2.1.1",
|
|
45
45
|
"axios": "^1.7.4",
|
|
46
46
|
"convict": "^6.2.4",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"build": "rollup -c",
|
|
61
61
|
"e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "fd9935c114e6a948eca173127947cebcf6381007"
|
|
64
64
|
}
|