Skip to content

Commit

Permalink
test collapsed inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Taior committed Sep 16, 2024
1 parent ae41d28 commit e01a8d4
Show file tree
Hide file tree
Showing 39 changed files with 221 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .github/ci_templates/e2e_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ check_e2e_labels:
# <template: e2e_run_job_template>
{!{ $ctx.jobID }!}:
name: "{!{ $ctx.jobName }!}"
if: ${{ github.event.inputs.cri == '{!{ $ctx.cri }!}' && github.event.inputs.k8s_version == '{!{ $ctx.kubernetesVersion }!}' && github.event.inputs.layout == '{!{ $ctx.layout }!}' }}
if: ${{ fromJson(inputs.test_config).cri == '{!{ $ctx.cri }!}' && github.event.inputs.k8s_version == '{!{ $ctx.kubernetesVersion }!}' && github.event.inputs.layout == '{!{ $ctx.layout }!}' }}
env:
PROVIDER: {!{ $ctx.providerName }!}
CRI: {!{ $ctx.criName }!}
Expand Down
3 changes: 3 additions & 0 deletions .github/ci_templates/helper_jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ git_info:
# Skip the CI for automation PRs, e.g. changelog
if: ${{ github.event.pull_request.user.login != 'deckhouse-BOaTswain' }}
steps:
- id: print_inputs
name: Print inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- id: git_info
name: Get tag name and SHA
uses: {!{ index (ds "actions") "actions/github-script" }!}
Expand Down
99 changes: 55 additions & 44 deletions .github/scripts/js/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const {
const {
buildFailedE2eTestAdditionalInfo
} = require("./e2e/cleanup");
const {tryParseAbortE2eCluster} = require("./e2e/slash_workflow_command");
const { tryParseAbortE2eCluster } = require("./e2e/slash_workflow_command");

/**
* Update a comment in "release" issue or pull request when workflow is started.
Expand Down Expand Up @@ -196,7 +196,7 @@ module.exports.updateCommentOnFinish = async ({
} else if (statusConfig.includes(',separate')) {
statusReport = renderJobStatusSeparate(status, name, startedAt);
} else if (statusConfig.includes(',final')) {
const addInfo = buildFailedE2eTestAdditionalInfo({needsContext, core, context});
const addInfo = buildFailedE2eTestAdditionalInfo({ needsContext, core, context });
core.debug(`Additional info: ${addInfo}`);
statusReport = renderWorkflowStatusFinal(status, name, ref, build_url, startedAt, addInfo);
}
Expand Down Expand Up @@ -257,7 +257,7 @@ module.exports.updateCommentOnFinish = async ({

core.info(`Status for workflow report is ${status}`);

const addInfo = buildFailedE2eTestAdditionalInfo({needsContext, core, context});
const addInfo = buildFailedE2eTestAdditionalInfo({ needsContext, core, context });
core.debug(`Additional info: ${addInfo}`);

statusReport = renderWorkflowStatusFinal(status, name, ref, build_url, startedAt, addInfo);
Expand Down Expand Up @@ -435,16 +435,18 @@ const setCRIAndVersionsFromInputs = ({ context, core, kubernetesDefaultVersion }
let cri = [defaultCRI];
let ver = [defaultVersion];

if (!!context.payload.inputs.cri) {
const requested_cri = context.payload.inputs.cri.toLowerCase();
let test_config = JSON.parse(context.payload.inputs.test_config)

if (!!test_config.cri) {
const requested_cri = test_config.cri.toLowerCase();
cri = requested_cri.split(',');
}
if (!!context.payload.inputs.ver) {
const requested_ver = context.payload.inputs.ver.replace(/\./g, '_');
if (!!test_config.ver) {
const requested_ver = test_config.ver.replace(/\./g, '_');
ver = requested_ver.split(',');
}

core.info(`workflow_dispatch is release related. e2e inputs: cri='${context.payload.inputs.cri}' and version='${context.payload.inputs.ver}'.`);
core.info(`workflow_dispatch is release related. e2e inputs: cri='${test_config.cri}' and version='${test_config.ver}'.`);

for (const out_cri of cri) {
for (const out_ver of ver) {
Expand Down Expand Up @@ -594,18 +596,18 @@ const extractCommandFromComment = (comment) => {
// Split comment to lines.
const lines = comment.split(/\r\n|\n|\r/).filter(l => l.startsWith('/'));
if (lines.length < 1) {
return {'err': 'first line is not a slash command'}
return { 'err': 'first line is not a slash command' }
}

// Search for user command in the first line of the comment.
// User command is a command and a tag name.
const argv = lines[0].split(/\s+/);

if ( ! /^\/[a-z\d_\-\/.,]+$/.test(argv[0])) {
return {'err': 'not a slash command in the first line'};
if (! /^\/[a-z\d_\-\/.,]+$/.test(argv[0])) {
return { 'err': 'not a slash command in the first line' };
}

return {argv, lines}
return { argv, lines }
};

module.exports.extractCommandFromComment = extractCommandFromComment;
Expand Down Expand Up @@ -633,7 +635,7 @@ const parseCommandArgumentAsRef = (cmdArg) => {
if (ref) {
return parseGitRef(ref);
}
return {notFoundMsg: `git_ref ${cmdArg} not allowed. Only main, release-X.Y, vX.Y.Z or test-vX.Y.Z.`};
return { notFoundMsg: `git_ref ${cmdArg} not allowed. Only main, release-X.Y, vX.Y.Z or test-vX.Y.Z.` };
};

/**
Expand All @@ -653,10 +655,10 @@ const parseCommandArgumentAsRef = (cmdArg) => {
* @param {object} inputs.core - A reference to the '@actions/core' package.
* @returns {object}
*/
const detectSlashCommand = ({ comment , context, core}) => {
const detectSlashCommand = ({ comment, context, core }) => {
const arg = extractCommandFromComment(comment);
if(arg.err) {
return {notFoundMsg: arg.err}
if (arg.err) {
return { notFoundMsg: arg.err }
}

const parts = arg.argv;
Expand All @@ -668,9 +670,9 @@ const detectSlashCommand = ({ comment , context, core}) => {
// A ref for workflow and a target ref for e2e release update test.
let targetRef = null

const abortRes = tryParseAbortE2eCluster({argv: arg.argv, context, core})
const abortRes = tryParseAbortE2eCluster({ argv: arg.argv, context, core })
if (abortRes !== null) {
return {...abortRes, command}
return { ...abortRes, command }
}


Expand All @@ -694,7 +696,7 @@ const detectSlashCommand = ({ comment , context, core}) => {
// Detect /e2e/run/* commands and /e2e/use/* arguments.
const isE2E = Object.entries(knownLabels)
.some(([name, info]) => {
return info.type.startsWith('e2e') && command.startsWith('/'+name)
return info.type.startsWith('e2e') && command.startsWith('/' + name)
})
if (isE2E) {
for (const provider of knownProviders) {
Expand All @@ -720,8 +722,7 @@ const detectSlashCommand = ({ comment , context, core}) => {
}

inputs = {
cri: cri.join(','),
ver: ver.join(','),
test_config: JSON.stringify({ cri: cri.join(','), ver: ver.join(','), editions: "FE" }),
}

// Add initial_ref_slug input when e2e command has two args.
Expand All @@ -732,10 +733,10 @@ const detectSlashCommand = ({ comment , context, core}) => {
}

// Detect /deploy/* commands.
const isDeploy = knownSlashCommands.deploy.some(c => command.startsWith('/'+c));
const isDeploy = knownSlashCommands.deploy.some(c => command.startsWith('/' + c));
if (isDeploy) {
for (const channel of knownChannels) {
if (command.includes('/'+channel)) {
if (command.includes('/' + channel)) {
workflow_id = `deploy-${channel}.yml`;
break;
}
Expand All @@ -750,7 +751,7 @@ const detectSlashCommand = ({ comment , context, core}) => {
}

// Detect /suspend/* commands.
const isSuspend = knownSlashCommands.suspend.some(c => command.startsWith('/'+c));
const isSuspend = knownSlashCommands.suspend.some(c => command.startsWith('/' + c));
if (isSuspend) {
for (const channel of knownChannels) {
if (command.includes(channel)) {
Expand All @@ -774,7 +775,7 @@ const detectSlashCommand = ({ comment , context, core}) => {
}

if (workflow_id === '') {
return {notFoundMsg: `workflow for '${command}' not found`};
return { notFoundMsg: `workflow for '${command}' not found` };
}

return {
Expand All @@ -799,7 +800,7 @@ const detectSlashCommand = ({ comment , context, core}) => {
* @param {object} inputs.content - Reaction type: (+1, -1, rocket, confused, ...).
* @returns {Promise<void|*>}
*/
const reactToComment = async ({github, context, comment_id, content}) => {
const reactToComment = async ({ github, context, comment_id, content }) => {
return await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down Expand Up @@ -862,20 +863,20 @@ module.exports.runSlashCommandForReleaseIssue = async ({ github, context, core }
} else {
failedMsg = `Command '${slashCommand.command}' requires issue to relate to milestone with version in title. Got milestone '${event.issue.milestone.title}'.`
}
} else if(slashCommand.isDestroyFailedE2e) {
} else if (slashCommand.isDestroyFailedE2e) {
workflow_ref = slashCommand.targetRef;
}

// Git ref is malformed.
if (failedMsg) {
core.setFailed(failedMsg);
return await reactToComment({github, context, comment_id, content: 'confused'});
return await reactToComment({ github, context, comment_id, content: 'confused' });
}

core.info(`Use ref '${workflow_ref}' for workflow.`);

// React with rocket emoji!
await reactToComment({github, context, comment_id, content: 'rocket'});
await reactToComment({ github, context, comment_id, content: 'rocket' });

// Add new issue comment and start the requested workflow.
core.info('Add issue comment to report workflow status.');
Expand Down Expand Up @@ -903,7 +904,8 @@ module.exports.runSlashCommandForReleaseIssue = async ({ github, context, core }
}
}

return await startWorkflow({github, context, core,
return await startWorkflow({
github, context, core,
workflow_id: slashCommand.workflow_id,
ref: workflow_ref,
inputs: {
Expand Down Expand Up @@ -1286,10 +1288,10 @@ const findMilestoneForGitRef = async ({ github, context, core, gitRefInfo }) =>
} catch (error) {
if (error.name === 'GraphqlResponseError') {
core.log('Request:', error.request);
return {notFoundMsg: error.message}
return { notFoundMsg: error.message }
} else {
// handle non-GraphQL error
return {notFoundMsg: `List milestones failed: ${dumpError(error)}`}
return { notFoundMsg: `List milestones failed: ${dumpError(error)}` }
}
}

Expand All @@ -1315,7 +1317,7 @@ const findMilestoneForGitRef = async ({ github, context, core, gitRefInfo }) =>

if (!milestone) {
core.info(`Milestones: ${JSON.stringify(result)}`);
return {notFoundMsg: `No related milestone found for ref '${context.ref}'. You should create milestone related to a tag and restart build.`}
return { notFoundMsg: `No related milestone found for ref '${context.ref}'. You should create milestone related to a tag and restart build.` }
}

core.info(`Found milestone related to ref '${context.ref}': '${milestone.title}' with number ${milestone.number}`);
Expand All @@ -1335,7 +1337,7 @@ const findReleaseIssueForMilestone = async ({ github, context, core, milestone }
labels: [releaseIssueLabel]
});
if (response.status !== 200 || response.data.length < 1) {
return {notFoundMsg: `List milestone issues failed: ${JSON.stringify(response)}`};
return { notFoundMsg: `List milestone issues failed: ${JSON.stringify(response)}` };
}

return response.data[0];
Expand Down Expand Up @@ -1399,7 +1401,7 @@ const startWorkflow = async ({ github, context, core, workflow_id, ref, inputs }
ref,
inputs: inputs || {},
});
} catch(error) {
} catch (error) {
return core.setFailed(`Error triggering workflow_dispatch event: ${dumpError(error)}`)
}

Expand Down Expand Up @@ -1427,9 +1429,11 @@ module.exports.runBuildForRelease = async ({ github, context, core }) => {

// Run workflow without commenting on release issue.
if (gitRefInfo.isDeveloperTag) {
return await startWorkflow({github, context, core,
return await startWorkflow({
github, context, core,
workflow_id: 'build-and-test_release.yml',
ref: context.ref});
ref: context.ref
});
}

if (gitRefInfo.isMain || gitRefInfo.tagVersion) {
Expand All @@ -1438,24 +1442,31 @@ module.exports.runBuildForRelease = async ({ github, context, core }) => {
// - find milestone
// - find release issue
// - add comment and start the workflow.
const milestone = await findMilestoneForGitRef({github, context, core,
gitRefInfo});
const milestone = await findMilestoneForGitRef({
github, context, core,
gitRefInfo
});
if (milestone.notFoundMsg) {
return core.setFailed(milestone.notFoundMsg);
}

const releaseIssue = await findReleaseIssueForMilestone({github, context, core,
milestone});
const releaseIssue = await findReleaseIssueForMilestone({
github, context, core,
milestone
});
if (releaseIssue.notFoundMsg) {
return core.setFailed(releaseIssue.notFoundMsg);
}

const commentInfo = await addReleaseIssueComment({github, context, core,
issue: releaseIssue, gitRefInfo});
const commentInfo = await addReleaseIssueComment({
github, context, core,
issue: releaseIssue, gitRefInfo
});

core.info(`Start build-and-test for ${gitRefInfo.description} '${context.ref}'...`);

return await startWorkflow({github, context, core,
return await startWorkflow({
github, context, core,
workflow_id: 'build-and-test_release.yml',
ref: context.ref,
inputs: {
Expand Down
8 changes: 3 additions & 5 deletions .github/workflow_templates/e2e.multi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,10 @@ on:
pull_request_head_label:
description: 'Head label of pull request. e.g. my_repo:my_feature_branch'
required: false
cri:
description: 'A comma-separated list of cri to test. Available: Containerd.'
required: false
ver:
description: 'A comma-separated list of versions to test. Available: from 1.24 to 1.28.'
test_config:
description: 'JSON string of parameters of current test'
required: false
default: '{"cri":"Containerd","ver":"1.27","editions":"FE"}'
initial_ref_slug:
description: 'An image tag to install first and then switch to workflow context ref'
required: false
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-and-test_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ jobs:
# Skip the CI for automation PRs, e.g. changelog
if: ${{ github.event.pull_request.user.login != 'deckhouse-BOaTswain' }}
steps:
- id: print_inputs
name: Print inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- id: git_info
name: Get tag name and SHA
uses: actions/github-script@v6.4.1
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-and-test_pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ jobs:
# Skip the CI for automation PRs, e.g. changelog
if: ${{ github.event.pull_request.user.login != 'deckhouse-BOaTswain' }}
steps:
- id: print_inputs
name: Print inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- id: git_info
name: Get tag name and SHA
uses: actions/github-script@v6.4.1
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-and-test_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ jobs:
# Skip the CI for automation PRs, e.g. changelog
if: ${{ github.event.pull_request.user.login != 'deckhouse-BOaTswain' }}
steps:
- id: print_inputs
name: Print inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- id: git_info
name: Get tag name and SHA
uses: actions/github-script@v6.4.1
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deploy-alpha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ jobs:
# Skip the CI for automation PRs, e.g. changelog
if: ${{ github.event.pull_request.user.login != 'deckhouse-BOaTswain' }}
steps:
- id: print_inputs
name: Print inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- id: git_info
name: Get tag name and SHA
uses: actions/github-script@v6.4.1
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deploy-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ jobs:
# Skip the CI for automation PRs, e.g. changelog
if: ${{ github.event.pull_request.user.login != 'deckhouse-BOaTswain' }}
steps:
- id: print_inputs
name: Print inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- id: git_info
name: Get tag name and SHA
uses: actions/github-script@v6.4.1
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deploy-early-access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ jobs:
# Skip the CI for automation PRs, e.g. changelog
if: ${{ github.event.pull_request.user.login != 'deckhouse-BOaTswain' }}
steps:
- id: print_inputs
name: Print inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- id: git_info
name: Get tag name and SHA
uses: actions/github-script@v6.4.1
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deploy-rock-solid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ jobs:
# Skip the CI for automation PRs, e.g. changelog
if: ${{ github.event.pull_request.user.login != 'deckhouse-BOaTswain' }}
steps:
- id: print_inputs
name: Print inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- id: git_info
name: Get tag name and SHA
uses: actions/github-script@v6.4.1
Expand Down
Loading

0 comments on commit e01a8d4

Please sign in to comment.