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

Use XmlLint against tool configurations (PHPUnit, PHPCS, Psalm) #31

Merged
merged 2 commits into from
Aug 18, 2022
Merged

Use XmlLint against tool configurations (PHPUnit, PHPCS, Psalm) #31

merged 2 commits into from
Aug 18, 2022

Conversation

internalsystemerror
Copy link
Member

@internalsystemerror internalsystemerror commented May 10, 2021

Q A
Documentation no
Bugfix no
BC Break no
New Feature no
RFC no
QA yes

Description

This PR adds the use of xmllint if added via laminas/laminas-continuous-integration-action#37

Note: I don't personally use psalm, and have not checked that the xmllint command works for this schema. However I obtained the schema from the psalm.xml of mezzio/mezzio, as I did with PHPUnit and PHPCS, both of which work correctly.

src/create-jobs.js Outdated Show resolved Hide resolved
Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

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

My primary concern with this is that if these jobs fail... we've still queued jobs for the tools referenced, which means that they still run, but with known invalid schemas.

I think it might make more sense to inline the xmllint into the commands: xmllint ... && command .... This means that we fail early if the config is incorrect for the jobs running those tools.

@internalsystemerror
Copy link
Member Author

Yeah I was looking into being able to set a job as dependent on another as I considered that a better approach. Do you have any ideas on that? Otherwise I will just implement the changes you requested.

@internalsystemerror
Copy link
Member Author

The problem with inlining the commands is what/how to do that with the PHPUnit matrix? That's why I considered a better solution to be allowing the jobs to be dependent on other jobs.

@weierophinney
Copy link
Member

@internalsystemerror I think it may make more sense to validate in this action; you can see how @boesing managed it for the composer.json in #33 . I think there's similar tools for JS?

@weierophinney
Copy link
Member

I think it may make more sense to validate in this action

On second thought, maybe not - many of these reference a schema file that's installed with the tooling, which happens via Composer.

So, another possibility: do the linting as a precursor to running the associated command?

@internalsystemerror
Copy link
Member Author

internalsystemerror commented Aug 11, 2021

@weierophinney As it stands, the linting will run as a precursor to the associated commands since the jobs will be created with xmllint ... && command. EDIT: This was incorrect.

I've fetched the latest changes since this was made, too.

@internalsystemerror
Copy link
Member Author

internalsystemerror commented Aug 11, 2021

I have modified the commands to run xmllint ... && command.

@boesing
Copy link
Member

boesing commented Aug 11, 2021

Not 100% sure but if a project has both dist and non-dist, this would no create two jobs, right?

Plenty of unrelated changes there as well. 😅

@internalsystemerror
Copy link
Member Author

internalsystemerror commented Aug 12, 2021

Not 100% sure but if a project has both dist and non-dist, this would no create two jobs, right?

Correct, I believe it would.

Plenty of unrelated changes there as well. 😅

Sorry, I have format on save. I've corrected these but left in the couple of syntax fixes it added.

@boesing
Copy link
Member

boesing commented Aug 12, 2021

I wonder if it would be possible to avoid having two files created.
Maybe with using test to check if file exists before linting?

Pseudo-Code:

((test -r phpunit.xml && xmllint phpunit.xml ...) || (test -r phpunit.xml.dist && xmllint phpunit.xml.dist)) && vendor/bin/phpunit

@internalsystemerror
Copy link
Member Author

Nice idea, that would avoid 2 jobs being created if 2 files exist. Thinking about it though, if a second file is submitted (dist xml along with xml), either this is accidental, in which case having the same job twice would be an indication. Or, it's deliberate, in which case you may wish to run these separately? Honestly I don't see this latter one happening though.

@boesing
Copy link
Member

boesing commented Oct 5, 2021

Or, it's deliberate, in which case you may wish to run these separately? Honestly I don't see this latter one happening though.

The only thing which came to my mind would be a .laminas/pre-install.sh script which applies changes to a config temporarily for whatever case.
In combination with this action, it could lead to issues when manipulating the .dist (as it is committed) so you would probably copy the *.dist file to the non-dist version, apply your changes you want to have for CI (for whatever reasons) and then execute the tool. Doing it this way would prevent the github action to detect a change (as usually the non-dist files are added to .gitignore).

Fun fact - we probably going to do exactly this for PHPUnit regarding the recent changes for deprecations to exceptions: laminas/laminas-continuous-integration-action#54

So in fact, we are not creating a new file from the .dist but modifying whatever file will be used for phpunit (which is non-dist prior dist when it comes to priority).

@boesing boesing changed the base branch from 1.8.x to 1.12.x October 10, 2021 18:24
src/create-jobs.js Outdated Show resolved Hide resolved
Copy link
Member

@boesing boesing left a comment

Choose a reason for hiding this comment

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

LGTM. Just a lil nitpick but from my perspective, this could work.
@weierophinney do you see anything else here? I think it would be fine if we spawn the Jobs and let them fail then since we need any feedback from the tooling.
Just not sure about the fact if we should provide the output from the linter to help devs fixing the problem

src/create-jobs.js Outdated Show resolved Hide resolved
Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

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

Two categories of changes:

  • Instead of const filename = appendDistExtensionIfFilenameDoesntExist(...), name the constant something that is semantically appropriate: phpunitConfigFile, phpcsConfigFile, etc.
  • I'm thinking we shouldn't use the --noout flag. If we have --noout and xmllint fails, it's not immediately obvious what happened. With output, the user will know what xmllint errored on.

src/create-jobs.js Outdated Show resolved Hide resolved
src/create-jobs.js Outdated Show resolved Hide resolved
src/create-jobs.js Outdated Show resolved Hide resolved
src/create-jobs.js Outdated Show resolved Hide resolved
src/create-jobs.js Outdated Show resolved Hide resolved
boesing added a commit to boesing/laminas-ci-matrix-action that referenced this pull request Mar 3, 2022
This feature is based on the feedback from @Ocramius in laminas#76 and provides better namings to github UI.
This will also prevent laminas#31 with its extended commands where we do check for linting before actually executing the command itself.

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
@boesing
Copy link
Member

boesing commented Jul 26, 2022

The CI container now supports before_script and after_script.
We could add the linting as one of the before_script entries (its a list of commands).

@internalsystemerror
Copy link
Member Author

internalsystemerror commented Aug 6, 2022

I've been looking at reimplementing this today, using the new before_script option. I was mainly looking for a way to only run the xml linting once per file. For example, using before_script on PHPUnit, it would run xmllint for each phpunit job in the matrix.

Does anyone have any ideas on that?

@Ocramius
Copy link
Member

Ocramius commented Aug 7, 2022

Wouldn't it be better to run an independent matrix job that only runs xmllint/yamllint for root level xml/yaml files? 🤔

A completely independent failure would be nicer than mixing it with test results, or worse with no tests run at all.

@internalsystemerror
Copy link
Member Author

A completely independent failure would be nicer than mixing it with test results, or worse with no tests run at all.

Preventing tests from running with a known incorrect schema was requested in this comment #31 (review).

Adding in these checks as just another linting check would certainly be the easiest solution to implement.

@weierophinney
Copy link
Member

I was mainly looking for a way to only run the xml linting once per file.

I think the only way to do that is if we were to do this as one or more separate jobs in the workflow, marked to fail the workflow if it fails. Since we can extend workflows now, we could do this in the main workflow in the .github repo...

@boesing
Copy link
Member

boesing commented Aug 8, 2022

I am not sure if its smart to have linting for configs seperately. I would expect all Jobs related to that Tool failing if the config is invalid rather than having another Job just to lint.

So I would be +1 for adding these lint checks as a before_scripts entry.

@Ocramius
Copy link
Member

Ocramius commented Aug 9, 2022

Works for me: no hard opinion, as long as linting manages to make it through, at least 👍

@internalsystemerror
Copy link
Member Author

OK. Then since I have no preference either, I'll update this PR to simply add xmllint as a before_script check for each tool, hopefully this weekend.

Signed-off-by: Gary Lockett <gary@creativecow.uk>
@internalsystemerror
Copy link
Member Author

Forgive the incoming update spam. This took much longer than I want to admit, mainly because I can't get a reliable way to run the tests even on a clean branch.

Pushing now to get test results via GHA, expect fixes (which is updating the expected matrix.json to include the new before_script commands) shortly.

Signed-off-by: Gary Lockett <gary@creativecow.uk>
@internalsystemerror
Copy link
Member Author

internalsystemerror commented Aug 17, 2022

Checks are green. Ready for review. @boesing tagging you specifically as you had some ideas already for this.

Matrices that are generated for tools will include before_script: [] (and the XML lint command where appropriate). Those jobs which are set as explicit/additional checks within .laminas-ci.json do not include this feature as I was having issues so decided it was out of scope 😄 .

@internalsystemerror internalsystemerror changed the base branch from 1.12.x to 1.14.x August 17, 2022 17:04
@boesing
Copy link
Member

boesing commented Aug 17, 2022

I hope I find some time this weekend to review this.
I wonder if we need some generic stuff like configurationType: XML|YAML|JSON so that xmllint or yamllint does not need to get repeated.

And there is still that "if phpunit.xml exists, we should lint that file, else phpunit.xml.dist". But I would assume not to lint both at the same time for example. But I have no clue how to implement that properly, as the phpunit.xml might get created within the container. I did that somewhere to actually dynamically set convertDeprecationsToExceptions in PHPUnit Configuration to false. Maybe @Ocramius can remember that PR as he reviewed that 😂

@Ocramius
Copy link
Member

https://www.youtube.com/watch?v=DFdDNOnGjWc

@internalsystemerror
Copy link
Member Author

It's been waiting 15 months, another few weeks or even months wouldn't hurt it. The approach I took was to KISS. The tools are modified to reduce the filesToCheck: string[] to contain only the files that exist, with empty tools being removed.

Functionally it's the same as before, however the ability to add a tool in the future without any files to check has been removed. Then for each file to check that remains, if there is a linting command available it will add it as a before_script.

Any more than that I found myself overengineering something that might not need to exist. For example, I'd also like to extend the before_script functionality to include explicit checks that have their own.

import {Action} from '../action';
import {Output} from '../config/output';
import {Logger} from '../logging';

/* eslint-disable-next-line import/no-commonjs, @typescript-eslint/no-var-requires */
Copy link
Member

Choose a reason for hiding this comment

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

I am pretty sure that I had to do this.
But since tests are passing, I think its okay now.

Maybe that was on my macos machine when I compiled that locally. Dunno...

@Ocramius Ocramius added this to the 1.14.0 milestone Aug 18, 2022
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

LGTM, althought to be noted that XMLLint could (in theory) rely on the pre-defined XSD references within phpunit.xml(.dist)

@Ocramius Ocramius changed the title Use XmlLint against tool configurations (PHPUnit, PHPCS, Psalm) Use XmlLint against tool configurations (PHPUnit, PHPCS, Psalm) Aug 18, 2022
@Ocramius Ocramius merged commit e5bc561 into laminas:1.14.x Aug 18, 2022
@internalsystemerror internalsystemerror deleted the feature/xmllint branch August 18, 2022 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants