Skip to content

Commit a040a33

Browse files
committed
feat(ci): add automatic e2e tests
Signed-off-by: Maksim Fedotov <maksim.fedotov@flant.com>
1 parent 497d17b commit a040a33

5 files changed

Lines changed: 617 additions & 1 deletion

File tree

.github/scripts/js/ci.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
* @returns {object}
2626
*/
2727

28+
const {
29+
userClusterLabels
30+
} = require('./constants');
2831
const { dumpError } = require('./error');
2932
const extractCommandFromComment = (comment) => {
3033
// Split comment to lines.
@@ -65,6 +68,31 @@ const reactToComment = async ({github, context, comment_id, content}) => {
6568
});
6669
};
6770
module.exports.reactToComment = reactToComment;
71+
72+
const checkUserClusterLabel = async ({prLabels}) => {
73+
const userLabelsInPR = prLabels
74+
.map(label => label.name)
75+
.filter(labelName => userClusterLabels[labelName]);
76+
return userLabelsInPR;
77+
};
78+
module.exports.checkUserClusterLabel = checkUserClusterLabel;
79+
80+
const getClusterUser = async ({context, core}) => {
81+
const prLabels = context.payload.pull_request.labels;
82+
let userLabelsInPR = await checkUserClusterLabel({prLabels});
83+
if (userLabelsInPR.length === 0) {
84+
core.info('No user labels found in PR, using PR author\'s cluster');
85+
const prAuthorId = context.payload.pull_request.user.id;
86+
core.info(`PR author: ${prAuthorId}`);
87+
return prAuthorId.toString();
88+
// const authorLabel = [{'name': `e2e/user/${prAuthor}`}];
89+
// retry check for PR author's cluster label
90+
} else if (userLabelsInPR.length > 1) {
91+
return core.setFailed(`Error: PR has multiple user labels: ${userLabelsInPR.join(', ')}`);
92+
}
93+
return userClusterLabels[userLabelsInPR].id
94+
};
95+
module.exports.getClusterUser = getClusterUser;
6896

6997
/**
7098
* Start workflow using workflow_dispatch event.

.github/scripts/js/constants.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright 2022 Flant JSC
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
12+
//@ts-check
13+
14+
const skipE2eLabel = 'skip/e2e';
15+
const abortFailedE2eCommand = '/e2e/abort';
16+
module.exports.skipE2eLabel = skipE2eLabel;
17+
module.exports.abortFailedE2eCommand = abortFailedE2eCommand;
18+
19+
// Labels available for pull requests.
20+
const labels = {
21+
// E2E
22+
'e2e/run': { type: 'e2e-run', provider: 'static' },
23+
// Allow running workflows for external PRs.
24+
'status/ok-to-test': { type: 'ok-to-test' },
25+
26+
};
27+
module.exports.knownLabels = labels;
28+
const userClusterLables = {
29+
'e2e/user/nevermarine' : { type: 'e2e-user', id: '72984806'},
30+
'e2e/user/Isteb4k' : { type: 'e2e-user', id: '93128416'}
31+
};
32+
module.exports.userClusterLabels = userClusterLables;
33+
34+
// Label to detect if issue is a release issue.
35+
const releaseIssueLabel = 'issue/release';
36+
module.exports.releaseIssueLabel = releaseIssueLabel;
37+
38+
const slashCommands = {
39+
deploy: ['deploy/alpha', 'deploy/beta', 'deploy/early-access', 'deploy/stable', 'deploy/rock-solid'],
40+
suspend: ['suspend/alpha', 'suspend/beta', 'suspend/early-access', 'suspend/stable', 'suspend/rock-solid']
41+
};
42+
module.exports.knownSlashCommands = slashCommands;
43+
44+
module.exports.labelsSrv = {
45+
/**
46+
* Search for known label name using its type and property:
47+
* - search by provider property for e2e-run labels
48+
* - search by env property for deploy-web labels
49+
*
50+
* @param {object} inputs
51+
* @param {string} inputs.labelType
52+
* @param {string} inputs.labelSubject
53+
* @returns {string}
54+
*/
55+
findLabel: ({ labelType, labelSubject }) => {
56+
return (Object.entries(labels).find(([name, info]) => {
57+
if (info.type === labelType) {
58+
if (labelType === 'e2e-run') {
59+
return info.provider === labelSubject;
60+
}
61+
if (labelType === 'deploy-web') {
62+
return info.env === labelSubject;
63+
}
64+
65+
return true;
66+
}
67+
return false;
68+
}) || [''])[0];
69+
}
70+
};
71+
72+
// Providers for e2e tests.
73+
const providers = Object.entries(labels)
74+
.filter(([name, info]) => info.type === 'e2e-run')
75+
.map(([name, info]) => info.provider)
76+
.sort();
77+
module.exports.knownProviders = providers;
78+
79+
// Channels available for deploy.
80+
const channels = [
81+
//
82+
'alpha',
83+
'beta',
84+
'early-access',
85+
'stable',
86+
'rock-solid'
87+
];
88+
89+
module.exports.knownChannels = channels;
90+
91+
const criNames = Object.entries(labels)
92+
.filter(([name, info]) => info.type === 'e2e-use' && !!info.cri)
93+
.map(([name, info]) => info.cri);
94+
module.exports.knownCRINames = criNames;
95+
96+
const kubernetesVersions = Object.entries(labels)
97+
.filter(([name, info]) => info.type === 'e2e-use' && !!info.ver)
98+
.map(([name, info]) => info.ver)
99+
.sort();
100+
module.exports.knownKubernetesVersions = kubernetesVersions;
101+
102+
module.exports.e2eDefaults = {
103+
criName: 'Containerd',
104+
edition: 'FE',
105+
multimaster: false,
106+
cis: false
107+
};
108+
109+
const editions = ['CE', 'EE', 'FE', 'BE', 'SE', 'SE-plus'];
110+
module.exports.knownEditions = editions;

0 commit comments

Comments
 (0)