@argos-ci/gitlab 0.0.1-alpha.347
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/LICENSE +7 -0
- package/README.md +15 -0
- package/bin/argos-gitlab.js +3 -0
- package/dist/cli.mjs +108 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.mjs +87 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2022 Smooth Code
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://argos-ci.com/?utm_source=github&utm_medium=logo" target="_blank">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/argos-ci/argos/main/resources/logos/logo-github-readme.png" alt="Argos" width="300" height="61">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
_Argos is a visual testing solution that fits in your workflow to avoid visual regression. Takes screenshots on each commit and be notified if something changes._
|
|
8
|
+
|
|
9
|
+
# Argos GitLab
|
|
10
|
+
|
|
11
|
+
Argos GitLab utilities to setup GitLab in self-hosted mode.
|
|
12
|
+
|
|
13
|
+
[](https://www.npmjs.com/package/@argos-ci/gitlab)
|
|
14
|
+
[](https://www.npmjs.com/package/@argos-ci/gitlab)
|
|
15
|
+
[](https://www.npmjs.com/package/@argos-ci/gitlab)
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { program } from 'commander';
|
|
5
|
+
import { createClient } from '@argos-ci/api-client';
|
|
6
|
+
import { Gitlab } from '@gitbeaker/rest';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Run the main logic of the action.
|
|
10
|
+
*/ async function run(input) {
|
|
11
|
+
const { argosClient, gitlabClient, gitlabProjectId, pullInterval, commit } = input;
|
|
12
|
+
const { data, error } = await argosClient.GET("/project/builds", {
|
|
13
|
+
params: {
|
|
14
|
+
query: {
|
|
15
|
+
distinctName: "true",
|
|
16
|
+
commit
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
if (error) {
|
|
21
|
+
console.error(error);
|
|
22
|
+
throw new Error(error.error);
|
|
23
|
+
}
|
|
24
|
+
if (data.results.length === 0) {
|
|
25
|
+
console.log("No builds found for commit", commit);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
await Promise.all(data.results.map(async (build)=>{
|
|
29
|
+
if (build.notification) {
|
|
30
|
+
console.log(`Setting status for build #${build.number}: "${build.status}" (Argos) → "${build.notification.gitlab.state}" (GitLab)`);
|
|
31
|
+
await gitlabClient.Commits.editStatus(gitlabProjectId, commit, build.notification.gitlab.state, {
|
|
32
|
+
context: build.notification.context,
|
|
33
|
+
targetUrl: build.url,
|
|
34
|
+
description: build.notification.description
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
if (data.results.some((build)=>build.status === "pending" || build.status === "progress")) {
|
|
39
|
+
await new Promise((resolve)=>setTimeout(resolve, pullInterval));
|
|
40
|
+
run(input);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Upate GitLab commit statuses based on Argos builds.
|
|
45
|
+
*/ async function updateGitLabCommitStatuses(input) {
|
|
46
|
+
const argos = createClient({
|
|
47
|
+
authToken: input.argosToken
|
|
48
|
+
});
|
|
49
|
+
const gitlab = new Gitlab({
|
|
50
|
+
oauthToken: input.gitlab.authToken,
|
|
51
|
+
host: input.gitlab.baseUrl
|
|
52
|
+
});
|
|
53
|
+
await run({
|
|
54
|
+
argosClient: argos,
|
|
55
|
+
gitlabClient: gitlab,
|
|
56
|
+
gitlabProjectId: input.gitlab.projectId,
|
|
57
|
+
commit: input.commit,
|
|
58
|
+
pullInterval: input.pullInterval ?? 3000
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get the configuration from the environment variables.
|
|
64
|
+
*/ function getConfig() {
|
|
65
|
+
if (!process.env.CI_PROJECT_ID) {
|
|
66
|
+
throw new Error("CI_PROJECT_ID is not set");
|
|
67
|
+
}
|
|
68
|
+
if (!process.env.CI_SERVER_URL) {
|
|
69
|
+
throw new Error("CI_SERVER_URL is not set");
|
|
70
|
+
}
|
|
71
|
+
if (!process.env.CI_COMMIT_SHA) {
|
|
72
|
+
throw new Error("CI_COMMIT_SHA is not set");
|
|
73
|
+
}
|
|
74
|
+
if (!process.env.GITLAB_TOKEN) {
|
|
75
|
+
throw new Error("GITLAB_TOKEN is not set");
|
|
76
|
+
}
|
|
77
|
+
if (!process.env.ARGOS_TOKEN) {
|
|
78
|
+
throw new Error("ARGOS_TOKEN is not set");
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
commit: process.env.CI_COMMIT_SHA,
|
|
82
|
+
argosToken: process.env.ARGOS_TOKEN,
|
|
83
|
+
gitlab: {
|
|
84
|
+
projectId: process.env.CI_PROJECT_ID,
|
|
85
|
+
authToken: process.env.GITLAB_TOKEN,
|
|
86
|
+
baseUrl: process.env.CI_SERVER_URL
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
|
92
|
+
const rawPkg = await readFile(resolve(__dirname, "..", "package.json"), "utf8");
|
|
93
|
+
const pkg = JSON.parse(rawPkg);
|
|
94
|
+
program.name(pkg.name).description("Run Argos GitLab commands from the command line.").version(pkg.version);
|
|
95
|
+
program.command("update-statuses").description("Update GitLab commit statuses based on Argos builds.").action(async ()=>{
|
|
96
|
+
const config = getConfig();
|
|
97
|
+
try {
|
|
98
|
+
await updateGitLabCommitStatuses(config);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error(error.stack);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
if (!process.argv.slice(2).length) {
|
|
105
|
+
program.outputHelp();
|
|
106
|
+
} else {
|
|
107
|
+
program.parse(process.argv);
|
|
108
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upate GitLab commit statuses based on Argos builds.
|
|
3
|
+
*/
|
|
4
|
+
declare function updateGitLabCommitStatuses(input: {
|
|
5
|
+
commit: string;
|
|
6
|
+
pullInterval?: number;
|
|
7
|
+
argosToken: string;
|
|
8
|
+
gitlab: {
|
|
9
|
+
projectId: string;
|
|
10
|
+
authToken: string;
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
};
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Get the configuration from the environment variables.
|
|
16
|
+
*/
|
|
17
|
+
declare function getConfig(): {
|
|
18
|
+
commit: string;
|
|
19
|
+
argosToken: string;
|
|
20
|
+
gitlab: {
|
|
21
|
+
projectId: string;
|
|
22
|
+
authToken: string;
|
|
23
|
+
baseUrl: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export { updateGitLabCommitStatuses, getConfig };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createClient } from '@argos-ci/api-client';
|
|
2
|
+
import { Gitlab } from '@gitbeaker/rest';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Run the main logic of the action.
|
|
6
|
+
*/ async function run(input) {
|
|
7
|
+
const { argosClient, gitlabClient, gitlabProjectId, pullInterval, commit } = input;
|
|
8
|
+
const { data, error } = await argosClient.GET("/project/builds", {
|
|
9
|
+
params: {
|
|
10
|
+
query: {
|
|
11
|
+
distinctName: "true",
|
|
12
|
+
commit
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if (error) {
|
|
17
|
+
console.error(error);
|
|
18
|
+
throw new Error(error.error);
|
|
19
|
+
}
|
|
20
|
+
if (data.results.length === 0) {
|
|
21
|
+
console.log("No builds found for commit", commit);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
await Promise.all(data.results.map(async (build)=>{
|
|
25
|
+
if (build.notification) {
|
|
26
|
+
console.log(`Setting status for build #${build.number}: "${build.status}" (Argos) → "${build.notification.gitlab.state}" (GitLab)`);
|
|
27
|
+
await gitlabClient.Commits.editStatus(gitlabProjectId, commit, build.notification.gitlab.state, {
|
|
28
|
+
context: build.notification.context,
|
|
29
|
+
targetUrl: build.url,
|
|
30
|
+
description: build.notification.description
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}));
|
|
34
|
+
if (data.results.some((build)=>build.status === "pending" || build.status === "progress")) {
|
|
35
|
+
await new Promise((resolve)=>setTimeout(resolve, pullInterval));
|
|
36
|
+
run(input);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Upate GitLab commit statuses based on Argos builds.
|
|
41
|
+
*/ async function updateGitLabCommitStatuses(input) {
|
|
42
|
+
const argos = createClient({
|
|
43
|
+
authToken: input.argosToken
|
|
44
|
+
});
|
|
45
|
+
const gitlab = new Gitlab({
|
|
46
|
+
oauthToken: input.gitlab.authToken,
|
|
47
|
+
host: input.gitlab.baseUrl
|
|
48
|
+
});
|
|
49
|
+
await run({
|
|
50
|
+
argosClient: argos,
|
|
51
|
+
gitlabClient: gitlab,
|
|
52
|
+
gitlabProjectId: input.gitlab.projectId,
|
|
53
|
+
commit: input.commit,
|
|
54
|
+
pullInterval: input.pullInterval ?? 3000
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get the configuration from the environment variables.
|
|
60
|
+
*/ function getConfig() {
|
|
61
|
+
if (!process.env.CI_PROJECT_ID) {
|
|
62
|
+
throw new Error("CI_PROJECT_ID is not set");
|
|
63
|
+
}
|
|
64
|
+
if (!process.env.CI_SERVER_URL) {
|
|
65
|
+
throw new Error("CI_SERVER_URL is not set");
|
|
66
|
+
}
|
|
67
|
+
if (!process.env.CI_COMMIT_SHA) {
|
|
68
|
+
throw new Error("CI_COMMIT_SHA is not set");
|
|
69
|
+
}
|
|
70
|
+
if (!process.env.GITLAB_TOKEN) {
|
|
71
|
+
throw new Error("GITLAB_TOKEN is not set");
|
|
72
|
+
}
|
|
73
|
+
if (!process.env.ARGOS_TOKEN) {
|
|
74
|
+
throw new Error("ARGOS_TOKEN is not set");
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
commit: process.env.CI_COMMIT_SHA,
|
|
78
|
+
argosToken: process.env.ARGOS_TOKEN,
|
|
79
|
+
gitlab: {
|
|
80
|
+
projectId: process.env.CI_PROJECT_ID,
|
|
81
|
+
authToken: process.env.GITLAB_TOKEN,
|
|
82
|
+
baseUrl: process.env.CI_SERVER_URL
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { getConfig, updateGitLabCommitStatuses };
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@argos-ci/gitlab",
|
|
3
|
+
"description": "GitLab utilities for Argos.",
|
|
4
|
+
"version": "0.0.1-alpha.347+294bbba",
|
|
5
|
+
"author": "Smooth Code",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/argos-ci/argos-javascript.git",
|
|
10
|
+
"directory": "packages/gitlab"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"browser",
|
|
14
|
+
"argos",
|
|
15
|
+
"automation",
|
|
16
|
+
"test automation",
|
|
17
|
+
"testing",
|
|
18
|
+
"visual testing",
|
|
19
|
+
"regression",
|
|
20
|
+
"visual regression"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"bin": {
|
|
27
|
+
"argos": "./bin/argos-gitlab.js"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.mjs",
|
|
33
|
+
"default": "./dist/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18.0.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"prebuild": "rm -rf dist",
|
|
43
|
+
"build": "rollup -c"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@argos-ci/api-client": "0.0.0",
|
|
47
|
+
"@gitbeaker/rest": "^40.0.3",
|
|
48
|
+
"commander": "^12.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^18.0.0"
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "294bbba6b1d3e757aa436af9f4f8ac6f684424a7"
|
|
54
|
+
}
|