|
1 | | -# Actions |
2 | | -Repo for GitHub actions and workflows |
| 1 | +# Process-PSModule |
| 2 | + |
| 3 | +A workflow for the PSModule process, stitching together the `Initialize`, `Build`, `Test`, and `Publish` actions to create a complete |
| 4 | +CI/CD pipeline for PowerShell modules. The workflow is used by all PowerShell modules in the PSModule organization. |
| 5 | + |
| 6 | +## Specifications and practices |
| 7 | + |
| 8 | +Process-PSModule follows: |
| 9 | + |
| 10 | +- [Test-Driven Development](https://testdriven.io/test-driven-development/) using [Pester](https://pester.dev) and [PSScriptAnalyzer](https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules) |
| 11 | +- [GitHub Flow specifications](https://docs.github.com/en/get-started/using-github/github-flow) |
| 12 | +- [SemVer 2.0.0 specifications](https://semver.org) |
| 13 | +- [Continiuous Delivery practices](https://en.wikipedia.org/wiki/Continuous_delivery) |
| 14 | + |
| 15 | +## How it works |
| 16 | + |
| 17 | +The workflow is designed to be trigger on pull requests to the repository's default branch. |
| 18 | +When a pull request is opened, closed, reopened, synchronized (push), or labeled, the workflow will run. |
| 19 | +Depending on the labels in the pull requests, the workflow will result in different outcomes. |
| 20 | + |
| 21 | +- [Initialize-PSModule](https://github.com/PSModule/Initialize-PSModule/) - To prepare the runner for all requirements of the framework. |
| 22 | +- [Test-PSModule](https://github.com/PSModule/Test-PSModule/) - Testing the source code using only PSScriptAnalyzer and the PSModule test suites. |
| 23 | +- [Build-PSModule](https://github.com/PSModule/Build-PSModule/) - To compile the repository into an efficient PowerShell module. |
| 24 | +- [Test-PSModule](https://github.com/PSModule/Test-PSModule/) - Testing the compiled module using PSScriptAnalyzer, PSModule test suites and custom module tests. |
| 25 | +- [Publish-PSModule](https://github.com/PSModule/Publish-PSModule/) - Publish the module to the PowerShell Gallery, publish docs to GitHub Pages, and create a release on the GitHub repository. |
| 26 | + |
| 27 | +To use the workflow, create a new file in the `.github/workflows` directory of the module repository and add the following content. |
| 28 | +<details> |
| 29 | +<summary>Workflow suggestion</summary> |
| 30 | + |
| 31 | +```yaml |
| 32 | +name: Process-PSModule |
| 33 | + |
| 34 | +on: |
| 35 | + pull_request: |
| 36 | + branches: |
| 37 | + - main |
| 38 | + types: |
| 39 | + - closed |
| 40 | + - opened |
| 41 | + - reopened |
| 42 | + - synchronize |
| 43 | + - labeled |
| 44 | + |
| 45 | +concurrency: |
| 46 | + group: ${{ github.workflow }} |
| 47 | + |
| 48 | +permissions: |
| 49 | + contents: write |
| 50 | + pull-requests: write |
| 51 | + |
| 52 | +jobs: |
| 53 | + Process-PSModule: |
| 54 | + uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@v1 |
| 55 | + secrets: inherit |
| 56 | + |
| 57 | +``` |
| 58 | +</details> |
| 59 | + |
| 60 | +## Usage |
| 61 | + |
| 62 | +### Inputs |
| 63 | + |
| 64 | +| Name | Type | Description | Required | Default | |
| 65 | +| ---- | ---- | ----------- | -------- | ------- | |
| 66 | +| `Name` | `string` | The name of the module to process. This defaults to the repository name if nothing is specified. | `false` | N/A | |
| 67 | +| `SkipTests` | `boolean` | Whether to skip the tests. | false | `false` | |
| 68 | +| `TestProcess` | `boolean` | Whether to test the process. | false | `false` | |
| 69 | + |
| 70 | +### Secrets |
| 71 | + |
| 72 | +The following secrets are **required** for the workflow to run: |
| 73 | + |
| 74 | +| Name | Location | Description | Default | |
| 75 | +| ---- | -------- | ----------- | ------- | |
| 76 | +| `GITHUB_TOKEN` | `github` context | The token used to authenticate with GitHub. | `${{ secrets.GITHUB_TOKEN }}` | |
| 77 | +| `APIKey` | GitHub secrets | The API key for the PowerShell Gallery. | N/A | |
| 78 | + |
| 79 | +## In detail |
| 80 | + |
| 81 | +The following steps will be run when the workflow triggers: |
| 82 | + |
| 83 | +- Checkout Code [actions/checkout](https://github.com/actions/checkout/) |
| 84 | + - Checks out the code of the repository to the runner. |
| 85 | +- Initialize environment [PSModule/Initialize-PSModule](https://github.com/PSModule/Initialize-PSModule/) |
| 86 | +- Test source code [PSModule/Test-PSModule](https://github.com/PSModule/Test-PSModule/) |
| 87 | + - Looks for the module in the `src` directory and runs the PSScriptAnalyzer and PSModule testing suite on the code. |
| 88 | +- Build module [PSModule/Build-PSModule](https://github.com/PSModule/Build-PSModule/) |
| 89 | + - Build the manifest file for the module. |
| 90 | + - Compiles the `src` directory into a PowerShell module and docs. |
| 91 | + - The compiled module is output to the `outputs/modules` directory. |
| 92 | + - The compiled docs are output to the `outputs/docs` directory. |
| 93 | +- Test built module [PSModule/Test-PSModule](https://github.com/PSModule/Test-PSModule/) |
| 94 | + - Looks for the module in the `outputs/modules` directory and runs the PSScriptAnalyzer, PSModule testing suite and the custom module tests from the `tests` directory on the code. |
| 95 | +- Publish module [PSModule/Publish-PSModule](https://github.com/PSModule/Publish-PSModule/) |
| 96 | + - Calculates the next version of the module based on the latest release and labels on the PR. |
| 97 | + - Publishes the module to the PowerShell Gallery using the API key stored in as a secret named `APIKey`. |
| 98 | + - Publishes the docs to GitHub Pages from the `outputs/docs` directory. |
| 99 | + - Creates a release on the GitHub repository with the source code. |
| 100 | + |
| 101 | +## Permissions |
| 102 | + |
| 103 | +The action requires the following permissions: |
| 104 | + |
| 105 | +If running the action in a restrictive mode, the following permissions needs to be granted to the action: |
| 106 | + |
| 107 | +```yaml |
| 108 | +permissions: |
| 109 | + contents: write # Required to create releases |
| 110 | + pull-requests: write # Required to create comments on the PRs |
| 111 | +``` |
0 commit comments