Skip to content

Commit

Permalink
Reusable action for tests created and kept node version and package p…
Browse files Browse the repository at this point in the history
…ath as input
  • Loading branch information
jitu5 committed Apr 11, 2024
1 parent 4a9ff80 commit 181e8ce
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 65 deletions.
15 changes: 13 additions & 2 deletions .github/actions/install_node_dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
node-version: 16.13.2
node-version: ${{ inputs.node-version }}

- id: npm-cache-dir
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
Expand All @@ -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
Expand Down
51 changes: 51 additions & 0 deletions .github/actions/setup_tests/action.yml
Original file line number Diff line number Diff line change
@@ -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
37 changes: 5 additions & 32 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions .github/workflows/javascript-lint-and-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
Expand Down
35 changes: 4 additions & 31 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 181e8ce

Please sign in to comment.