Problem/Motivation

The regex used to extract the type: when reading a projects .info.yml is too permissive.
Reported on #3492716-6: Fix CI for Stylelint 16

Proposed resolution

Thanks to @longwave for the solution. Only allow spaces before type: so replace leading ^.* with [[:space:]]*

Remaining tasks

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jonathan1055 created an issue. See original summary.

longwave made their first commit to this issue’s fork.

longwave’s picture

Status: Active » Needs review
jonathan1055’s picture

Status: Needs review » Needs work

You got there before me.
Tested locally and it works as expected.

I suggest for extra safety we also add | head -1 afterwards. I know that having two "type:" would be invalid config, but we should avoid generating a bad build.env even in that scenario. I have made this suggestion in the MR.

jonathan1055’s picture

Issue summary: View changes

Updated IS.
For info, the change that caused this is in the tagged 1.6.10 release, but the default-ref is still 1.6.9, so most of Contrib will not be affected.
See https://git.drupalcode.org/project/gitlab_templates/-/commits/1.6.x-late...

longwave’s picture

I wondered about adding the same thing after I did the initial fix, I think it's a good idea. I was trying to see if there was a way of doing it directly in sed but head is easier to understand anyway.

longwave’s picture

Status: Needs work » Needs review
longwave’s picture

Status: Needs review » Reviewed & tested by the community

In fact let's be bold and mark this RTBC as we both agree on the solution here.

jonathan1055’s picture

Is it valid yml to have a space after the keyword, before the colon? I know we don't do that much but I think it might be allowed.

longwave’s picture

Status: Reviewed & tested by the community » Needs review

Probably we shouldn't use regex at all, as there still could be false positives if we ever use nested structures in the YAML, or heredocs, or anything similar.

MR!306 uses a pure PHP solution instead which works for me inside drupalci/php-8.3-ubuntu-apache:production.

jonathan1055’s picture

Nice idea, but I would suggest it's a little bit over-the-top to use php to parse the yml file to get just this one key. I think that the regex version is fine for now, it is simple and if we take the first "type:" found it will nearly always be the required value. On the times when this does not, we already have the override capability to set the variable PROJECT_TYPE in the project's .gitlab-ci.yml. If I hadn't asked the question in #10 then you would probably have left it at RTBC and not started the second MR :-)

jonathan1055’s picture

Actually I have realized that we don't already cater for overriding the project type, only the project name. So I have pushed a change to MR305 for this - essentially just swapping round the two clauses to allow for a condition on the else too.
https://git.drupalcode.org/project/gitlab_templates/-/merge_requests/305...

jonathan1055’s picture

Tested MR305 with a normal .info.yml file. The project name and project type are derived correctly.
https://git.drupalcode.org/issue/scheduler-3445052/-/pipelines/364767

Tested with extra type: in a comment and a second type: keyword.
https://git.drupalcode.org/issue/scheduler-3445052/-/commit/77fdc469e936...
The yml is invalid (as shown by eslint) but the composer job still does not create a bad build.env
https://git.drupalcode.org/issue/scheduler-3445052/-/pipelines/364793

Tested with an override in the UI form - worked as expected, the form value is shown in the composer log
https://git.drupalcode.org/issue/scheduler-3445052/-/pipelines/364801

longwave changed the visibility of the branch 3492927-php-solution to hidden.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Alright, let's just go with the hardened regex. The suggested changes look good to me.

fjgarlin made their first commit to this issue’s fork.

  • fjgarlin committed b7e9bd18 on main authored by longwave
    Issue #3492927 by longwave, jonathan1055: Fix regex when parsing info....
fjgarlin’s picture

Status: Reviewed & tested by the community » Fixed

Merged. Thanks both for working on this and reviewing/testing.

jonathan1055’s picture

Now that MR305 has been merged can we close MR306 ?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.