dsccommunity / AzureDevOpsDsc

This module contains DSC resources for deployment and configuration of initially Azure DevOps Services and later Azure DevOps Server.
MIT License
1 stars 5 forks source link

AzDevOpsProject: Azure DevOps, REST API Wrapper and AzDevOpsProject, DSC resource #7

Closed SphenicPaul closed 3 years ago

SphenicPaul commented 3 years ago

Pull Request (PR) description

@johlju / @kilasuit - I couldn't see this had moved much in a number of months and...

As a result, I've put the last few weeks into engineering something to start this module off and used the SqlServerDsc module as a comparison of sorts in getting to this point.

I had an existing set of PowerShell functions that I've used to form the basis of wrappers around the Azure DevOps REST API and I've tried to maintain the majority of the 'wrapper' functionality in a limited set of resources to encourage reuse (there's a little more information on module structure linked to from the 'contribution' document\readme).

This PR isn't completely ready to go (although there's possibly a lot in it - I'd like to think subsquent changes PRs would be much smaller), but I thought I'd put it out for review to get some feedback/improvements/suggestions etc.

Outstanding notes/points/actions:

(Note: I've steered away from depending directly on the client libraries as it stands)

This Pull Request (PR) fixes the following issues

Fixes #3 - Possibly? - This PR and it's changes might make this issue a non-issue

Task list


This change is Reviewable

gaelcolas commented 3 years ago

Great work! I've had a look at the structure to start with, as it'll be easier to review. After that we'll also need to look at the CI, but it may not be setup on this very recent repo.

Putting all the comments here about the overall structure so it's easier to read:

Enums

enums should be single ps1 files with 1 enum definition per file. Compilation will put them in the main module psm1. No needs for subfolders in enums

DSC folders

remove DscResources and DscClassResources (folder and files). The DscClassResources' classes will be moved (see below).

DSC Classes

Instead of source/DscClassResources/AzDevOpsProject/AzDevOpsProject.psm1 you should have: source/Classes/AzDevOpsProject.ps1. It will be compiled within your module's psm1, solving problems with importing other files (no need to dotSource).

Submodules

In your source/Modules/AzureDevopsDsc.Common, I'd recommend only having public/private If it really gets too big, it's usually an indication that it should be further split out. I also think that should probably be a module of its own, your call. If you feel that's too many functions for a single helper module, probably best to create other helper modules. burrying them to deep do not help discoverability.

Final note on the submodules, you ought to be able to build the PSM1 by merging the Public/Private/Classes... folder the same way as the top module. You have to have the psd1, configure build.yml's NestedModules, and remove CopyOnly: true (or set to false)

NestedModule:
  AzDevOpsProject.Common:
    CopyOnly: false
    AddToManifest: false

This is not documented, so let me know if any issue and I'll help. I may also be wrong :)

gaelcolas commented 3 years ago

Oh, I forgot, don't put anything in the Module.psm1. You add this at the top or the bottom using a prefix.ps1 or suffix.ps1 and then letting build.yml know like this: https://github.com/gaelcolas/Sampler/blob/master/build.yaml#L18

kilasuit commented 3 years ago

@SphenicPaul Firstly, thanks for all the effort that you've gone to, I can see that you've been very busy indeed. Just to set proper expectations I do intend to get to this on Friday (I unfortunately don't have much time this week till then) and dig deeper into this PR and properly review it.

A few quick things though

Looking forward to working with you on this going forward πŸ˜„

gaelcolas commented 3 years ago

Simply put, main is the new default for GitHub. It's a nice change, but we're not just ready yet.

@kilasuit You can only keep main if and when the whole pipeline works with it, which is something @PlagueHO has worked on, but I don't think it's ready just yet (let's catch up with him). Yes we can switch back to master until then, either @kilasuit or myself will do, whoever's got time first (probably not me until next week).

SphenicPaul commented 3 years ago

I've merged my most recent changes back into this PR (to update the Enums, DSC Folders and DSC Classes points raised).

Test coverage is currently about 50% (taking into account Unit tests only), largely due the ommission and duplication of class-related code-paths - It seems the functionality/code-paths in the classes are not registering as being tested (likely due to test setup following recent changes) and, in addition, the classes are being duplicated within the code coverage omissions (once in the 'Classes' directory and once within the output '.psm1' file).

I doubt (hope) there is much work to get these tests registering as part of the code coverage (and remove the duplication - I know this can be excluded in the build.yml, but I've left it as it is for now).

I'm pretty sure there is coverage for all bar 5 or so functions/methods, and the examples (which I believe get tested ... up to the point of generating the MOF... as part of the suite of DSC Resource tests as part of the build).

I'll leave this as it is for now until you've had a chance to take a look. I'm unlikely to look at making any changes to this before Sunday (29/11) or Monday, but will pickup/respond to feedback before then if I can.

johlju commented 3 years ago

@kilasuit do you have time to review this one? We need to fix the pipeline too, to support the branch rename. See blog post https://dsccommunity.org/blog/convert-master-to-main/

SphenicPaul commented 3 years ago

FWIW ... I've not been back to this for a little while, but I'm inclined to think that making use of some of the modules suggested by @kilasuit does make sense - There's lots of test coverage in my PR (with the exception of some of the classes) so even if we can get an initial build working, refactoring to use other modules should become much easier/cleaner (and I'm guessing any initial builds don't have to be "published" from day one?).

Meanwhile, given a few items that need doing to get the pipeline up and working, I'd probably suggest an initial (smaller πŸ˜… ) PR to get the build pipeline working off main, but I do still think that it's worth creating a "destructable", Azure DevOps Services collection and linking an API key (or API keys limited to functionality around specific resources) into that instance so the DSC build can perform integration tests against it - I got this working from my own builds and worked quite well (Note: the build template I used is in this PR and includes some modifications from the original one).

I'm happy to create a small PR with just the build-related changes in it if required (i.e. updated template and branch name) but you both may have more access/knowledge to tweak/debug and make any revisions to get the build working but it would be good to get to a point to know if a PR build from another fork/repository works against this repository ... it could also mean that we/I could trickle in smaller changes (possibly items already in this PR but in a set of smaller PRs that are easier to review/update).

Let me know if you need me to do anything - I'm only on Slack intermittently, so tag me here if needed.

johlju commented 3 years ago

@SphenicPaul We can merge this and build from it. I fixed the pipeline files in the repos so it should build against main branch correctly now. I kicked off the test in this PR to see if it looks good or if there is something easy to fix to get the pipeline to pass (if it does not pass).

SphenicPaul commented 3 years ago

@johlju - Looks like the unit tests in the PR were failing due to the lack of code coverage and the integration tests are failing due to a lack of an Integration environment (Azure DevOps Services instance) and related API key.

For now, I've lowered the Unit tests threshold (I intend to put this back up) to try and ensure we can get a build running to completion (even if it's not used initially).... looks like you've done this anyway πŸ˜„ .

In order to resolve the integration tests, the following variables need adding to the build/pipeline:

... and...

SphenicPaul commented 3 years ago

Also looks like there are now some items/errors relating to missing modules on the Linux boxes and errors with trying to use the Examples which probably need me to make some changes to the scripts.

johlju commented 3 years ago

I'm pushing some changes to see if we can get the unit tests to work at least. My thinking is that we merge this and then create issues for everything we find that needs fixing. At least this is a baseline to work from.

The problem is that the integration test cannot run for PR's since the secret pipeline values are not added to the build for PR's. That will make the build fail on main branch only, and then its "to late" to fix the build issue for the PR. So I'm thinking we should look at making the integration tests to run manually and each contributor can set there own "destructible" DevOps tenant.

I disabled the integration test in the pipeline for now. I can create an issue for the integration tests part.

johlju commented 3 years ago

Unit tests passing now. HQRM tests was running for all OS's an compiling examples does not work xplat yet, moved it to a separate job.

johlju commented 3 years ago

Merged. Let's continue the work form here.

SphenicPaul commented 3 years ago

OK. Thanks.

Your points make sense - I'll have a think on the Integration tests and post my initial thoughts in the issue (#9).