Skip to content

Commit fc0e9a7

Browse files
authored
fix: Update set-env and add-path to use Environment Files (#8)
* fix: Update set-env and add-path to use Env Files Actions runners will mark as warning using these old commands, instead these should write to special env files per https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/ fixes #6 * docs: Add Send-ActionFileCommand docs * docs: Update changelog * refactor: Add test script, change CI invocation * ci: fix testing no commands block * refactor: All tests using files use TestDrive
1 parent 5932e32 commit fc0e9a7

File tree

7 files changed

+354
-71
lines changed

7 files changed

+354
-71
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v2
1818
- name: Test with Pester
19-
run: |
20-
Install-Module -Name Pester -Force -SkipPublisherCheck -MinimumVersion '5.0'
21-
Import-Module Pester -MinimumVersion '5.0'
22-
Invoke-Pester -CI
19+
run: ./test.ps1
2320
- name: Invoke action
2421
env:
2522
TEMP: ${{ runner.temp }}
@@ -234,18 +231,20 @@ jobs:
234231
235232
# Invoke-ActionNoCommandsBlock
236233
- name: Invoke-ActionNoCommandsBlock test (act)
237-
uses: ./
238-
with:
239-
script: |
234+
id: Invoke-ActionNoCommandsBlock
235+
shell: pwsh
236+
run: |
237+
Import-Module ./lib/GitHubActionsCore -Force
240238
Invoke-ActionNoCommandsBlock -GenerateToken {
241-
Set-ActionVariable nocmdvar nocmd
239+
Set-ActionOutput testout testval
242240
}
243241
- name: Invoke-ActionNoCommandsBlock test (assert)
244242
uses: ./
245243
with:
246244
script: |
247-
if ($env:nocmdvar -ne $null) {
248-
throw "Invoke-ActionNoCommandsBlock failed.`n$env:nocmdvar"
245+
$result = '${{ steps.Invoke-ActionNoCommandsBlock.outputs.testout }}'
246+
if ($result) {
247+
throw "Invoke-ActionNoCommandsBlock failed.`n$result"
249248
}
250249
251250
# Write-Action -Debug, -Info, -Warning, -Error and Grouping are not testable in any sensible manner

CHANGELOG.md

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

8+
## [Unreleased]
9+
10+
### Added
11+
- `Send-ActionFileCommand` cmdlet that handles sending commands to [Environment Files] instead of console output ([#8]).
12+
13+
### Changed
14+
- `Add-ActionPath` and `Set-ActionVariable` are updated for [Environment Files] Actions Runner change ([#8]).
15+
16+
[Environment Files]: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#environment-files
17+
[#8]: https://github.com/Amadevus/pwsh-script/pull/8
18+
819
## [2.0.0] - 2020-09-10
920

1021
### Changed

docs/GitHubActionsCore/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
| [Invoke-ActionGroup](Invoke-ActionGroup.md) | Executes the argument script block within an output group. Equivalent of `core.group(name, func)`. |
1010
| [Invoke-ActionNoCommandsBlock](Invoke-ActionNoCommandsBlock.md) | Invokes a scriptblock that won't result in any output interpreted as a workflow command. Useful for printing arbitrary text that may contain command-like text. No quivalent in `@actions/core` package. |
1111
| [Send-ActionCommand](Send-ActionCommand.md) | Sends a command to the hosting Workflow/Action context. Equivalent to `core.issue(cmd, msg)`/`core.issueCommand(cmd, props, msg)`. |
12+
| [Send-ActionFileCommand](Send-ActionFileCommand.md) | Sends a command to an Action Environment File. Equivalent to `core.issueFileCommand(cmd, msg)`. |
1213
| [Set-ActionCommandEcho](Set-ActionCommandEcho.md) | Enables or disables the echoing of commands into stdout for the rest of the step. Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set. Equivalent of `core.setCommandEcho(enabled)`. |
1314
| [Set-ActionFailed](Set-ActionFailed.md) | Sets an action status to failed. When the action exits it will be with an exit code of 1. Equivalent of `core.setFailed(message)`. |
1415
| [Set-ActionOutput](Set-ActionOutput.md) | Sets the value of an output. Equivalent of `core.setOutput(name, value)`. |
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Send-ActionFileCommand
2+
```
3+
4+
NAME
5+
Send-ActionFileCommand
6+
7+
SYNOPSIS
8+
Sends a command to an Action Environment File.
9+
Equivalent to `core.issueFileCommand(cmd, msg)`.
10+
11+
12+
SYNTAX
13+
Send-ActionFileCommand [-Command] <String> [-Message] <PSObject> [<CommonParameters>]
14+
15+
16+
DESCRIPTION
17+
Appends given message to an Action Environment File.
18+
19+
20+
PARAMETERS
21+
-Command <String>
22+
Command (environment file variable suffix) to send message for.
23+
24+
Required? true
25+
Position? 1
26+
Default value
27+
Accept pipeline input? false
28+
Accept wildcard characters? false
29+
30+
-Message <PSObject>
31+
Message to append.
32+
33+
Required? true
34+
Position? 2
35+
Default value
36+
Accept pipeline input? true (ByValue)
37+
Accept wildcard characters? false
38+
39+
<CommonParameters>
40+
This cmdlet supports the common parameters: Verbose, Debug,
41+
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
42+
OutBuffer, PipelineVariable, and OutVariable. For more information, see
43+
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
44+
45+
INPUTS
46+
47+
OUTPUTS
48+
49+
-------------------------- EXAMPLE 1 --------------------------
50+
51+
PS>Send-ActionFileCommand ENV 'myvar=value'
52+
53+
54+
55+
56+
57+
58+
-------------------------- EXAMPLE 2 --------------------------
59+
60+
PS>'myvar=value', 'myvar2=novalue' | Send-ActionFileCommand ENV
61+
62+
63+
64+
65+
66+
67+
68+
RELATED LINKS
69+
https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#environment-files
70+
71+
```
72+

0 commit comments

Comments
 (0)