Test GH action: share data on current workflow #816
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'Test GH action: share data on current workflow' | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
schedule: | |
- cron: '0 0 * * 0' # Once a week: "At 00:00 on Sunday." | |
defaults: | |
run: | |
shell: pwsh | |
jobs: | |
trigger-info: | |
name: Trigger info | |
permissions: | |
contents: read | |
runs-on: ubuntu-latest | |
steps: | |
- name: Dump github context for debug purposes | |
env: | |
GITHUB_CONTEXT: ${{ toJSON(github) }} | |
run: $env:GITHUB_CONTEXT | |
- name: Trigger info | |
run: | | |
Write-Output "::notice::This workflow was triggered by a 'workflow_run' from '${{ github.event.workflow_run.name }}'." | |
test-failure: | |
name: test failure | |
permissions: | |
contents: read | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run action with bad input | |
id: set-bad-input | |
uses: ./action-local | |
continue-on-error: true | |
with: | |
command: set-data | |
data: | | |
invalid YAML input | |
- name: The action should fail the step if it encounters an error | |
run: | | |
$errorOutcome = '${{ steps.set-bad-input.outcome }}' | |
if($errorOutcome -eq 'success') { | |
Write-Output "::error title=Action check:Action should have failed the workflow because of invalid input but it didn't." | |
Exit 1 | |
} | |
else { | |
Write-Output "::notice title=Action check::Action would have failed the workflow given invalid input. You should see an error message on the action's Annotations." | |
} | |
set-data-with-github-step-json-output: | |
name: set-data command with github-step-json output | |
permissions: | |
contents: read | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set name value | |
id: set-name | |
run: | | |
# just to show an example that data to share can be built in different steps | |
# and then shared using this action | |
Write-Output "name=George Washington" >> $env:GITHUB_OUTPUT | |
- name: Run set-data command | |
id: set | |
uses: ./action-local | |
with: | |
command: set-data | |
artifact-name: from-set-with-github-step-json-output | |
# output: github-step-json # this is the default | |
data: | | |
name: ${{ steps.set-name.outputs.name }} | |
age: 89 | |
height_in_inches: 5.75 | |
addresses: | |
home: | |
street: | | |
400 Mockingbird Lane | |
address line 2 | |
city: Louaryland | |
state: Hawidaho | |
zip: 99970 | |
list: | |
- first | |
- second | |
- third | |
- name: Dump outputs from previous step | |
env: | |
STEP_OUTPUT: ${{ toJSON(steps.set.outputs) }} | |
run: $env:STEP_OUTPUT | |
- name: Verify set-data command output | |
run: | | |
$street = @' | |
400 Mockingbird Lane | |
address line 2 | |
'@ | |
if('${{ steps.set.outputs.name }}' -eq 'George Washington' ` | |
-and '${{ steps.set.outputs.age }}' -eq '89' ` | |
-and '${{ steps.set.outputs.height_in_inches }}' -eq '5.75' ` | |
-and '${{ steps.set.outputs.addresses_home_street }}' -eq $street ` | |
-and '${{ steps.set.outputs.addresses_home_city }}' -eq 'Louaryland' ` | |
-and '${{ steps.set.outputs.addresses_home_state }}' -eq 'Hawidaho' ` | |
-and '${{ steps.set.outputs.addresses_home_zip }}' -eq '99970' ` | |
-and '${{ steps.set.outputs.addresses_home_list_0_ }}' -eq 'first' ` | |
-and '${{ steps.set.outputs.addresses_home_list_1_ }}' -eq 'second' ` | |
-and '${{ steps.set.outputs.addresses_home_list_2_ }}' -eq 'third') | |
{ | |
Write-Output "Action produced expected output values." | |
Exit 0 | |
} | |
Write-Output "::error::Action didn't produce expected github-step-json output." | |
Exit 1 | |
set-data-with-strict-json-output: | |
name: set-data command with strict-json output | |
permissions: | |
contents: read | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run set-data command | |
id: set | |
uses: ./action-local | |
with: | |
command: set-data | |
artifact-name: from-set-with-strict-json-output | |
output: strict-json | |
data: | | |
name: George Washington | |
age: 89 | |
height_in_inches: 5.75 | |
addresses: | |
home: | |
street: | | |
400 Mockingbird Lane | |
address line 2 | |
city: Louaryland | |
state: Hawidaho | |
zip: 99970 | |
list: | |
- first | |
- second | |
- third | |
- name: Dump outputs from previous step | |
env: | |
STEP_OUTPUT: ${{ toJSON(steps.set.outputs) }} | |
run: $env:STEP_OUTPUT | |
- name: Verify set-data command output | |
run: | | |
# verify using github fromJson function | |
$street = @' | |
400 Mockingbird Lane | |
address line 2 | |
'@ | |
if('${{ fromJson(steps.set.outputs.data).name }}' -eq 'George Washington' ` | |
-and '${{ fromJson(steps.set.outputs.data).age }}' -eq '89' ` | |
-and '${{ fromJson(steps.set.outputs.data).height_in_inches }}' -eq '5.75' ` | |
-and '${{ fromJson(steps.set.outputs.data).addresses.home.street }}' -eq $street ` | |
-and '${{ fromJson(steps.set.outputs.data).addresses.home.city }}' -eq 'Louaryland' ` | |
-and '${{ fromJson(steps.set.outputs.data).addresses.home.state }}' -eq 'Hawidaho' ` | |
-and '${{ fromJson(steps.set.outputs.data).addresses.home.zip }}' -eq '99970' ` | |
-and '${{ fromJson(steps.set.outputs.data).addresses.home.list[0] }}' -eq 'first' ` | |
-and '${{ fromJson(steps.set.outputs.data).addresses.home.list[1] }}' -eq 'second' ` | |
-and '${{ fromJson(steps.set.outputs.data).addresses.home.list[2] }}' -eq 'third') | |
{ | |
Write-Output "Action produced expected output values." | |
Exit 0 | |
} | |
Write-Output "::error::Action didn't produce expected github-step-json output." | |
Exit 1 | |
- name: Verify set-data command output 2 | |
run: | | |
# verify using powershell | |
$data = '${{ steps.set.outputs.data }}' | ConvertFrom-Json | |
$street = @' | |
400 Mockingbird Lane | |
address line 2 | |
'@ | |
if($data.name -eq 'George Washington' ` | |
-and $data.age -eq '89' ` | |
-and $data.height_in_inches -eq '5.75' ` | |
-and $data.addresses.home.street -eq $street ` | |
-and $data.addresses.home.city -eq 'Louaryland' ` | |
-and $data.addresses.home.state -eq 'Hawidaho' ` | |
-and $data.addresses.home.zip -eq '99970' ` | |
-and $data.addresses.home.list[0] -eq 'first' ` | |
-and $data.addresses.home.list[1] -eq 'second' ` | |
-and $data.addresses.home.list[2] -eq 'third') | |
{ | |
Write-Output "Action produced expected output values." | |
Exit 0 | |
} | |
Write-Output "::error::Action didn't produce expected github-step-json output." | |
Exit 1 | |
set-data-with-none-output: | |
name: set-data command with none output | |
permissions: | |
contents: read | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run set-data command | |
id: set | |
uses: ./action-local | |
with: | |
command: set-data | |
output: none | |
data: | | |
name: George Washington | |
artifact-name: from-set-with-none-output | |
age: 89 | |
height_in_inches: 5.75 | |
addresses: | |
home: | |
street: | | |
400 Mockingbird Lane | |
address line 2 | |
city: Louaryland | |
state: Hawidaho | |
zip: 99970 | |
list: | |
- first | |
- second | |
- third | |
- name: Dump outputs from previous step | |
env: | |
STEP_OUTPUT: ${{ toJSON(steps.set.outputs) }} | |
run: $env:STEP_OUTPUT | |
- name: Verify set-data command output | |
run: | | |
if('${{ toJSON(steps.set.outputs) }}' -eq '{}') | |
{ | |
Write-Output "Action didn't produce any output as expected." | |
Exit 0 | |
} | |
Write-Output "::error::Action produced output when using output was set to none." | |
Exit 1 | |
read-data-current-workflow-with-github-step-json-output: | |
name: read-data-current-workflow command with github-step-json output | |
permissions: | |
contents: read | |
runs-on: ubuntu-latest | |
needs: [set-data-with-github-step-json-output] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run read-data-current-workflow command | |
id: read | |
uses: ./action-local | |
with: | |
command: read-data-current-workflow | |
artifact-name: from-set-with-github-step-json-output | |
# output: github-step-json # this is the default | |
- name: Dump outputs from previous step | |
env: | |
STEP_OUTPUT: ${{ toJSON(steps.read.outputs) }} | |
run: $env:STEP_OUTPUT | |
- name: Verify read-data-current-workflow command output | |
run: | | |
$street = @' | |
400 Mockingbird Lane | |
address line 2 | |
'@ | |
if('${{ steps.read.outputs.name }}' -eq 'George Washington' ` | |
-and '${{ steps.read.outputs.age }}' -eq '89' ` | |
-and '${{ steps.read.outputs.height_in_inches }}' -eq '5.75' ` | |
-and '${{ steps.read.outputs.addresses_home_street }}' -eq $street ` | |
-and '${{ steps.read.outputs.addresses_home_city }}' -eq 'Louaryland' ` | |
-and '${{ steps.read.outputs.addresses_home_state }}' -eq 'Hawidaho' ` | |
-and '${{ steps.read.outputs.addresses_home_zip }}' -eq '99970' ` | |
-and '${{ steps.read.outputs.addresses_home_list_0_ }}' -eq 'first' ` | |
-and '${{ steps.read.outputs.addresses_home_list_1_ }}' -eq 'second' ` | |
-and '${{ steps.read.outputs.addresses_home_list_2_ }}' -eq 'third') | |
{ | |
Write-Output "Action produced expected output values." | |
Exit 0 | |
} | |
Write-Output "::error::Action didn't produce expected github-step-json output." | |
Exit 1 | |
read-data-current-workflow-with-strict-json-output: | |
name: read-data-current-workflow command with strict-json output | |
permissions: | |
contents: read | |
runs-on: ubuntu-latest | |
needs: [set-data-with-strict-json-output] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run read-data-current-workflow command | |
id: read | |
uses: ./action-local | |
with: | |
command: read-data-current-workflow | |
artifact-name: from-set-with-strict-json-output | |
output: strict-json | |
- name: Dump outputs from previous step | |
env: | |
STEP_OUTPUT: ${{ toJSON(steps.read.outputs) }} | |
run: $env:STEP_OUTPUT | |
- name: Verify read-data-current-workflow command output | |
run: | | |
# verify using github fromJson function | |
$street = @' | |
400 Mockingbird Lane | |
address line 2 | |
'@ | |
if('${{ fromJson(steps.read.outputs.data).name }}' -eq 'George Washington' ` | |
-and '${{ fromJson(steps.read.outputs.data).age }}' -eq '89' ` | |
-and '${{ fromJson(steps.read.outputs.data).height_in_inches }}' -eq '5.75' ` | |
-and '${{ fromJson(steps.read.outputs.data).addresses.home.street }}' -eq $street ` | |
-and '${{ fromJson(steps.read.outputs.data).addresses.home.city }}' -eq 'Louaryland' ` | |
-and '${{ fromJson(steps.read.outputs.data).addresses.home.state }}' -eq 'Hawidaho' ` | |
-and '${{ fromJson(steps.read.outputs.data).addresses.home.zip }}' -eq '99970' ` | |
-and '${{ fromJson(steps.read.outputs.data).addresses.home.list[0] }}' -eq 'first' ` | |
-and '${{ fromJson(steps.read.outputs.data).addresses.home.list[1] }}' -eq 'second' ` | |
-and '${{ fromJson(steps.read.outputs.data).addresses.home.list[2] }}' -eq 'third') | |
{ | |
Write-Output "Action produced expected output values." | |
Exit 0 | |
} | |
Write-Output "::error::Action didn't produce expected github-step-json output." | |
Exit 1 | |
- name: Verify read-data-current-workflow command output 2 | |
run: | | |
# verify using powershell | |
$data = '${{ steps.read.outputs.data }}' | ConvertFrom-Json | |
$street = @' | |
400 Mockingbird Lane | |
address line 2 | |
'@ | |
if($data.name -eq 'George Washington' ` | |
-and $data.age -eq '89' ` | |
-and $data.height_in_inches -eq '5.75' ` | |
-and $data.addresses.home.street -eq $street ` | |
-and $data.addresses.home.city -eq 'Louaryland' ` | |
-and $data.addresses.home.state -eq 'Hawidaho' ` | |
-and $data.addresses.home.zip -eq '99970' ` | |
-and $data.addresses.home.list[0] -eq 'first' ` | |
-and $data.addresses.home.list[1] -eq 'second' ` | |
-and $data.addresses.home.list[2] -eq 'third') | |
{ | |
Write-Output "Action produced expected output values." | |
Exit 0 | |
} | |
Write-Output "::error::Action didn't produce expected github-step-json output." | |
Exit 1 |