|
17 | 17 | type: number
|
18 | 18 |
|
19 | 19 | jobs:
|
20 |
| - test-inputs: |
| 20 | + test-push-pull-request: |
21 | 21 | runs-on: ubuntu-latest
|
| 22 | + if: github.event_name == 'push' || github.event_name == 'pull_request' |
22 | 23 | steps:
|
23 | 24 | - uses: actions/checkout@v3
|
24 |
| - - name: Run action (inputs only) |
| 25 | + - name: Run action (no inputs expected) |
25 | 26 | uses: ./
|
26 | 27 | id: print_inputs
|
27 |
| - - name: Check output (inputs only) |
| 28 | + - name: Check output (no inputs expected) |
| 29 | + run: | |
| 30 | + echo "Action output:" |
| 31 | + echo "${{ steps.print_inputs.outputs.output }}" |
| 32 | + |
| 33 | + if [[ "${{ steps.print_inputs.outputs.output }}" == *"No workflow_dispatch inputs found in the event payload."* ]]; then |
| 34 | + echo "Test passed: No inputs were found, as expected for push/pull_request events" |
| 35 | + else |
| 36 | + echo "Test failed: Unexpected output for push/pull_request events" |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | +
|
| 40 | + test-workflow-dispatch: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + if: github.event_name == 'workflow_dispatch' |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v3 |
| 45 | + - name: Run action (inputs expected) |
| 46 | + uses: ./ |
| 47 | + id: print_inputs |
| 48 | + - name: Check output (inputs expected) |
28 | 49 | run: |
|
29 | 50 | echo "Action output:"
|
30 | 51 | echo "${{ steps.print_inputs.outputs.output }}"
|
31 | 52 |
|
32 | 53 | if [[ "${{ steps.print_inputs.outputs.output }}" == *"test_name"* && "${{ steps.print_inputs.outputs.output }}" == *"test_number"* ]]; then
|
33 |
| - echo "Test passed: Inputs were printed correctly" |
| 54 | + echo "Test passed: Inputs were printed correctly for workflow_dispatch event" |
34 | 55 | else
|
35 |
| - echo "Test failed: Inputs were not printed as expected" |
36 |
| - echo "Expected to find 'test_name' and 'test_number' in the output" |
| 56 | + echo "Test failed: Inputs were not printed as expected for workflow_dispatch event" |
37 | 57 | exit 1
|
38 | 58 | fi
|
39 | 59 |
|
40 |
| - test-inputs-and-env: |
| 60 | + test-env-vars: |
41 | 61 | runs-on: ubuntu-latest
|
42 | 62 | steps:
|
43 | 63 | - uses: actions/checkout@v3
|
44 |
| - - name: Run action (inputs and env vars) |
| 64 | + - name: Run action (with env vars) |
45 | 65 | uses: ./
|
46 | 66 | id: print_inputs_and_env
|
47 | 67 | with:
|
48 | 68 | print_env_vars: 'true'
|
49 |
| - - name: Check output (inputs and env vars) |
| 69 | + - name: Check output (env vars) |
50 | 70 | run: |
|
51 | 71 | echo "Action output:"
|
52 | 72 | echo "${{ steps.print_inputs_and_env.outputs.output }}"
|
53 | 73 |
|
54 |
| - if [[ "${{ steps.print_inputs_and_env.outputs.output }}" == *"test_name"* && |
55 |
| - "${{ steps.print_inputs_and_env.outputs.output }}" == *"test_number"* && |
56 |
| - "${{ steps.print_inputs_and_env.outputs.output }}" == *"Printing environment variables:"* ]]; then |
57 |
| - echo "Test passed: Inputs and env vars were printed correctly" |
| 74 | + if [[ "${{ steps.print_inputs_and_env.outputs.output }}" == *"Printing environment variables:"* && "${{ steps.print_inputs_and_env.outputs.output }}" == *"GITHUB_"* ]]; then |
| 75 | + echo "Test passed: Environment variables were printed correctly" |
58 | 76 | else
|
59 |
| - echo "Test failed: Inputs or env vars were not printed as expected" |
60 |
| - echo "Expected to find 'test_name', 'test_number', and 'Printing environment variables:' in the output" |
| 77 | + echo "Test failed: Environment variables were not printed as expected" |
61 | 78 | exit 1
|
62 | 79 | fi
|
0 commit comments