Skip to content

Commit

Permalink
mapping_error fixed (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ginxo authored Aug 26, 2020
1 parent 5c47fe1 commit 641353f
Show file tree
Hide file tree
Showing 8 changed files with 498 additions and 54 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ This is a github action limitation already reported as a suggestion to provide f
It's not possible to use expressions like `image: "docker://kie-group:github-action-build-chain:{{ inputs.build-chain-build-system }}"`. This way it would be easy to dynamically select image to run with a simple `with` input from flow yml file and we could skip errors like [matrix in uses](#matrix-in-uses).
Just because of this we have to maintain different Dockerfile definitions in different branches and to tag every branch for every version we release like `python3-cekit-v1`.
### Contributors
<table>
Expand All @@ -587,4 +586,4 @@ Just because of this we have to maintain different Dockerfile definitions in dif
</a>
</td>
</tr>
</table>
</table>
63 changes: 51 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2664,18 +2664,35 @@ const {
} = __webpack_require__(484);
const { logger } = __webpack_require__(79);

async function checkoutDependencies(context, dependencies) {
async function checkoutDependencies(
context,
dependencies,
currentTargetBranch
) {
const result = {};
for (const dependencyKey of Object.keys(dependencies)) {
await checkoutProject(context, dependencyKey, dependencies[dependencyKey]);
result[dependencyKey] = await checkoutProject(
context,
dependencyKey,
dependencies[dependencyKey],
currentTargetBranch
);
}
return result;
}

async function checkoutProject(context, project, dependencyInformation) {
async function checkoutProject(
context,
project,
dependencyInformation,
currentTargetBranch
) {
const dir = getDir(context.config.rootFolder, project);
const checkoutInfo = await getCheckoutInfo(
context,
dependencyInformation.group,
project,
currentTargetBranch,
dependencyInformation.mapping
);
if (checkoutInfo == undefined) {
Expand All @@ -2686,13 +2703,13 @@ async function checkoutProject(context, project, dependencyInformation) {

if (checkoutInfo.merge) {
logger.info(
`Merging ${context.config.github.serverUrl}/${dependencyInformation.group}/${project}:${context.config.github.targetBranch} into ${context.config.github.serverUrl}/${checkoutInfo.group}/${checkoutInfo.project}:${checkoutInfo.branch}`
`Merging ${context.config.github.serverUrl}/${dependencyInformation.group}/${project}:${checkoutInfo.targetBranch} into ${context.config.github.serverUrl}/${checkoutInfo.group}/${checkoutInfo.project}:${checkoutInfo.branch}`
);
try {
await clone(
`${context.config.github.serverUrl}/${dependencyInformation.group}/${project}`,
dir,
context.config.github.targetBranch
checkoutInfo.targetBranch
);
} catch (err) {
logger.error(
Expand Down Expand Up @@ -2730,15 +2747,22 @@ async function checkoutProject(context, project, dependencyInformation) {
throw err;
}
}
return checkoutInfo;
}

async function getCheckoutInfo(context, targetGroup, targetProject, mapping) {
async function getCheckoutInfo(
context,
targetGroup,
targetProject,
currentTargetBranch,
mapping
) {
const sourceGroup = context.config.github.sourceGroup;
const sourceBranch = context.config.github.sourceBranch;
const targetBranch =
mapping && mapping.source === context.config.github.targetBranch
mapping && mapping.source === currentTargetBranch
? mapping.target
: context.config.github.targetBranch;
: currentTargetBranch;
const forkedProjectName = await getForkedProjectName(
context.octokit,
targetGroup,
Expand All @@ -2762,6 +2786,7 @@ async function getCheckoutInfo(context, targetGroup, targetProject, mapping) {
project: forkedProjectName,
group: sourceGroup,
branch: sourceBranch,
targetBranch,
merge: await hasPullRequest(
context.octokit,
targetGroup,
Expand All @@ -2780,6 +2805,7 @@ async function getCheckoutInfo(context, targetGroup, targetProject, mapping) {
project: targetProject,
group: targetGroup,
branch: sourceBranch,
targetBranch,
merge: await hasPullRequest(
context.octokit,
targetGroup,
Expand All @@ -2798,6 +2824,7 @@ async function getCheckoutInfo(context, targetGroup, targetProject, mapping) {
project: targetProject,
group: targetGroup,
branch: targetBranch,
targetBranch,
merge: false
}
: undefined;
Expand Down Expand Up @@ -3109,6 +3136,7 @@ async function checkoutParentsAndGetWorkflowInformation(
context,
projectList,
project,
currentTargetBranch,
parentDependencies
) {
if (!projectList[project]) {
Expand All @@ -3119,7 +3147,11 @@ async function checkoutParentsAndGetWorkflowInformation(
", "
)}] for project ${project}`
);
await checkoutDependencies(context, parentDependencies);
const checkoutInfos = await checkoutDependencies(
context,
parentDependencies,
currentTargetBranch
);
core.endGroup();
for (const parentProject of Object.keys(parentDependencies).filter(
parentDependency => parentDependency !== null && parentDependency !== ""
Expand All @@ -3140,6 +3172,7 @@ async function checkoutParentsAndGetWorkflowInformation(
context,
projectList,
parentProject,
checkoutInfos[parentProject].targetBranch,
parentWorkflowInformation.parentDependencies
)
);
Expand Down Expand Up @@ -22764,9 +22797,14 @@ async function start(context) {
context.config.rootFolder,
context.config.github.project
);
await checkoutProject(context, context.config.github.project, {
group: context.config.github.group
});
await checkoutProject(
context,
context.config.github.project,
{
group: context.config.github.group
},
context.config.github.targetBranch
);
const workflowInformation = readWorkflowInformation(
context.config.github.project,
context.config.github.jobName,
Expand All @@ -22782,6 +22820,7 @@ async function start(context) {
context,
[context.config.github.project],
context.config.github.project,
context.config.github.targetBranch,
workflowInformation.parentDependencies
)
).reverse();
Expand Down
43 changes: 35 additions & 8 deletions src/lib/build-chain-flow-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,35 @@ const {
} = require("./git");
const { logger } = require("./common");

async function checkoutDependencies(context, dependencies) {
async function checkoutDependencies(
context,
dependencies,
currentTargetBranch
) {
const result = {};
for (const dependencyKey of Object.keys(dependencies)) {
await checkoutProject(context, dependencyKey, dependencies[dependencyKey]);
result[dependencyKey] = await checkoutProject(
context,
dependencyKey,
dependencies[dependencyKey],
currentTargetBranch
);
}
return result;
}

async function checkoutProject(context, project, dependencyInformation) {
async function checkoutProject(
context,
project,
dependencyInformation,
currentTargetBranch
) {
const dir = getDir(context.config.rootFolder, project);
const checkoutInfo = await getCheckoutInfo(
context,
dependencyInformation.group,
project,
currentTargetBranch,
dependencyInformation.mapping
);
if (checkoutInfo == undefined) {
Expand All @@ -29,13 +46,13 @@ async function checkoutProject(context, project, dependencyInformation) {

if (checkoutInfo.merge) {
logger.info(
`Merging ${context.config.github.serverUrl}/${dependencyInformation.group}/${project}:${context.config.github.targetBranch} into ${context.config.github.serverUrl}/${checkoutInfo.group}/${checkoutInfo.project}:${checkoutInfo.branch}`
`Merging ${context.config.github.serverUrl}/${dependencyInformation.group}/${project}:${checkoutInfo.targetBranch} into ${context.config.github.serverUrl}/${checkoutInfo.group}/${checkoutInfo.project}:${checkoutInfo.branch}`
);
try {
await clone(
`${context.config.github.serverUrl}/${dependencyInformation.group}/${project}`,
dir,
context.config.github.targetBranch
checkoutInfo.targetBranch
);
} catch (err) {
logger.error(
Expand Down Expand Up @@ -73,15 +90,22 @@ async function checkoutProject(context, project, dependencyInformation) {
throw err;
}
}
return checkoutInfo;
}

async function getCheckoutInfo(context, targetGroup, targetProject, mapping) {
async function getCheckoutInfo(
context,
targetGroup,
targetProject,
currentTargetBranch,
mapping
) {
const sourceGroup = context.config.github.sourceGroup;
const sourceBranch = context.config.github.sourceBranch;
const targetBranch =
mapping && mapping.source === context.config.github.targetBranch
mapping && mapping.source === currentTargetBranch
? mapping.target
: context.config.github.targetBranch;
: currentTargetBranch;
const forkedProjectName = await getForkedProjectName(
context.octokit,
targetGroup,
Expand All @@ -105,6 +129,7 @@ async function getCheckoutInfo(context, targetGroup, targetProject, mapping) {
project: forkedProjectName,
group: sourceGroup,
branch: sourceBranch,
targetBranch,
merge: await hasPullRequest(
context.octokit,
targetGroup,
Expand All @@ -123,6 +148,7 @@ async function getCheckoutInfo(context, targetGroup, targetProject, mapping) {
project: targetProject,
group: targetGroup,
branch: sourceBranch,
targetBranch,
merge: await hasPullRequest(
context.octokit,
targetGroup,
Expand All @@ -141,6 +167,7 @@ async function getCheckoutInfo(context, targetGroup, targetProject, mapping) {
project: targetProject,
group: targetGroup,
branch: targetBranch,
targetBranch,
merge: false
}
: undefined;
Expand Down
12 changes: 9 additions & 3 deletions src/lib/build-chain-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ async function start(context) {
context.config.rootFolder,
context.config.github.project
);
await checkoutProject(context, context.config.github.project, {
group: context.config.github.group
});
await checkoutProject(
context,
context.config.github.project,
{
group: context.config.github.group
},
context.config.github.targetBranch
);
const workflowInformation = readWorkflowInformation(
context.config.github.project,
context.config.github.jobName,
Expand All @@ -35,6 +40,7 @@ async function start(context) {
context,
[context.config.github.project],
context.config.github.project,
context.config.github.targetBranch,
workflowInformation.parentDependencies
)
).reverse();
Expand Down
8 changes: 7 additions & 1 deletion src/lib/workflow-informaton-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async function checkoutParentsAndGetWorkflowInformation(
context,
projectList,
project,
currentTargetBranch,
parentDependencies
) {
if (!projectList[project]) {
Expand All @@ -20,7 +21,11 @@ async function checkoutParentsAndGetWorkflowInformation(
", "
)}] for project ${project}`
);
await checkoutDependencies(context, parentDependencies);
const checkoutInfos = await checkoutDependencies(
context,
parentDependencies,
currentTargetBranch
);
core.endGroup();
for (const parentProject of Object.keys(parentDependencies).filter(
parentDependency => parentDependency !== null && parentDependency !== ""
Expand All @@ -41,6 +46,7 @@ async function checkoutParentsAndGetWorkflowInformation(
context,
projectList,
parentProject,
checkoutInfos[parentProject].targetBranch,
parentWorkflowInformation.parentDependencies
)
);
Expand Down
Loading

0 comments on commit 641353f

Please sign in to comment.