From 181e8ce1c03e6435904de0f4cd6a4c47d0095ebd Mon Sep 17 00:00:00 2001 From: Jitendra Gundaniya Date: Thu, 11 Apr 2024 11:57:26 +0100 Subject: [PATCH] Reusable action for tests created and kept node version and package path as input --- .../install_node_dependencies/action.yml | 15 +++++- .github/actions/setup_tests/action.yml | 51 +++++++++++++++++++ .github/workflows/e2e-tests.yml | 37 ++------------ .../workflows/javascript-lint-and-tests.yml | 2 + .github/workflows/unit-tests.yml | 35 ++----------- 5 files changed, 75 insertions(+), 65 deletions(-) create mode 100644 .github/actions/setup_tests/action.yml diff --git a/.github/actions/install_node_dependencies/action.yml b/.github/actions/install_node_dependencies/action.yml index 2d37f4302d..ae9ce15c1d 100644 --- a/.github/actions/install_node_dependencies/action.yml +++ b/.github/actions/install_node_dependencies/action.yml @@ -1,12 +1,23 @@ name: Setup Node.js and Install Dependencies description: Sets up a specific Node.js version, caches Node modules, and installs Node dependencies. +inputs: + node-version: + description: 'Node.js version' + required: true + default: '16.13.2' + + package-path: + description: 'Path to package.json file' + required: false + default: '.' + runs: using: composite steps: - uses: actions/setup-node@v4.0.0 with: - node-version: 16.13.2 + node-version: ${{ inputs.node-version }} - id: npm-cache-dir run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT @@ -15,7 +26,7 @@ runs: - uses: actions/cache@v4 with: path: "${{ steps.npm-cache-dir.outputs.dir }}" - key: "${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}" + key: "${{ runner.os }}-node-${{ hashFiles(inputs.package-path + '/package-lock.json') }}" restore-keys: "${{ runner.os }}-node-" - run: npm ci diff --git a/.github/actions/setup_tests/action.yml b/.github/actions/setup_tests/action.yml new file mode 100644 index 0000000000..f41ec23ba5 --- /dev/null +++ b/.github/actions/setup_tests/action.yml @@ -0,0 +1,51 @@ +name: Setup Tests +description: Sets up the testing environment by checking out the code, setting up Python and Node.js, caching Python packages, installing Kedro and other Python dependencies, and building the React application. + +inputs: + os: + description: 'Operating system' + required: true + default: 'ubuntu-latest' + python-version: + description: 'Python version' + required: true + default: '3.9' + +runs: + using: "composite" + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python ${{inputs.python-version}} + uses: actions/setup-python@v5 + with: + python-version: ${{inputs.python-version}} + + - name: Cache python packages for Linux + if: inputs.os == 'ubuntu-latest' + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{inputs.os}}-python-${{inputs.python-version}} + + - name: Cache python packages for Windows + if: inputs.os == 'windows-latest' + uses: actions/cache@v4 + with: + path: ~\AppData\Local\pip\Cache + key: ${{inputs.os}}-python-${{inputs.python-version}} + + - name: Install Kedro and other Python Dependencies + uses: "./.github/actions/install_python_dependencies" + + - name: Setup Node.js and Install Dependencies + uses: "./.github/actions/install_node_dependencies" + with: + node-version: '16.13.2' + + - name: Build React application + run: |- + node -v + make build + shell: bash \ No newline at end of file diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 0cb344f68c..c964f09114 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -15,38 +15,11 @@ jobs: # Only run on main and demo branches for Windows if: inputs.os == 'ubuntu-latest' || ((github.ref == 'refs/heads/main' || github.ref == 'refs/heads/demo') && inputs.os == 'windows-latest') steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Python ${{inputs.python-version}} - uses: actions/setup-python@v5 - with: - python-version: ${{inputs.python-version}} - - - name: Cache python packages for Linux - if: inputs.os == 'ubuntu-latest' - uses: actions/cache@v4 + - name: Setup Tests + uses: ./.github/actions/setup-tests.yml with: - path: ~/.cache/pip - key: ${{inputs.os}}-python-${{inputs.python-version}} - - - name: Cache python packages for Windows - if: inputs.os == 'windows-latest' - uses: actions/cache@v4 - with: - path: ~\AppData\Local\pip\Cache - key: ${{inputs.os}}-python-${{inputs.python-version}} - - - name: Install Kedro and other Python Dependencies - uses: "./.github/actions/install_python_dependencies" - - - name: Setup Node.js and Install Dependencies - uses: "./.github/actions/install_node_dependencies" - - - name: Build React application - run: |- - node -v - make build + os: ${{ inputs.os }} + python-version: ${{ inputs.python-version }} - - name: Run Python tests + - name: Run all end to end tests run: make e2e-tests \ No newline at end of file diff --git a/.github/workflows/javascript-lint-and-tests.yml b/.github/workflows/javascript-lint-and-tests.yml index 94c80dc1e1..4f151f81d4 100644 --- a/.github/workflows/javascript-lint-and-tests.yml +++ b/.github/workflows/javascript-lint-and-tests.yml @@ -35,6 +35,8 @@ jobs: - name: Setup Node.js and Install Dependencies uses: "./.github/actions/install_node_dependencies" + with: + node-version: '16.13.2' - name: Setup Cypress requirements run: |- diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 96a7aadc1a..98dfd200c7 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -15,38 +15,11 @@ jobs: # Only run on main and demo branches for Windows if: inputs.os == 'ubuntu-latest' || ((github.ref == 'refs/heads/main' || github.ref == 'refs/heads/demo') && inputs.os == 'windows-latest') steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Python ${{inputs.python-version}} - uses: actions/setup-python@v5 - with: - python-version: ${{inputs.python-version}} - - - name: Cache python packages for Linux - if: inputs.os == 'ubuntu-latest' - uses: actions/cache@v4 + - name: Setup Tests + uses: ./.github/actions/setup-tests.yml with: - path: ~/.cache/pip - key: ${{inputs.os}}-python-${{inputs.python-version}} - - - name: Cache python packages for Windows - if: inputs.os == 'windows-latest' - uses: actions/cache@v4 - with: - path: ~\AppData\Local\pip\Cache - key: ${{inputs.os}}-python-${{inputs.python-version}} - - - name: Install Kedro and other Python Dependencies - uses: "./.github/actions/install_python_dependencies" - - - name: Setup Node.js and Install Dependencies - uses: "./.github/actions/install_node_dependencies" - - - name: Build React application - run: |- - node -v - make build + os: ${{ inputs.os }} + python-version: ${{ inputs.python-version }} - name: Run Python tests run: make pytest \ No newline at end of file