From 2c309baf40ca427183e0fd8f224f9a56d466cfa0 Mon Sep 17 00:00:00 2001 From: Shayki Abramczyk Date: Tue, 23 Jul 2024 15:33:53 +0300 Subject: [PATCH] Update test.yaml --- .github/workflows/test.yaml | 47 +++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c3ac97c..1cfbc55 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,46 +17,63 @@ on: type: number jobs: - test-inputs: + test-push-pull-request: runs-on: ubuntu-latest + if: github.event_name == 'push' || github.event_name == 'pull_request' steps: - uses: actions/checkout@v3 - - name: Run action (inputs only) + - name: Run action (no inputs expected) uses: ./ id: print_inputs - - name: Check output (inputs only) + - name: Check output (no inputs expected) + run: | + echo "Action output:" + echo "${{ steps.print_inputs.outputs.output }}" + + if [[ "${{ steps.print_inputs.outputs.output }}" == *"No workflow_dispatch inputs found in the event payload."* ]]; then + echo "Test passed: No inputs were found, as expected for push/pull_request events" + else + echo "Test failed: Unexpected output for push/pull_request events" + exit 1 + fi + + test-workflow-dispatch: + runs-on: ubuntu-latest + if: github.event_name == 'workflow_dispatch' + steps: + - uses: actions/checkout@v3 + - name: Run action (inputs expected) + uses: ./ + id: print_inputs + - name: Check output (inputs expected) run: | echo "Action output:" echo "${{ steps.print_inputs.outputs.output }}" if [[ "${{ steps.print_inputs.outputs.output }}" == *"test_name"* && "${{ steps.print_inputs.outputs.output }}" == *"test_number"* ]]; then - echo "Test passed: Inputs were printed correctly" + echo "Test passed: Inputs were printed correctly for workflow_dispatch event" else - echo "Test failed: Inputs were not printed as expected" - echo "Expected to find 'test_name' and 'test_number' in the output" + echo "Test failed: Inputs were not printed as expected for workflow_dispatch event" exit 1 fi - test-inputs-and-env: + test-env-vars: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Run action (inputs and env vars) + - name: Run action (with env vars) uses: ./ id: print_inputs_and_env with: print_env_vars: 'true' - - name: Check output (inputs and env vars) + - name: Check output (env vars) run: | echo "Action output:" echo "${{ steps.print_inputs_and_env.outputs.output }}" - if [[ "${{ steps.print_inputs_and_env.outputs.output }}" == *"test_name"* && - "${{ steps.print_inputs_and_env.outputs.output }}" == *"test_number"* && - "${{ steps.print_inputs_and_env.outputs.output }}" == *"Printing environment variables:"* ]]; then - echo "Test passed: Inputs and env vars were printed correctly" + if [[ "${{ steps.print_inputs_and_env.outputs.output }}" == *"Printing environment variables:"* && "${{ steps.print_inputs_and_env.outputs.output }}" == *"GITHUB_"* ]]; then + echo "Test passed: Environment variables were printed correctly" else - echo "Test failed: Inputs or env vars were not printed as expected" - echo "Expected to find 'test_name', 'test_number', and 'Printing environment variables:' in the output" + echo "Test failed: Environment variables were not printed as expected" exit 1 fi