-
Notifications
You must be signed in to change notification settings - Fork 26
chore: extract dir paths to common vars #796
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
base: main
Are you sure you want to change the base?
Conversation
There was an error running your pipeline, see logs for details. |
@mender-test-bot sync |
trying to re-open the PR |
There was an error running your pipeline, see logs for details. |
@mender-test-bot sync |
d4e640f
to
105c544
Compare
c9f3c03
to
971821b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI change looks reasonable to me. However, I'm not too familiar with the npm setup here and would like to defer the approval to @mendersoftware/frontend-dependabot-reviewers
d471f6a
to
eedf0f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite a few changes in a single commit that don't align with the commit message...
The change in the commit title is IMO a personal preference over the repo structure, which is indeed hardcoded. Can you give an explanation as to the improvements this would bring over the explicit reliance on the repo structure - also in light of the added indirection?
More general:
Pure formatting changes are IMO also mostly a personal preference and should go at least into a separate commit if they are included at all as they will usually just cause noise for the people editing the files frequently.
script: | ||
- deno run --allow-env --allow-read --allow-sys tests/licenses/licenseCheck.ts --rootDir $(pwd) | ||
- deno run --allow-env --allow-read --allow-sys --config ${FRONTEND_DIR}/scripts/deno.json ${FRONTEND_DIR}/tests/licenses/licenseCheck.ts --rootDir ${FRONTEND_DIR} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using the independent deno config like this (outside of the licenseCheck script hierarchy), you could move the licenseCheck
to the scripts, define the execution as a new task in there and make sure the comparison in the file points to the license csv file. The change in versioning requires the config file, as otherwise the missing "nodeModulesDir": "auto",
would prevent retrieving the package in CI - this also causes the import map entry in there that you noted about 👌.
This wasn't intended to be in there, but would make a nice consolidation 👍.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should address this in a followup PR, I am lumping too much stuff into this one PR as it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that would be a good practice. So remove the related changes from this PR as it conflates both and create a followup PR or task. Or separate the different aspects in separate commits as I requested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dhaustein applying your own logic here: the contents of the script are frontend team code and as such the final say is: that change is poor, please adjust or create a follow up task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will be defining a QA role and who is responsible for what exactly, hopefully next week, until then we have the same role
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting...
Until then we still have this PR opened before the fact and as the person mainly responsible for the code in here, I still insist on this being addressed before this can get merged or put into a follow up task, since the change as is, is considered bad practice and thus nothing we want in the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few observation. Sorry I unsubscribed from this issue due to lack of frontend expertise.
+1 for removing the job-local directories
I'm not sure what would be the best approach for the number of new variables introduced, but I would personally prefer keeping it to a minimum.
It would also be great if you could split the different changes into separate commits that more accurately describe the changes.
frontend/pipeline.yml
Outdated
FRONTEND_DIR: ${CI_PROJECT_DIR}/frontend | ||
LOGS_DIR: ${CI_PROJECT_DIR}/logs | ||
COVERAGE_DIR: ${FRONTEND_DIR}/coverage | ||
SCREENSHOTS_DIR: ${FRONTEND_DIR}/screenshots | ||
JUNIT_DIR: ${FRONTEND_DIR} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about instead of defining 5 different variables that points to frontend artifacts, consolidate everything into a FRONTEND_ARTIFACTS_DIR
pointing to the root of all artifacts and update the jobs the scripts that generate these artifacts to write to sub-directories inside this path?
In that case it doesn't matter what you define the variable as and there will be less boilerplate dealing with the correct environment variables.
FRONTEND_DIR: ${CI_PROJECT_DIR}/frontend | |
LOGS_DIR: ${CI_PROJECT_DIR}/logs | |
COVERAGE_DIR: ${FRONTEND_DIR}/coverage | |
SCREENSHOTS_DIR: ${FRONTEND_DIR}/screenshots | |
JUNIT_DIR: ${FRONTEND_DIR} | |
FRONTEND_ARTIFACTS_ROOT: "${CI_PROJECT_DIR:-$(git rev-parse --show-toplevel)}/frontend/artifacts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach!
It does rely on git, and I am not sure how it's going to work for things like shallow clones, but I also cannot see the $CI_PROJECT_DIR to not have a value. Something must've gone very wrong if that happened. Either way, a cool fallback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into the artifacts root path changes and it won't be as straightforward.
I'd need to add something akin to path.join(frontendDir, 'artifacts');
into vitest.config.ts
and playwright.config.ts
because they are set to output to their root which would be FRONTEND_DIR
and not FRONTEND_DIR/artifacts
I'd rather not change it this way, unless we really really want it.
I can go back to a partial approach. Keep the FRONTEND_DIR
variable
variables:
FRONTEND_DIR: ${CI_PROJECT_DIR:-$(git rev-parse --show-toplevel)}/frontend
but don't do anything extra for the different artifacts dirs. And for the job artifacts just do:
artifacts:
paths:
- ${FRONTEND_DIR}/coverage
- ${FRONTEND_DIR}/screenshots
- ${FRONTEND_DIR}/junit
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually turns out that
FRONTEND_DIR: ${CI_PROJECT_DIR:-$(git rev-parse --show-toplevel)}/frontend
won't work because gitlab will not do command substitution, so I changed it to simply
FRONTEND_DIR: ${CI_PROJECT_DIR}/frontend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alfrunes What's your take on he changes now?
eedf0f3
to
aa54580
Compare
Hi @kjaskiewiczz @merlin-northern as discussed on the server meeting, I've broken down these changes into hopefully cleaner commit structure. |
333c63b
to
55c8d92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feat
commits are misleading here -- the changes are not really features of mender-server. It would be OK if this was a tests repository, but we don't want to present these changes are new features in Mender Server, right?
Looks good to me otherwise.
- npm ci --prefix ${FRONTEND_DIR} --cache ${FRONTEND_DIR}/.npm --prefer-offline | ||
- npm ci --prefix ${FRONTEND_DIR}/tests/e2e_tests | ||
- npm run lint --prefix ${FRONTEND_DIR} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okey so I do not want to attack (too much) you, but this couple of lines is my clipboard, so I come here to copy from when I forget how to run the ci for the Frontend. and if I have to remove that many chars from the command, I will have rather re-typed it. so all in all I do not really see the benefit of the FRONTEND_DIR variable. why did you introduce it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing a cd dir
in a ci is considered an anti-pattern, it's moving the pointer around and all the scripts assume a certain directory structure. Luckily all the tooling has some way to force a "workdir" so it can be defined once and re-used. Also when working on the CI you have to keep that in your head too.
If you rely on the CI code for your local needs, the code will still work the same, you just need to ensure you have the new env var.
And if you are copy pasting it every time, maybe it's time to create a script. 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dhaustein your question didn't answer the question to the why of the variable, but a why to the (undisputed) --prefix
. Please come up with a reasonable explanation to the why of the variable.
As to best practices, it is also a best practice to reduce complexity where possible - in comparison a single level folder definition that is not only shorter than the variable definition, but moreover won't ever be an issue getting inherited in child pipelines/ expanded in a script/ is clearly readable without knowing the full pipeline definition.
And since this is repeatedly ignored here: the CI instructions are not only used by us internally and if we want to add the extra indirection we should have a good reason - so far I haven't seen any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the why has been discussed at least thrice now.
This is decreasing complexity, like I said to a comment to Peter, please read it.
I agree that in an ideal world the CI and the local would work the same. Alas we are not there yet and probably never will be 100%. Copying over lines from a CI script so you can run stuff locally, instead of relying on, I dunno, makefiles? is also a symptom of bad design.
Additionally, to this. Since I am in charge of the test automation, I have the final say. If you have a problem with this, talk to Marcin or Thomas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dhaustein you should re-read the company handbook on the decision making process and I'm talking with both to hopefully prevent more of these discussions with you.
So how can an added layer of indirection decrease complexity? Now you have to do a lookup of: script => line => variable => line -- in comparison to: script => line ... we clearly must have a diverging counting system. So no, your why has not been discussed in a convincing way.
And again it's to avoid adding steps also to external consumers of the CI file - adding additional dependencies (such as make) for them to build parts of the application is in contrast to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@merlin-northern I could add the new env var to https://github.com/mendersoftware/mender-server/blob/main/.env And if you use the likes of direnv, you would be able to copy and use the CI commands withouth having to think about the env var. Would that work dor you?
@vpodzime Yeah I wasn't sure how this team approaches features in and around testing. I will reword the commits. |
I'm not an expert here and I don't have a strong opinion. If I understand correctly @dhaustein wants to standardize things, which is good, and @mzedel is trying to avoid issues, which is also good. As for the arguments:
In programming I think this would be a good case for using const, but there are no consts in gitlab. Still I get the idea of having it organized this way.
I agree that if we see the risk in the change and we've seen some issues caused by similar approach in the past I would skip this change. So as for this particular change/commit +1 for replacing cd with prefix and -1 for replacing |
My two cents here; as for my experience when testing CI pipelines locally, I found very valuable the direnv project: by having a
would solve both issues: you can run the same code from your terminal as in CI, and you can keep Gitlab best practices. This makes direnv as a requirements for the project, though.. Fell free to ignore my 2 cents |
Ticket: none Changelog: Updated the Deno image from debian-1.46.3 to debian-2.0.2 for the licenseCheck CI job Signed-off-by: Dusan Haustein <[email protected]>
Ticket: none Changelog: Add support for specifying root directory for checkGeneratedLicenses() in licenseCheck script Signed-off-by: Dusan Haustein <[email protected]>
Ticket: none Changelog: Centralize license-checker-rseidelsohn dependency in Deno imports Signed-off-by: Dusan Haustein <[email protected]>
Ticket: none Changelog: Removed unused steps for making and archiving the frontend/logs dir Signed-off-by: Dusan Haustein <[email protected]>
Ticket: none Changelog: none Signed-off-by: Dusan Haustein <[email protected]>
Ticket: none Changelog: Removed not needed SERVER_ROOT and GUI_REPOSITORY env vars supplied to the frontend/tests/e2e_tests/run script (the script exports the vars on its own) Signed-off-by: Dusan Haustein <[email protected]>
Ticket: none Changelog: Refactored the frontend pipeline to use a centralized FRONTEND_DIR variable instead of hardcoded 'frontend' paths and 'cd frontend' commands Signed-off-by: Dusan Haustein <[email protected]>
55c8d92
to
2feb7e2
Compare
Merging these commits will result in the following changelog entries: Changelogsmender-server (extract-paths-to-dirs)New changes in mender-server since main:
|
@oldgiova s mention of
made me think, maybe there is guidance from them on their CI - and turns out it's even better: their CI is of course open source. So you can go straight to their frontend file for an example on how they consider their CI to be used and they even share the same frontend name for their frontend things: https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/frontend.gitlab-ci.yml?ref_type=heads#L347 - turns out they use variables for things to be reassigned during the pipeline. I highly recommend anyone interested, but @dhaustein in particular to take a look through the main gitlab CI file and the corresponding includes folder. |
But that is exactly what I am trying to do with
|
I thought you were referring to the likes of
or the other The primary change in this PR is me trying to extract the repeated pattern of If your problem is that this would create a new variable, we can go with something like:
Which is a style Gitlab's CI code uses, too. However, this would mean having an instance of:
in every job that wants to use this var again. |
@dhaustein look again please. It's quite consistent among the files (e.g. https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/gitlab-gems.gitlab-ci.yml and the 15 repetitions of the |
@mzedel Yes, however the usage of variables in includes is limited https://docs.gitlab.com/ci/yaml/includes/#use-variables-with-include They cannot replace the common filepath with a var, not within the job at least, they'd have to define it in the global CI/CD settings which would hide the value to a completely different place. On our end for example - our yocto pipeline hinges on The thing is complex sure, but for one the usage of I know DRY is not a dogma, but generally a good idea. What should I change in this regard so that you are more receptive to these changes? |
To the handling in the yocto pipeline... I think that's a very, very different setup, as the client pipeline relies on multiple repositories (getting dependencies as submodules or cloning them, building them inside and going back again) and at least I haven't touched the build steps of any of this (as personally I found both the Jenkins setup & the gitlab setup not at all clear to work in + I lack the client knowledge to make informed decisions there). I'd be happy to have a chat about the reasons for the switch from Jenkins in the first place & things we considered - maybe we can do this once Lluis is back..? So my recommendation would rather be to not make steps to the (afaict more Jenkins-aligned) mender-qa setup, but instead decouple mender-qa if possible & align with Gitlab built in features to no longer need the As to the PR here: I think the removal of Regarding what's in the gitlab repo:
That would address the |
Thanks all. @mzedel @dhaustein let's land the clear wins and pause the contentious part. @dhaustein the DRY principle is a guideline, not an absolute law. It is most useful when abstracting values that might change. The name of the main What I propose is:
Also, please keep the discussion to the technical arguments here and other things (process/ownership) let's discuss elsewhere. |
${FRONTEND_DIR}
variable throughout--prefix
instead ofcd
commandsdebian-1.46.3
todebian-2.0.2
for the licenseCheck joblicenseCheck
script to not be hardcoded to use only current directorylicense-checker-rseidelsohn
todeno.json
(not sure if strictly needed but I saw some import errors without it)test:frontend:unit
job