From 29197bb527d181f097662cbf9465023f617f5919 Mon Sep 17 00:00:00 2001 From: Maksym Sobolyev Date: Thu, 23 Nov 2023 13:15:03 -0800 Subject: [PATCH] Split tests into individual jobs. --- .github/workflows/run-tests.yml | 27 +++++++++++++++++++++++---- actions/Publish_Logs/action.yml | 21 +++++++++++++++++++++ actions/Run_All_Tests/action.yml | 12 +----------- actions/Run_Test/action.yml | 20 ++++++++++++++++++++ actions/Set_Matrix/action.yml | 17 +++++++++++++++++ actions/read_matrix.py | 3 +++ 6 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 actions/Publish_Logs/action.yml create mode 100644 actions/Run_Test/action.yml create mode 100644 actions/Set_Matrix/action.yml create mode 100644 actions/read_matrix.py diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 23c9997..124c305 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -6,10 +6,27 @@ on: pull_request: jobs: + setup-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: - test: + - name: Prepare SIPssert + uses: OpenSIPS/SIPssert/actions/Prepare_SIPssert@main + with: + sipssert-repo: ${{ github.repository }} + tests-repo: OpenSIPS/sipssert-opensips-tests - runs-on: ubuntu-latest + - name: Read and parse YAML file + id: set-matrix + uses: ./sipssert/actions/Set_Matrix + + test: + needs: setup-matrix + strategy: + matrix: ${{fromJson(needs.setup-matrix.outputs.matrix)}} + runs-on: ${{ matrix.os }} steps: @@ -19,5 +36,7 @@ jobs: sipssert-repo: ${{ github.repository }} tests-repo: OpenSIPS/sipssert-opensips-tests - - name: Run All Tests - uses: OpenSIPS/SIPssert/actions/Run_All_Tests@main + - name: Run Test + uses: ./sipssert/actions/Run_Test + with: + scenario: ${{ matrix.scenario }} diff --git a/actions/Publish_Logs/action.yml b/actions/Publish_Logs/action.yml new file mode 100644 index 0000000..2a552ac --- /dev/null +++ b/actions/Publish_Logs/action.yml @@ -0,0 +1,21 @@ +name: 'Publish Logs' +description: 'Collect and upload logs for all scenarious' +inputs: + log_name: + description: "Name of logs after upload" + default: sipssert-logs + required: true +runs: + using: 'composite' + steps: + - name: Resolve logs path + run: | + cd tests + echo "LOGS_PATH=$(readlink -f logs/latest)" >> $GITHUB_ENV + shell: bash + + - name: Publish logs + uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.log_name }} + path: ${{ env.LOGS_PATH }} diff --git a/actions/Run_All_Tests/action.yml b/actions/Run_All_Tests/action.yml index e604d42..4122615 100644 --- a/actions/Run_All_Tests/action.yml +++ b/actions/Run_All_Tests/action.yml @@ -10,16 +10,6 @@ runs: sh -x ./run-all.sh shell: bash - - name: Resolve logs path - if: always() - run: | - cd tests - echo "LOGS_PATH=$(readlink -f logs/latest)" >> $GITHUB_ENV - shell: bash - - name: Publish logs - uses: actions/upload-artifact@v3 if: always() - with: - name: sipssert-logs - path: ${{ env.LOGS_PATH }} + uses: ./sipssert/actions/Publish_Logs diff --git a/actions/Run_Test/action.yml b/actions/Run_Test/action.yml new file mode 100644 index 0000000..4632ea6 --- /dev/null +++ b/actions/Run_Test/action.yml @@ -0,0 +1,20 @@ +name: 'Run Test' +description: 'Runs specific test, resolves the logs path, and uploads the logs' +inputs: + scenario: + description: "Name of scenario to run" + required: true +runs: + using: 'composite' + steps: + - name: Run All Tests + run: | + cd tests + SETS=${{ inputs.scenario }} sh -x ./run-all.sh + shell: bash + + - name: Publish logs + if: always() + uses: ./sipssert/actions/Publish_Logs + with: + log_name: sipssert-${{ inputs.scenario }}-logs diff --git a/actions/Set_Matrix/action.yml b/actions/Set_Matrix/action.yml new file mode 100644 index 0000000..e1f389f --- /dev/null +++ b/actions/Set_Matrix/action.yml @@ -0,0 +1,17 @@ +name: 'Read Job Matrix' +description: 'Read list of scenarious to run and output matrix.' +inputs: {} +outputs: + matrix: + description: "The job matrix" + value: ${{ steps.set-matrix.outputs.matrix }} +runs: + using: 'composite' + steps: + - name: Read and parse YAML file + id: set-matrix + run: | + echo "Reading YAML file to create matrix" + MATRIX=$(python3 sipssert/actions/read_matrix.py tests/matrix.yml) + echo "matrix=${MATRIX}" >> $GITHUB_OUTPUT + shell: bash diff --git a/actions/read_matrix.py b/actions/read_matrix.py new file mode 100644 index 0000000..f672ea2 --- /dev/null +++ b/actions/read_matrix.py @@ -0,0 +1,3 @@ +import sys, json, yaml + +print(json.dumps(yaml.safe_load(open(sys.argv[1]))))