Autoresolve cspell GIT_DEPTH issue when diff fails

Created on 20 February 2024, about 1 year ago
Updated 17 June 2024, 10 months ago

Problem/Motivation

In 🐛 Spell-checking job fails with "couldn't find remote ref refs/heads/11.x" when 11.x branch does not exist in fork Active we

Use ${CI_MERGE_REQUEST_TARGET_BRANCH_SHA:-$CI_MERGE_REQUEST_DIFF_BASE_SHA} to calculate the optimal base SHA for the MR. This avoids fetching any remote and uses the target SHA if available (MRs created by core committers) or the base SHA of the merge (MRs created by non-committers). Either way the change set should only contain the changes in the MR itself.

(Quote from @longwave)

In https://git.drupalcode.org/issue/drupal-2408549/-/jobs/793302 we observed

$ if [ -n "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA" ]; then echo "HEAD is $(git rev-parse HEAD). \$CI_MERGE_REQUEST_TARGET_BRANCH_SHA is ${CI_MERGE_REQUEST_TARGET_BRANCH_SHA}"; else echo "HEAD is $(git rev-parse HEAD). \$CI_MERGE_REQUEST_DIFF_BASE_SHA is ${CI_MERGE_REQUEST_DIFF_BASE_SHA}"; fi;
HEAD is fabcf543c3a61a96a0bddb3f443d7115b5f36b76. $CI_MERGE_REQUEST_DIFF_BASE_SHA is c574a6e4f0867d27a49a244ee9648d7adfaf9f9b
$ git diff ${CI_MERGE_REQUEST_TARGET_BRANCH_SHA:-$CI_MERGE_REQUEST_DIFF_BASE_SHA} --name-only | sed "s_^_../_" | yarn --cwd=./core run -s spellcheck:core --no-must-find-files --file-list stdin
fatal: bad object c574a6e4f0867d27a49a244ee9648d7adfaf9f9b
CSpell: Files checked: 0, Issues found: 0 in 0 files

Key note: the above issue at that point had 74 commits on top of a (previous) HEAD.

Resolution required merging 11.x into the Fork branch.
https://git.drupalcode.org/project/drupal/-/commits/8e615698ad1a44150b4e... which reduced head to 1 commit ahead of the CI_MERGE_REQUEST_DIFF_BASE_SHA.

On cursory review this failure appears it could be related to our setting GIT_DEPTH: "50" in the .gitlab-ci.yml.

Steps to reproduce

Create an MR this is >= 51 commits ahea of the common ancestor of the target branch.

Proposed resolution

It has been suggested by @dww that we may want to detect failures and re-fetch the MR branch with a higher depth.
It has been suggested by @longwave that we may just wish to increase the depth to a (significantly) higher value.
We may also choose to remove the depth limitation completely. (how much time/bandwidth savings is this and is it worth the maintenance costs)

Update:
Use error detection to unshallow the git repository if diff fails. Then cspell can run properly.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

10.3

Component
PHPUnit 

Last updated about 6 hours ago

Created by

🇺🇸United States cmlara

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024