Skip to content

Commit fb0137b

Browse files
🚀 [Feature]: Add optional secrets for test application in reusable workflows (#53)
## Description - Add optional secrets to test module that interact with APIs in CI workflows. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [x] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 0eed8cb commit fb0137b

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

.github/workflows/CI.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ name: Process-PSModule - CI
22

33
on:
44
workflow_call:
5+
secrets:
6+
APIKey:
7+
description: The API key to use when publishing modules
8+
required: true
9+
TEST_APP_CLIENT_ID:
10+
description: The client ID for the test application
11+
required: false
12+
TEST_APP_PRIVATE_KEY:
13+
description: The private key for the test application
14+
required: false
15+
TEST_FG_PAT:
16+
description: The personal access token for the test application
17+
required: false
18+
TEST_PAT:
19+
description: The personal access token for the test application
20+
required: false
521
inputs:
622
Name:
723
type: string
@@ -49,6 +65,10 @@ on:
4965

5066
env:
5167
GITHUB_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication
68+
TEST_APP_CLIENT_ID: ${{ secrets.TEST_APP_CLIENT_ID }}
69+
TEST_APP_PRIVATE_KEY: ${{ secrets.TEST_APP_PRIVATE_KEY }}
70+
TEST_FG_PAT: ${{ secrets.TEST_FG_PAT }}
71+
TEST_PAT: ${{ secrets.TEST_PAT }}
5272

5373
permissions:
5474
contents: read # to checkout the repository

.github/workflows/workflow.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ on:
66
APIKey:
77
description: The API key to use when publishing modules
88
required: true
9+
TEST_APP_CLIENT_ID:
10+
description: The client ID for the test application
11+
required: false
12+
TEST_APP_PRIVATE_KEY:
13+
description: The private key for the test application
14+
required: false
15+
TEST_FG_PAT:
16+
description: The personal access token for the test application
17+
required: false
18+
TEST_PAT:
19+
description: The personal access token for the test application
20+
required: false
921
inputs:
1022
Name:
1123
type: string
@@ -58,6 +70,10 @@ on:
5870

5971
env:
6072
GITHUB_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication
73+
TEST_APP_CLIENT_ID: ${{ secrets.TEST_APP_CLIENT_ID }}
74+
TEST_APP_PRIVATE_KEY: ${{ secrets.TEST_APP_PRIVATE_KEY }}
75+
TEST_FG_PAT: ${{ secrets.TEST_FG_PAT }}
76+
TEST_PAT: ${{ secrets.TEST_PAT }}
6177

6278
permissions:
6379
contents: write # to checkout the repo and create releases on the repo
@@ -446,6 +462,12 @@ jobs:
446462
fetch-depth: 0
447463
ref: ${{ github.event.pull_request.head.sha }}
448464

465+
- name: Initialize environment
466+
uses: PSModule/Initialize-PSModule@v1
467+
with:
468+
Version: ${{ inputs.Version }}
469+
Prerelease: ${{ inputs.Prerelease }}
470+
449471
- name: Download docs artifact
450472
uses: actions/download-artifact@v4
451473
with:

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,17 @@ jobs:
8282

8383
### Secrets
8484

85-
The following secrets are **required** for the workflow to run:
85+
The following secrets are used by the workflow. They can be automatically provided (if available) by setting the `secrets: inherit`
86+
in the workflow file.
8687

8788
| Name | Location | Description | Default |
8889
| ---- | -------- | ----------- | ------- |
8990
| `GITHUB_TOKEN` | `github` context | The token used to authenticate with GitHub. | `${{ secrets.GITHUB_TOKEN }}` |
9091
| `APIKey` | GitHub secrets | The API key for the PowerShell Gallery. | N/A |
92+
| `TEST_APP_CLIENT_ID` | GitHub secrets | The client ID for running tests. | N/A |
93+
| `TEST_APP_PRIVATE_KEY` | GitHub secrets | The private key for running tests. | N/A |
94+
| `TEST_FG_PAT` | GitHub secrets | The fine-grained personal access token for running tests. | N/A |
95+
| `TEST_PAT` | GitHub secrets | The classic personal access token for running tests. | N/A |
9196

9297
## Permissions
9398

tests/tests/PSModuleTest.Tests.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ Param(
77

88
Write-Verbose "Path to the module: [$Path]" -Verbose
99

10+
Describe 'Environment Variables are available' {
11+
It 'Should be available [<_>]' -ForEach @('TEST_APP_CLIENT_ID', 'TEST_APP_PRIVATE_KEY', 'TEST_FG_PAT', 'TEST_PAT') {
12+
$name = $_
13+
Write-Verbose "Environment variable: [$name]" -Verbose
14+
Get-ChildItem env: | Where-Object { $_.Name -eq $name } | Should -Not -BeNullOrEmpty
15+
}
16+
}
17+
1018
Describe 'PSModuleTest.Tests.ps1' {
1119
Context 'Function: Test-PSModuleTest' {
1220
It 'Should be able to call the function' {

0 commit comments

Comments
 (0)