Sampler Deeper - Taking your Module developm. a step further - Gael Colas,Rob Sewell - PSConfEU 2023
HTML-код
- Опубликовано: 6 июл 2023
- This is PART 2 of 2.
Part 1: • Intro Sampler- Taking ...
Complete title
Sampler Deeper - Taking your Module development and deployment a step further
Summary
Sampler automates tasks related to creating and managing modules in PowerShell. It allows users to merge functions into a single module, create a changelog, publish the module to the PowerShell gallery, and perform various other tasks. In the previous session, we covered the basics of defining module dependencies and resolving them using Sampler. Now, we provide examples of real-life use cases and go into more detail about how to use Sampler.
Sampler can be used not only for building modules but also for controlling environments and running tasks in CI/CD tools. I share examples of how we personally use Sampler, such as building machine configuration packages and Chocolaty packages, running scripts in CI/CD tools, and internalizing modules from the Chocolaty repository. There are many use cases for Sampler.
Next, we discuss setting up a module to make use of Sampler, using the example of the dbhx module. We explain the process of creating a new Sampler module, moving code into the source folder, organizing tests, defining required modules, and configuring PS Script Analyzer settings.
Moving on, we talk about organizing and transferring files within our project. We have moved the code of conduct, change log, and contributing files to their respective locations. The build docs file handles the building process, and we have added our license information. We have also made changes in the build.yaml file to define our build tasks and workflow. In the Pesta configuration, we adjusted the output path and format for test results. We removed unnecessary DSC components and added GitHub configurations. Additionally, we discussed the setup process in the developing directory within our GitHub repository. We have containers set up for different purposes, such as installing PowerShell and Git. Our DevContainer is controlled by DevContainer.json and Docker Compose to ensure a consistent and functional development environment. We also have various extensions and settings in place to enhance our coding experience, including Git Graph and error lens.
I mention that I set the environment configuration and explained it to Jess, who then implemented it. Claudio was struggling with failing tests due to extra white spaces in his code, but we resolved it by adding the environment configuration to our development container definition. This ensures that Claudio has the same experience as us and keeps our environment controlled. We use GitHub Actions and YAML files to automate our workflows. We set up environment variables and perform various stages such as checking out the code, installing Git version, building and packaging the module, and running tests on different platforms. We publish test results and set up badges on our repository to track progress. We can also deploy releases to GitHub and PowerShell Gallery. The containers branch allows us to update containers and create new images, which are then pushed to Docker Hub and incorporated into our docker-compose file. We keep all our changes in source control and automate the process as much as possible. This level of automation gives us control over our environment and simplifies the development process.
We can integrate the Sampler module with PowerShell to perform advanced functions. For example, we can add a new check to the code using the build.ps1 and tasks. We can run various tests using Pester and ensure everything is working well across different operating systems. By calling the build.ps1-publish, we can publish the module to the PowerShell gallery. To manage changelogs, we follow the standard of Keep a Changelog, which allows us to track and categorize changes for each version of the module. The changelog management module automatically updates the changelog and publishes it to GitHub and the PowerShell gallery.