Skip to content

Commit

Permalink
fix: Update set-env and add-path to use Environment Files (#8)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
amis92 committed Feb 5, 2021
1 parent 5932e32 commit fc0e9a7
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 71 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Test with Pester
run: |
Install-Module -Name Pester -Force -SkipPublisherCheck -MinimumVersion '5.0'
Import-Module Pester -MinimumVersion '5.0'
Invoke-Pester -CI
run: ./test.ps1
- name: Invoke action
env:
TEMP: ${{ runner.temp }}
Expand Down Expand Up @@ -234,18 +231,20 @@ jobs:
# Invoke-ActionNoCommandsBlock
- name: Invoke-ActionNoCommandsBlock test (act)
uses: ./
with:
script: |
id: Invoke-ActionNoCommandsBlock
shell: pwsh
run: |
Import-Module ./lib/GitHubActionsCore -Force
Invoke-ActionNoCommandsBlock -GenerateToken {
Set-ActionVariable nocmdvar nocmd
Set-ActionOutput testout testval
}
- name: Invoke-ActionNoCommandsBlock test (assert)
uses: ./
with:
script: |
if ($env:nocmdvar -ne $null) {
throw "Invoke-ActionNoCommandsBlock failed.`n$env:nocmdvar"
$result = '${{ steps.Invoke-ActionNoCommandsBlock.outputs.testout }}'
if ($result) {
throw "Invoke-ActionNoCommandsBlock failed.`n$result"
}
# Write-Action -Debug, -Info, -Warning, -Error and Grouping are not testable in any sensible manner
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- `Send-ActionFileCommand` cmdlet that handles sending commands to [Environment Files] instead of console output ([#8]).

### Changed
- `Add-ActionPath` and `Set-ActionVariable` are updated for [Environment Files] Actions Runner change ([#8]).

[Environment Files]: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#environment-files
[#8]: https://github.com/Amadevus/pwsh-script/pull/8

## [2.0.0] - 2020-09-10

### Changed
Expand Down
1 change: 1 addition & 0 deletions docs/GitHubActionsCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
| [Invoke-ActionGroup](Invoke-ActionGroup.md) | Executes the argument script block within an output group. Equivalent of `core.group(name, func)`. |
| [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. |
| [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)`. |
| [Send-ActionFileCommand](Send-ActionFileCommand.md) | Sends a command to an Action Environment File. Equivalent to `core.issueFileCommand(cmd, msg)`. |
| [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)`. |
| [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)`. |
| [Set-ActionOutput](Set-ActionOutput.md) | Sets the value of an output. Equivalent of `core.setOutput(name, value)`. |
Expand Down
72 changes: 72 additions & 0 deletions docs/GitHubActionsCore/Send-ActionFileCommand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Send-ActionFileCommand
```
NAME
Send-ActionFileCommand
SYNOPSIS
Sends a command to an Action Environment File.
Equivalent to `core.issueFileCommand(cmd, msg)`.
SYNTAX
Send-ActionFileCommand [-Command] <String> [-Message] <PSObject> [<CommonParameters>]
DESCRIPTION
Appends given message to an Action Environment File.
PARAMETERS
-Command <String>
Command (environment file variable suffix) to send message for.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Message <PSObject>
Message to append.
Required? true
Position? 2
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS>Send-ActionFileCommand ENV 'myvar=value'
-------------------------- EXAMPLE 2 --------------------------
PS>'myvar=value', 'myvar2=novalue' | Send-ActionFileCommand ENV
RELATED LINKS
https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#environment-files
```

Loading

0 comments on commit fc0e9a7

Please sign in to comment.