Skip to content

Commit fb1fdf3

Browse files
committed
Allow disabling sending PR comments
Call PowerShell entrypoint script directly instead of calling bash first
1 parent 284d117 commit fb1fdf3

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [1.1.0] - 2018-01-06
9+
10+
### Changed
11+
12+
- Call PowerShell entrypoint script directly instead of calling bash first.
13+
- Allow disabling sending PSScriptAnalyzer results back to PR by setting the environment variable `PSSCRIPTANALYZER_SEND_COMMENT` to `false` or `0`.
14+
815
## [1.0.1] - 2018-12-28
916

1017
### Fixed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ action "PSScriptAnalyzer" {
3939
## Environment Variables
4040

4141
| Name | Default | Description |
42-
|--------------------------------|---------|-------------|
43-
| PSSCRIPTANALYZER_ROOT | . | The root directory to run PSScriptAnalyzer on. By default, this is the root of the repository.
42+
|--------------------------------|------|-------------|
43+
| PSSCRIPTANALYZER_ROOT | . | The root directory to run PSScriptAnalyzer on. By default, this is the root of the repository.
4444
| PSSCRIPTANALYZER_SETTINGS_PATH | none | The path to a PSScriptAnalyser settings file to control rules to execute.
45+
| PSSCRIPTANALYZER_SEND_COMMENT | true | Enable/disable sending comments with PSScriptAnalyzer results back to PR.
4546

4647
## Example
4748

analyze/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ LABEL "com.github.actions.icon" = "box"
1010
LABEL "com.github.actions.color" = "blue"
1111

1212
LABEL "name" = "github-action-psscriptanalyzer"
13-
LABEL "version" = "1.0.1"
13+
LABEL "version" = "1.1.0"
1414
LABEL "repository" = "https://github.com/devblackops/github-action-psscriptanalyzer"
1515
LABEL "homepage" = "https://github.com/PowerShell/PSScriptAnalyzer"
1616
LABEL "maintainer" = "Brandon Olin <[email protected]>"
1717

18-
ADD entrypoint.sh /entrypoint.sh
19-
ADD run.ps1 /run.ps1
18+
ADD entrypoint.ps1 /entrypoint.ps1
2019

2120
COPY LICENSE README.md /
2221

23-
RUN chmod +x /entrypoint.sh
22+
RUN chmod +x /entrypoint.ps1
2423

25-
ENTRYPOINT ["/entrypoint.sh"]
24+
ENTRYPOINT ["pwsh", "/entrypoint.ps1"]

analyze/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ action "PSScriptAnalyzer" {
3737
## Environment Variables
3838

3939
| Name | Default | Description |
40-
|--------------------------------|---------|-------------|
41-
| PSSCRIPTANALYZER_ROOT | . | The root directory to run PSScriptAnalyzer on. By default, this is the root of the repository.
40+
|--------------------------------|------|-------------|
41+
| PSSCRIPTANALYZER_ROOT | . | The root directory to run PSScriptAnalyzer on. By default, this is the root of the repository.
4242
| PSSCRIPTANALYZER_SETTINGS_PATH | none | The path to a PSScriptAnalyser settings file to control rules to execute.
43+
| PSSCRIPTANALYZER_SEND_COMMENT | true | Enable/disable sending comments with PSScriptAnalyzer results back to PR.
44+
45+
## Example
46+
47+
![](media/example.jpg)

analyze/run.ps1 renamed to analyze/entrypoint.ps1

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,24 @@ if (($warnings -gt 0) -or ($infos -gt 0)) {
5151
}
5252
Write-Output $comment
5353

54+
# Comment threshold
55+
56+
5457
# Send comment back to PR if any errors were found
55-
$ghEvent = Get-Content -Path $env:GITHUB_EVENT_PATH | ConvertFrom-Json
56-
if ($errors -gt 0) {
57-
$params = @{
58-
Uri = $ghEvent.pull_request.'_links'.comments.href
59-
Method = 'Post'
60-
Headers = @{
61-
Authorization = "token $env:GITHUB_TOKEN"
58+
if ($env:PSSCRIPTANALYZER_SEND_COMMENT -ne 'false' -and $env:PSSCRIPTANALYZER_SEND_COMMENT -ne 0) {
59+
if ($errors -gt 0) {
60+
$ghEvent = Get-Content -Path $env:GITHUB_EVENT_PATH | ConvertFrom-Json
61+
$params = @{
62+
Uri = $ghEvent.pull_request.'_links'.comments.href
63+
Method = 'Post'
64+
Headers = @{
65+
Authorization = "token $env:GITHUB_TOKEN"
66+
}
67+
ContentType = 'application/json'
68+
Body = @{body = $comment} | ConvertTo-Json
6269
}
63-
ContentType = 'application/json'
64-
Body = @{body = $comment} | ConvertTo-Json
70+
Invoke-RestMethod @params > $null
6571
}
66-
Invoke-RestMethod @params > $null
6772
}
6873

6974
exit $errors

analyze/entrypoint.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)