Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host rules migration not working as expected #20539

Closed
RahulGautamSingh opened this issue Feb 21, 2023 · 5 comments · Fixed by #20540
Closed

Host rules migration not working as expected #20539

RahulGautamSingh opened this issue Feb 21, 2023 · 5 comments · Fixed by #20540
Assignees
Labels
priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others status:requirements Full requirements are not yet known, so implementation should not be started type:bug Bug fix of existing functionality

Comments

@RahulGautamSingh
Copy link
Collaborator

RahulGautamSingh commented Feb 21, 2023

How are you running Renovate?

Self-hosted

If you're self-hosting Renovate, tell us what version of Renovate you run.

34.148.0

If you're self-hosting Renovate, select which platform you are using.

github.com

If you're self-hosting Renovate, tell us what version of the platform you run.

No response

Was this something which used to work for you, and then stopped?

I never saw this working

Describe the bug

Host rules are migrated twice and the first migration effects the next one such that it can't serve its purpose.

if (
key === 'endpoint' ||
key === 'host' ||
key === 'baseUrl' ||
key === 'hostName' ||
key === 'domainName'
) {
if (is.string(value)) {
newRule.matchHost ??= massageUrl(value);
}

function migrateRule(rule: LegacyHostRule & HostRule): HostRule {
const cloned: LegacyHostRule & HostRule = clone(rule);
delete cloned.hostName;
delete cloned.domainName;
delete cloned.baseUrl;
const result: HostRule = cloned;
const { matchHost } = result;
const { hostName, domainName, baseUrl } = rule;
const hostValues = [matchHost, hostName, domainName, baseUrl].filter(Boolean);
if (hostValues.length === 1) {
const [matchHost] = hostValues;
result.matchHost = matchHost;
} else if (hostValues.length > 1) {
throw new Error(
`hostRules cannot contain more than one host-matching field - use "matchHost" only.`
);
}
return result;
}

The custom migration migrates LegacyHostRule options to matchHost (first come precedence if more than one legacy option is present)
And later migrateRule function does the same but instead it throws an error if more than 1 legacy option is present.
But migrateRule will never be called with legacy options as the previous config-migration already takes care of it.

Relevant debug logs

Logs
DEBUG: Checking for config file in C:\Users\LENOVO\Desktop\Whitesource\renovate/config.js
 WARN: Config needs migrating
       "originalConfig": {
         "token": "***********",
         "repositories": ["RahulGautamSingh-testing/merge3"],
         "hostRules": [
           {
             "baseUrl": "https://some.domain.com/",
             "domainName": "domain.com",
             "matchHost": "domain.com/",
             "hostName": "some.domain.com",
             "token": "***********"
           }
         ]
       },
       "migratedConfig": {
         "token": "***********",
         "repositories": ["RahulGautamSingh-testing/merge3"],
         "hostRules": [
           {"matchHost": "https://some.domain.com/", "token": "***********"}
         ]
       }

Have you created a minimal reproduction repository?

https://github.com/RahulGautamSingh-testing/repro-20539

@RahulGautamSingh RahulGautamSingh added type:bug Bug fix of existing functionality status:requirements Full requirements are not yet known, so implementation should not be started priority-5-triage labels Feb 21, 2023
@RahulGautamSingh
Copy link
Collaborator Author

RahulGautamSingh commented Feb 21, 2023

Fix:
We should move the "throw error" to the custom migration and remove the migrateRule function.
This will also reduce the type issues caused due to LegacyHostRule options.

I also think it would be good to throw CONFIG_VALIDATION error so that the user is notified via an issue.

@RahulGautamSingh RahulGautamSingh self-assigned this Feb 21, 2023
@RahulGautamSingh RahulGautamSingh added status:ready priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others and removed status:requirements Full requirements are not yet known, so implementation should not be started labels Feb 21, 2023
@rarkins
Copy link
Collaborator

rarkins commented Mar 24, 2023

If I had to choose between this type of config warning: RahulGautamSingh-testing/merge3#16 versus the risk of breaking apps and users with #20540, then I think I go for letting them have a config warning.

@viceice wdyt?

@viceice
Copy link
Member

viceice commented Mar 24, 2023

yes, a config warning issue should the way to go

@RahulGautamSingh
Copy link
Collaborator Author

RahulGautamSingh commented Apr 20, 2023

Checking my understanding..

  1. Do not modifiy the add and the migrateRule functions so the app doesn't break

    export function add(params: HostRule): void {

  2. Detect multiple hosts in the custom migration fn and throw a config_validation error. This will stop the processing of the repo and warn the user with a new PR.

    if (
    key === 'endpoint' ||
    key === 'host' ||

@rarkins rarkins added the auto:reproduction A minimal reproduction is necessary to proceed label Apr 21, 2023
@github-actions
Copy link
Contributor

Hi there,

Get your issue fixed faster by creating a minimal reproduction. This means a repository dedicated to reproducing this issue with the minimal dependencies and config possible.

Before we start working on your issue we need to know exactly what's causing the current behavior. A minimal reproduction helps us with this.

To get started, please read our guide on creating a minimal reproduction.

We may close the issue if you, or someone else, haven't created a minimal reproduction within two weeks. If you need more time, or are stuck, please ask for help or more time in a comment.

Good luck,

The Renovate team

@rarkins rarkins added status:requirements Full requirements are not yet known, so implementation should not be started and removed status:ready labels Apr 21, 2023
@RahulGautamSingh RahulGautamSingh removed the auto:reproduction A minimal reproduction is necessary to proceed label Apr 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others status:requirements Full requirements are not yet known, so implementation should not be started type:bug Bug fix of existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants