From 82b75a1014dbb6c16a1dd210a79b33f925f1afa3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 22 Nov 2024 13:41:30 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20optional=20secr?= =?UTF-8?q?ets=20for=20test=20application=20in=20CI=20workflows=20and=20up?= =?UTF-8?q?date=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/CI.yml | 20 ++++++++++++++++++++ .github/workflows/workflow.yml | 22 ++++++++++++++++++++++ README.md | 7 ++++++- tests/tests/PSModuleTest.Tests.ps1 | 8 ++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e6dfd7af..6a3ebb06 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -2,6 +2,22 @@ name: Process-PSModule - CI on: workflow_call: + secrets: + APIKey: + description: The API key to use when publishing modules + required: true + TEST_APP_CLIENT_ID: + description: The client ID for the test application + required: false + TEST_APP_PRIVATE_KEY: + description: The private key for the test application + required: false + TEST_FG_PAT: + description: The personal access token for the test application + required: false + TEST_PAT: + description: The personal access token for the test application + required: false inputs: Name: type: string @@ -49,6 +65,10 @@ on: env: GITHUB_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication + TEST_APP_CLIENT_ID: ${{ secrets.TEST_APP_CLIENT_ID }} + TEST_APP_PRIVATE_KEY: ${{ secrets.TEST_APP_PRIVATE_KEY }} + TEST_FG_PAT: ${{ secrets.TEST_FG_PAT }} + TEST_PAT: ${{ secrets.TEST_PAT }} permissions: contents: read # to checkout the repository diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index c6801086..ac4b95c4 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -6,6 +6,18 @@ on: APIKey: description: The API key to use when publishing modules required: true + TEST_APP_CLIENT_ID: + description: The client ID for the test application + required: false + TEST_APP_PRIVATE_KEY: + description: The private key for the test application + required: false + TEST_FG_PAT: + description: The personal access token for the test application + required: false + TEST_PAT: + description: The personal access token for the test application + required: false inputs: Name: type: string @@ -58,6 +70,10 @@ on: env: GITHUB_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication + TEST_APP_CLIENT_ID: ${{ secrets.TEST_APP_CLIENT_ID }} + TEST_APP_PRIVATE_KEY: ${{ secrets.TEST_APP_PRIVATE_KEY }} + TEST_FG_PAT: ${{ secrets.TEST_FG_PAT }} + TEST_PAT: ${{ secrets.TEST_PAT }} permissions: contents: write # to checkout the repo and create releases on the repo @@ -446,6 +462,12 @@ jobs: fetch-depth: 0 ref: ${{ github.event.pull_request.head.sha }} + - name: Initialize environment + uses: PSModule/Initialize-PSModule@v1 + with: + Version: ${{ inputs.Version }} + Prerelease: ${{ inputs.Prerelease }} + - name: Download docs artifact uses: actions/download-artifact@v4 with: diff --git a/README.md b/README.md index b6458aae..10c66f0f 100644 --- a/README.md +++ b/README.md @@ -82,12 +82,17 @@ jobs: ### Secrets -The following secrets are **required** for the workflow to run: +The following secrets are used by the workflow. They can be automatically provided (if available) by setting the `secrets: inherit` +in the workflow file. | Name | Location | Description | Default | | ---- | -------- | ----------- | ------- | | `GITHUB_TOKEN` | `github` context | The token used to authenticate with GitHub. | `${{ secrets.GITHUB_TOKEN }}` | | `APIKey` | GitHub secrets | The API key for the PowerShell Gallery. | N/A | +| `TEST_APP_CLIENT_ID` | GitHub secrets | The client ID for running tests. | N/A | +| `TEST_APP_PRIVATE_KEY` | GitHub secrets | The private key for running tests. | N/A | +| `TEST_FG_PAT` | GitHub secrets | The fine-grained personal access token for running tests. | N/A | +| `TEST_PAT` | GitHub secrets | The classic personal access token for running tests. | N/A | ## Permissions diff --git a/tests/tests/PSModuleTest.Tests.ps1 b/tests/tests/PSModuleTest.Tests.ps1 index 29095d14..e17ad000 100644 --- a/tests/tests/PSModuleTest.Tests.ps1 +++ b/tests/tests/PSModuleTest.Tests.ps1 @@ -7,6 +7,14 @@ Param( Write-Verbose "Path to the module: [$Path]" -Verbose +Describe 'Environment Variables are available' { + It 'Should be available [<_>]' -ForEach @('TEST_APP_CLIENT_ID', 'TEST_APP_PRIVATE_KEY', 'TEST_FG_PAT', 'TEST_PAT') { + $name = $_ + Write-Verbose "Environment variable: [$name]" -Verbose + Get-ChildItem env: | Where-Object { $_.Name -eq $name } | Should -Not -BeNullOrEmpty + } +} + Describe 'PSModuleTest.Tests.ps1' { Context 'Function: Test-PSModuleTest' { It 'Should be able to call the function' {