The test-only script for GitLab CI does not reliably use the right commit

Created on 22 January 2024, 11 months ago
Updated 20 February 2024, 10 months ago

Problem/Motivation

This issue is a follow-up to πŸ“Œ Make CI template compatible with private repositories Fixed .

The script .gitlab-ci/scripts/test-only.sh starts with

#!/bin/bash

export TARGET_BRANCH=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}${CI_COMMIT_BRANCH}
git fetch -vn --depth=50 origin "+refs/heads/$TARGET_BRANCH:refs/heads/$TARGET_BRANCH"

That sets $TARGET_BRANCH (typically 11.x for a merge request) and fetches the last 50 commits from that branch.

The next step is

echo "ℹ️ Changes from ${TARGET_BRANCH}"
git diff ${CI_MERGE_REQUEST_DIFF_BASE_SHA} --name-only
echo "If this list contains more files than what you changed, then you need to rebase your branch."

First of all, the message is not accurate. Secondly, there is no guarantee that $CI_MERGE_REQUEST_DIFF_BASE_SHA is one of the commits that have been fetched. We always fetch the source branch with --depth=3, and the first step fetches the target branch with --depth=50 (arbitrarily).

This logic error leads to actual failures in some cases: for example, https://git.drupalcode.org/project/drupal/-/jobs/570956. (Read the log: it is a separate problem that CI system did not mark it as a failure.)

Steps to reproduce

  1. Create a merge request with test changes.
  2. Wait until more than 50 commits have been added to the 11.x branch.
  3. Trigger the test-only CI job.

Proposed resolution

Fetch $CI_MERGE_REQUEST_DIFF_BASE_SHA directly instead of guessing how far back you have to look from the HEAD of the 11.x branch.

Update the messages logged in the CI job.

Merge request link

Do not merge (but use for testing the test-only job): https://git.drupalcode.org/project/drupal/-/merge_requests/6260

Candidate for merging: https://git.drupalcode.org/project/drupal/-/merge_requests/6261

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

N/A

πŸ› Bug report
Status

Closed: duplicate

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated 2 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

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