Skip to content

Commit 723ac80

Browse files
Fix workflow lint and script analyzer findings
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 18fe88d commit 723ac80

5 files changed

Lines changed: 90 additions & 19 deletions

File tree

.github/scripts/docs/Cleanup-PreviewDocs.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
deployments, deletes the preview environment, and updates the PR comment.
1010
1111
.EXAMPLE
12-
./Cleanup-PreviewDocs.ps1 -Repository "PSModule/docs" -Token $token -PullRequestNumber 42 -PreviewUrl "https://psmodule.io/docs/previews/pr-42/" -EnvironmentName "pr-preview-42"
12+
./Cleanup-PreviewDocs.ps1 `
13+
-Repository "PSModule/docs" `
14+
-Token $token `
15+
-PullRequestNumber 42 `
16+
-PreviewUrl "https://psmodule.io/docs/previews/pr-42/" `
17+
-EnvironmentName "pr-preview-42"
1318
#>
1419
[CmdletBinding()]
1520
param(
@@ -79,13 +84,13 @@ foreach ($deployment in $deployments) {
7984
Invoke-Gh -Arguments @('api', '--method', 'DELETE', "repos/$Repository/deployments/$($deployment.id)") | Out-Null
8085
}
8186

82-
$deleteEnvironmentExit = Invoke-Gh -Arguments @('api', '--method', 'DELETE', "repos/$Repository/environments/$EnvironmentName") -AllowFailure
87+
Invoke-Gh -Arguments @('api', '--method', 'DELETE', "repos/$Repository/environments/$EnvironmentName") -AllowFailure | Out-Null
8388
if ($LASTEXITCODE -ne 0) {
84-
$environmentCheckExit = Invoke-Gh -Arguments @('api', "repos/$Repository/environments/$EnvironmentName") -AllowFailure
89+
Invoke-Gh -Arguments @('api', "repos/$Repository/environments/$EnvironmentName") -AllowFailure | Out-Null
8590
if ($LASTEXITCODE -eq 0) {
8691
throw "Failed to delete environment '$EnvironmentName'."
8792
}
8893
}
8994

9095
$commentBody = "<!-- docs-pr-preview -->`n🧹 Preview removed: $PreviewUrl"
91-
Upsert-IssueComment -Repository $Repository -IssueNumber $PullRequestNumber -Marker '<!-- docs-pr-preview -->' -Body $commentBody
96+
Update-IssueComment -Repository $Repository -IssueNumber $PullRequestNumber -Marker '<!-- docs-pr-preview -->' -Body $commentBody

.github/scripts/docs/Publish-LiveDocs.ps1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
the updated branch using the GitHub App token identity.
1010
1111
.EXAMPLE
12-
./Publish-LiveDocs.ps1 -Repository "PSModule/docs" -Token $token -BuildDirectory "$PWD/src/site" -CommitSha $env:GITHUB_SHA
12+
./Publish-LiveDocs.ps1 `
13+
-Repository "PSModule/docs" `
14+
-Token $token `
15+
-BuildDirectory "$PWD/src/site" `
16+
-CommitSha $env:GITHUB_SHA
1317
#>
1418
[CmdletBinding()]
1519
param(
@@ -70,11 +74,11 @@ Invoke-Git -Arguments @('-C', $PagesDirectory, 'add', '-A')
7074

7175
$status = (& git -C $PagesDirectory status --porcelain)
7276
if ([string]::IsNullOrWhiteSpace($status)) {
73-
Set-WorkflowOutput -Name 'has_changes' -Value 'false'
77+
Write-WorkflowOutput -Name 'has_changes' -Value 'false'
7478
exit 0
7579
}
7680

7781
Invoke-Git -Arguments @('-C', $PagesDirectory, 'commit', '-m', "Deploy docs from $CommitSha")
7882
Invoke-Git -Arguments @('-C', $PagesDirectory, 'push', 'origin', "HEAD:refs/heads/$BaseBranch")
7983

80-
Set-WorkflowOutput -Name 'has_changes' -Value 'true'
84+
Write-WorkflowOutput -Name 'has_changes' -Value 'true'

.github/scripts/docs/Publish-PreviewDocs.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
pushes branch updates, and ensures the preview comment is present on the PR.
1010
1111
.EXAMPLE
12-
./Publish-PreviewDocs.ps1 -Repository "PSModule/docs" -Token $token -PullRequestNumber 42 -PreviewUrl "https://psmodule.io/docs/previews/pr-42/" -BuildDirectory "$PWD/src/site"
12+
./Publish-PreviewDocs.ps1 `
13+
-Repository "PSModule/docs" `
14+
-Token $token `
15+
-PullRequestNumber 42 `
16+
-PreviewUrl "https://psmodule.io/docs/previews/pr-42/" `
17+
-BuildDirectory "$PWD/src/site"
1318
#>
1419
[CmdletBinding()]
1520
param(
@@ -77,6 +82,6 @@ if (-not [string]::IsNullOrWhiteSpace($status)) {
7782

7883
$commentBody = "<!-- docs-pr-preview -->`n✅ Preview is ready: $PreviewUrl"
7984
$env:GH_TOKEN = $Token
80-
Upsert-IssueComment -Repository $Repository -IssueNumber $PullRequestNumber -Marker '<!-- docs-pr-preview -->' -Body $commentBody
85+
Update-IssueComment -Repository $Repository -IssueNumber $PullRequestNumber -Marker '<!-- docs-pr-preview -->' -Body $commentBody
8186

82-
Set-WorkflowOutput -Name 'url' -Value $PreviewUrl
87+
Write-WorkflowOutput -Name 'url' -Value $PreviewUrl

.github/scripts/docs/Shared.ps1

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ Set-StrictMode -Version Latest
22
$ErrorActionPreference = 'Stop'
33

44
function Invoke-Git {
5+
<#
6+
.SYNOPSIS
7+
Executes a git command and optionally allows non-zero exits.
8+
#>
59
param(
610
[Parameter(Mandatory = $true)]
711
[string[]]$Arguments,
@@ -17,7 +21,11 @@ function Invoke-Git {
1721
return $exitCode
1822
}
1923

20-
function Set-WorkflowOutput {
24+
function Write-WorkflowOutput {
25+
<#
26+
.SYNOPSIS
27+
Writes a named value to the GitHub Actions output file.
28+
#>
2129
param(
2230
[Parameter(Mandatory = $true)]
2331
[string]$Name,
@@ -33,6 +41,10 @@ function Set-WorkflowOutput {
3341
}
3442

3543
function Invoke-Gh {
44+
<#
45+
.SYNOPSIS
46+
Executes a gh command and optionally allows non-zero exits.
47+
#>
3648
param(
3749
[Parameter(Mandatory = $true)]
3850
[string[]]$Arguments,
@@ -48,7 +60,11 @@ function Invoke-Gh {
4860
return $output
4961
}
5062

51-
function Upsert-IssueComment {
63+
function Update-IssueComment {
64+
<#
65+
.SYNOPSIS
66+
Creates or updates a marker-based issue/PR comment.
67+
#>
5268
param(
5369
[Parameter(Mandatory = $true)]
5470
[string]$Repository,

.github/workflows/Docs.yml

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ jobs:
8181

8282
- name: Create GitHub App token
8383
id: app-token
84-
uses: actions/create-github-app-token@v2
84+
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2
8585
with:
8686
app-id: ${{ secrets.SCRIBBLER_BOT_CLIENT_ID }}
8787
private-key: ${{ secrets.SCRIBBLER_BOT_PRIVATE_KEY }}
88+
permission-contents: write
8889

8990
- name: Update index
9091
uses: ./.github/actions/update-index
@@ -107,7 +108,16 @@ jobs:
107108
- name: Publish live docs
108109
id: publish-live
109110
shell: pwsh
110-
run: ./.github/scripts/docs/Publish-LiveDocs.ps1 -Repository "${{ github.repository }}" -Token "${{ steps.app-token.outputs.token }}" -BuildDirectory "$PWD/src/site" -CommitSha "${{ github.sha }}"
111+
env:
112+
REPOSITORY: ${{ github.repository }}
113+
APP_TOKEN: ${{ steps.app-token.outputs.token }}
114+
COMMIT_SHA: ${{ github.sha }}
115+
run: |
116+
./.github/scripts/docs/Publish-LiveDocs.ps1 `
117+
-Repository $env:REPOSITORY `
118+
-Token $env:APP_TOKEN `
119+
-BuildDirectory "$PWD/src/site" `
120+
-CommitSha $env:COMMIT_SHA
111121
112122
preview:
113123
name: Preview
@@ -131,10 +141,12 @@ jobs:
131141

132142
- name: Create GitHub App token
133143
id: app-token
134-
uses: actions/create-github-app-token@v2
144+
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2
135145
with:
136146
app-id: ${{ secrets.SCRIBBLER_BOT_CLIENT_ID }}
137147
private-key: ${{ secrets.SCRIBBLER_BOT_PRIVATE_KEY }}
148+
permission-contents: write
149+
permission-issues: write
138150

139151
- name: Update index
140152
uses: ./.github/actions/update-index
@@ -152,15 +164,28 @@ jobs:
152164

153165
- name: Build preview site
154166
shell: pwsh
167+
env:
168+
PREVIEW_SITE_URL: ${{ env.PREVIEW_URL }}
155169
run: |
156-
./.github/scripts/docs/Set-ZensicalSiteUrl.ps1 -ConfigPath "$PWD/zensical.toml" -SiteUrl "${{ env.PREVIEW_URL }}"
170+
./.github/scripts/docs/Set-ZensicalSiteUrl.ps1 -ConfigPath "$PWD/zensical.toml" -SiteUrl $env:PREVIEW_SITE_URL
157171
zensical build --clean
158172
working-directory: src
159173

160174
- name: Publish preview docs
161175
id: preview-url
162176
shell: pwsh
163-
run: ./.github/scripts/docs/Publish-PreviewDocs.ps1 -Repository "${{ github.repository }}" -Token "${{ steps.app-token.outputs.token }}" -PullRequestNumber ${{ github.event.number }} -PreviewUrl "${{ env.PREVIEW_URL }}" -BuildDirectory "$PWD/src/site"
177+
env:
178+
REPOSITORY: ${{ github.repository }}
179+
APP_TOKEN: ${{ steps.app-token.outputs.token }}
180+
PR_NUMBER: ${{ github.event.number }}
181+
PREVIEW_SITE_URL: ${{ env.PREVIEW_URL }}
182+
run: |
183+
./.github/scripts/docs/Publish-PreviewDocs.ps1 `
184+
-Repository $env:REPOSITORY `
185+
-Token $env:APP_TOKEN `
186+
-PullRequestNumber $env:PR_NUMBER `
187+
-PreviewUrl $env:PREVIEW_SITE_URL `
188+
-BuildDirectory "$PWD/src/site"
164189
165190
preview-cleanup:
166191
name: Preview cleanup
@@ -181,11 +206,27 @@ jobs:
181206

182207
- name: Create GitHub App token
183208
id: app-token
184-
uses: actions/create-github-app-token@v2
209+
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2
185210
with:
186211
app-id: ${{ secrets.SCRIBBLER_BOT_CLIENT_ID }}
187212
private-key: ${{ secrets.SCRIBBLER_BOT_PRIVATE_KEY }}
213+
permission-administration: write
214+
permission-contents: write
215+
permission-deployments: write
216+
permission-issues: write
188217

189218
- name: Cleanup preview resources
190219
shell: pwsh
191-
run: ./.github/scripts/docs/Cleanup-PreviewDocs.ps1 -Repository "${{ github.repository }}" -Token "${{ steps.app-token.outputs.token }}" -PullRequestNumber ${{ github.event.number }} -PreviewUrl "${{ env.PREVIEW_URL }}" -EnvironmentName "${{ env.PREVIEW_ENVIRONMENT }}"
220+
env:
221+
REPOSITORY: ${{ github.repository }}
222+
APP_TOKEN: ${{ steps.app-token.outputs.token }}
223+
PR_NUMBER: ${{ github.event.number }}
224+
PREVIEW_SITE_URL: ${{ env.PREVIEW_URL }}
225+
PREVIEW_ENV: ${{ env.PREVIEW_ENVIRONMENT }}
226+
run: |
227+
./.github/scripts/docs/Cleanup-PreviewDocs.ps1 `
228+
-Repository $env:REPOSITORY `
229+
-Token $env:APP_TOKEN `
230+
-PullRequestNumber $env:PR_NUMBER `
231+
-PreviewUrl $env:PREVIEW_SITE_URL `
232+
-EnvironmentName $env:PREVIEW_ENV

0 commit comments

Comments
 (0)