Skip to content

Commit

Permalink
feat(branchNameStrict)!: remove forward slashes from non-prefix part …
Browse files Browse the repository at this point in the history
…of branchName (#32278)

Update logic for branchNameStrict=true so that it also removes forward slashes from branch names, with the exception of the `branchPrefix` part. In other words, if you leave the default `branchPrefix="renovate/"` then you'll get branch names like `renovate/foo-bar-42-x` instead of today's `renovate/foo/bar-42-x`.

BREAKING CHANGE: Branch names with multiple forward slashes will change if branchNameStrict=true
  • Loading branch information
rarkins committed Nov 4, 2024
1 parent 0f2783c commit a6d93dc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
7 changes: 6 additions & 1 deletion docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,12 @@ If `true`, Renovate removes special characters when slugifying the branch name:
- only alphabetic characters are allowed
- hyphens `-` are used to separate sections

The default `false` behavior will mean that special characters like `.` may end up in the branch name.
The default `false` behavior will mean that special characters like `.` and `/` may end up in the branch name.

<!-- prettier-ignore -->
!!! note
Renovate will not apply any search/replace to the `branchPrefix` part of the branch name.
If you don't want any `/` in your branch name then you will also need to change `branchPrefix` from the default `renovate/` value to something like `renovate-`.

## branchPrefix

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/examples/self-hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ COPY self-signed-certificate.crt /usr/local/share/ca-certificates/
RUN update-ca-certificates
# Change back to the Ubuntu user
USER 1000
USER 12021

This comment has been minimized.

Copy link
@felipecrs

felipecrs Nov 13, 2024

Contributor

BTW you could just have written this as ubuntu, so you don't need to change the UID if changed in base.

# OpenSSL
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
Expand Down
16 changes: 16 additions & 0 deletions lib/workers/repository/updates/branch-name.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ describe('workers/repository/updates/branch-name', () => {
expect(upgrade.branchName).toBe('renovate/jest-42-x');
});

it('removes slashes from the non-suffix part', () => {
const upgrade: RenovateConfig = {
branchNameStrict: true,
branchName:
'{{{branchPrefix}}}{{{additionalBranchPrefix}}}{{{branchTopic}}}',
branchTopic:
'{{{depNameSanitized}}}-{{{newMajor}}}{{#if isPatch}}.{{{newMinor}}}{{/if}}.x{{#if isLockfileUpdate}}-lockfile{{/if}}',
branchPrefix: 'renovate/',
depNameSanitized: '@foo/jest',
newMajor: '42',
group: {},
};
generateBranchName(upgrade);
expect(upgrade.branchName).toBe('renovate/foo-jest-42-x');
});

it('hashedBranchLength hashing', () => {
const upgrade: RenovateConfig = {
branchName:
Expand Down
13 changes: 11 additions & 2 deletions lib/workers/repository/updates/branch-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const MIN_HASH_LENGTH = 6;

const RE_MULTIPLE_DASH = regEx(/--+/g);

const RE_SPECIAL_CHARS_STRICT = regEx(/[`~!@#$%^&*()_=+[\]\\|{};':",.<>?]/g);
const RE_SPECIAL_CHARS_STRICT = regEx(/[`~!@#$%^&*()_=+[\]\\|{};':",.<>?/]/g);

/**
* Clean git branch name
Expand All @@ -26,12 +26,20 @@ const RE_SPECIAL_CHARS_STRICT = regEx(/[`~!@#$%^&*()_=+[\]\\|{};':",.<>?]/g);
*/
function cleanBranchName(
branchName: string,
branchPrefix: string,
branchNameStrict?: boolean,
): string {
let cleanedBranchName = branchName;

let existingBranchPrefix = '';
if (branchNameStrict) {
cleanedBranchName = cleanedBranchName.replace(RE_SPECIAL_CHARS_STRICT, '-'); // massage out all special characters that slip through slugify
if (cleanedBranchName.startsWith(branchPrefix)) {
existingBranchPrefix = branchPrefix;
cleanedBranchName = cleanedBranchName.slice(branchPrefix.length);
}
cleanedBranchName =
existingBranchPrefix +
cleanedBranchName.replace(RE_SPECIAL_CHARS_STRICT, '-'); // massage out all special characters that slip through slugify
}

return cleanGitRef
Expand Down Expand Up @@ -125,6 +133,7 @@ export function generateBranchName(update: RenovateConfig): void {
}
update.branchName = cleanBranchName(
update.branchName,
update.branchPrefix!,
update.branchNameStrict,
);
}
2 changes: 1 addition & 1 deletion tools/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ LABEL \
org.label-schema.version="${RENOVATE_VERSION}"

# Numeric user ID for the ubuntu user. Used to indicate a non-root user to OpenShift
USER 1000
USER 12021

5 comments on commit a6d93dc

@lordcheeto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the UID is a breaking change for the docker image and should have been in the change log. The existing base directory in the volume or bind mount is owned by the old user id.

@felipecrs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lordcheeto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for highlighting that resource for me, I'm glad that it's noted as a breaking change there. I'm not sure if it was listed correctly there on release; it may have been, but I do know that it was added to the release notes here on GitHub some time after the fact. The renovatebot fetches the GitHub release notes when it creates a pull request, and it was not listed as a breaking change when it generated or updated the pull request in my repository [screenshot]. It was probably missed because it was not noted in the commit here.

@KingJ
Copy link

@KingJ KingJ commented on a6d93dc Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to add, the release notes on Github;

deps: Renovate sidecard images will default to use Ubuntu 24.04 instead of 20.04, and use User ID 12021 instead of 1001

as well as the docs;

All our Docker images now set the Docker user ID to 12021, the old ID was 1001.

...have an error. As above, the old UID was actually 1000. This bit us when upgrading, as since we already set the container to use UID 1000 I had assumed we were already using a non-default UID.

@zluiten
Copy link

@zluiten zluiten commented on a6d93dc Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This had/has specifically consequences for templated gitlab runners since the cached directory renovate/cache/renovate/repository/ suddenly has the wrong file owner (see https://gitlab.com/renovate-bot/renovate-runner/-/blob/main/templates/renovate.gitlab-ci.yml?ref_type=heads#L16).

Clearing the runners cache fixes the issue. Opened an issue on the gitlab side.

Please sign in to comment.