Skip to content

Commit 0b0fedc

Browse files
Fix [Ignore label] test: add EventJson input so tests can pass event data without relying on event file
1 parent d35dd9e commit 0b0fedc

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

.github/workflows/Action-Test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ jobs:
360360
}
361361
}
362362
EventPath: ${{ runner.temp }}/fake-event.json
363+
EventJson: '{"pull_request":{"head":{"ref":"feat/test-ignore"},"labels":[{"name":"patch"},{"name":"skip-release"}]}}'
363364

364365
- name: Verify - Ignore label
365366
shell: pwsh

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ inputs:
3535
description: Path to the GitHub event JSON file. Defaults to the standard GitHub event path. Override for testing.
3636
required: false
3737
default: ''
38+
EventJson:
39+
description: GitHub event payload as a JSON string. When set, overrides reading from the event file. Use for testing.
40+
required: false
41+
default: ''
3842

3943
outputs:
4044
Version:
@@ -71,6 +75,7 @@ runs:
7175
env:
7276
PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_Settings: ${{ inputs.Settings }}
7377
PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_Name: ${{ inputs.Name }}
78+
PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson: ${{ inputs.EventJson }}
7479
PSMODULE_ACTION_PATH: ${{ github.action_path }}
7580
GITHUB_EVENT_PATH: ${{ inputs.EventPath || github.event_path }}
7681
run: |

scripts/main.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ LogGroup 'Resolve configuration' {
5959
}
6060

6161
LogGroup 'Event information' {
62-
$githubEventJson = Get-Content $env:GITHUB_EVENT_PATH
63-
$githubEvent = $githubEventJson | ConvertFrom-Json
62+
$eventJsonInput = $env:PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson
63+
if (-not [string]::IsNullOrWhiteSpace($eventJsonInput)) {
64+
$githubEvent = $eventJsonInput | ConvertFrom-Json
65+
} else {
66+
$githubEventJson = Get-Content $env:GITHUB_EVENT_PATH
67+
$githubEvent = $githubEventJson | ConvertFrom-Json
68+
}
6469
$pull_request = $githubEvent.pull_request
6570
if (-not $pull_request) {
6671
throw 'GitHub event does not contain pull_request data. This action must be run from a pull_request event.'

0 commit comments

Comments
 (0)