Skip to content

Commit

Permalink
ci: PLATE-745: Set up frontend test workflows (HumanSignal#5365)
Browse files Browse the repository at this point in the history
* ci: PLATE-745: Set up frontend test workflows

* headless tests

* uncomment pipeline

* ci: Build frontend

Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/7693774741

---------

Co-authored-by: robot-ci-heartex <[email protected]>
  • Loading branch information
nikitabelonogov and robot-ci-heartex authored Jan 29, 2024
1 parent 2e736d9 commit 522b241
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 31 deletions.
50 changes: 50 additions & 0 deletions .github/actions/setup-frontend-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Setup frontend environment
description: Setup frontend environment

inputs:
node-version:
description: node version
default: "18"
required: false
yarn-version:
description: yarn version
default: "1.22"
required: false
directory:
description: frontend directory
default: "web"
required: false

runs:
using: composite
steps:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "${{ inputs.node-version }}"

- name: Upgrade Yarn
env:
VERSION: "${{ inputs.yarn-version }}"
shell: bash
run: npm install -g "yarn@${VERSION}"

- name: Get yarn cache directory path
id: yarn-cache-dir-path
shell: bash
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- name: Configure yarn cache
uses: actions/cache@v4
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-node-${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }}

- name: Print Yarn cache size
shell: bash
run: du -d 0 -h ${{ steps.yarn-cache-dir-path.outputs.dir }}

- name: Install yarn dependencies
working-directory: "${{ inputs.directory }}"
shell: bash
run: yarn install --frozen-lockfile
38 changes: 37 additions & 1 deletion .github/workflows/cicd_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ jobs:
- 'label_studio/frontend/**'
- 'web/**'
- '.github/workflows/frontend-build.yml'
- '.github/workflows/tests-yarn-unit.yml'
- '.github/workflows/tests-yarn-integration.yml'
- '.github/workflows/tests-yarn-e2e.yml'
docker:
- 'label_studio/**'
- 'deploy/**'
Expand Down Expand Up @@ -408,6 +411,36 @@ jobs:
release-id: ${{ needs.draft-release.outputs.id }}
secrets: inherit

tests-yarn-unit:
name: "Tests"
needs:
- changed_files
if: needs.changed_files.outputs.frontend == 'true'
uses: ./.github/workflows/tests-yarn-unit.yml
with:
head_sha: ${{ github.event.pull_request.head.sha || github.event.after }}
secrets: inherit

tests-yarn-integration:
name: "Tests"
needs:
- changed_files
if: needs.changed_files.outputs.frontend == 'true' && github.ref_name == 'develop'
uses: ./.github/workflows/tests-yarn-integration.yml
with:
head_sha: ${{ github.event.pull_request.head.sha || github.event.after }}
secrets: inherit

tests-yarn-e2e:
name: "Tests"
needs:
- changed_files
if: needs.changed_files.outputs.frontend == 'true' && github.ref_name == 'develop'
uses: ./.github/workflows/tests-yarn-e2e.yml
with:
head_sha: ${{ github.event.pull_request.head.sha || github.event.after }}
secrets: inherit

check_gate:
name: "Ready to merge"
if: always()
Expand All @@ -419,11 +452,14 @@ jobs:
- pytest
- migrations
- build-docker
- tests-yarn-unit
- tests-yarn-integration
- tests-yarn-e2e
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
allowed-failures:
allowed-failures: tests-yarn-unit, tests-yarn-integration, tests-yarn-e2e
allowed-skips: gitleaks, bandit, ruff, blue, pytest, migrations, conda-test, build-docker
jobs: ${{ toJSON(needs) }}
31 changes: 7 additions & 24 deletions .github/workflows/frontend-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ on:
type: string

env:
NODE: 18
CACHE_NAME_PREFIX: v1
FRONTEND_MONOREPO_DIR: web
NODE: "18"
FRONTEND_MONOREPO_DIR: "web"
FRONTEND_BUILD_COMMIT_MESSAGE: "ci: Build frontend"

jobs:
Expand All @@ -40,31 +39,15 @@ jobs:
token: ${{ secrets.GIT_PAT }}
ref: ${{ inputs.ref }}

- uses: actions/setup-node@v4
- name: Setup frontend environment
uses: ./.github/actions/setup-frontend-environment
with:
node-version: "${{ env.NODE }}"

- name: Upgrade Yarn
run: npm install -g [email protected]

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- name: Configure yarn cache
uses: actions/cache@v4
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-node-${{ env.NODE }}-${{ hashFiles('**/yarn.lock') }}

- name: Print Yarn cache size
run: du -d 0 -h ${{ steps.yarn-cache-dir-path.outputs.dir }}
directory: "${{ env.FRONTEND_MONOREPO_DIR }}"

- name: "Monorepo: Build"
run: |
yarn install --frozen-lockfile
yarn build
working-directory: ${{ env.FRONTEND_MONOREPO_DIR }}
working-directory: "${{ env.FRONTEND_MONOREPO_DIR }}"
run: yarn build

- name: Commit and Push
run: |
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/test_migrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ on:
required: true
type: string

env:
NODE: '18'
CACHE_NAME_PREFIX: v1

jobs:
migrations:
name: "migrations"
Expand Down
81 changes: 81 additions & 0 deletions .github/workflows/tests-yarn-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: "yarn e2e"

on:
workflow_call:
inputs:
head_sha:
required: true
type: string

env:
NODE: "18"
FRONTEND_MONOREPO_DIR: "web"

jobs:
main:
name: "yarn e2e"
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: hmarr/[email protected]

- name: Configure git
shell: bash
run: |
set -xeuo pipefail
git config --global user.name 'robot-ci-heartex'
git config --global user.email '[email protected]'
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- name: Setup frontend environment
uses: ./.github/actions/setup-frontend-environment
with:
node-version: "${{ env.NODE }}"
directory: "${{ env.FRONTEND_MONOREPO_DIR }}"

- name: Install e2e dependencies
working-directory: ${{ env.FRONTEND_MONOREPO_DIR }}/libs/editor/tests/e2e
run: yarn install

- name: Run LSO server
id: run-lso-server
run: |
container_id=$(docker run --rm -d -p 8080:8080 heartexlabs/label-studio:develop)
echo "container_id=${container_id}" >> $GITHUB_OUTPUT
- name: Run LSF server
id: run-lsf-server
timeout-minutes: 1
working-directory: ${{ env.FRONTEND_MONOREPO_DIR }}
run: |
set -xeuo pipefail
yarn lsf:serve &
pid=$!
echo "pid=${pid}" >> $GITHUB_OUTPUT
while ! curl -s -o /dev/null -L "http://localhost:3000"; do
echo "=> Waiting for service to become available"
sleep 2s
done
- name: Run tests
working-directory: ${{ env.FRONTEND_MONOREPO_DIR }}
env:
HEADLESS: true
run: |
yarn test:e2e
- name: Kill LSO server
if: always()
continue-on-error: true
run: docker rm -f "${{ steps.run-lso-server.outputs.container_id }}"

- name: Kill LSF server
if: always()
continue-on-error: true
run: kill -9 "${{ steps.run-lsf-server.outputs.pid }}"
64 changes: 64 additions & 0 deletions .github/workflows/tests-yarn-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: "yarn integration"

on:
workflow_call:
inputs:
head_sha:
required: true
type: string

env:
NODE: "18"
FRONTEND_MONOREPO_DIR: "web"

jobs:
main:
name: "yarn integration"
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: hmarr/[email protected]

- name: Configure git
shell: bash
run: |
set -xeuo pipefail
git config --global user.name 'robot-ci-heartex'
git config --global user.email '[email protected]'
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- name: Setup frontend environment
uses: ./.github/actions/setup-frontend-environment
with:
node-version: "${{ env.NODE }}"
directory: "${{ env.FRONTEND_MONOREPO_DIR }}"

- name: Run server
id: run-server
timeout-minutes: 1
working-directory: ${{ env.FRONTEND_MONOREPO_DIR }}
run: |
set -xeuo pipefail
yarn lsf:serve &
pid=$!
echo "pid=${pid}" >> $GITHUB_OUTPUT
while ! curl -s -o /dev/null -L "http://localhost:3000"; do
echo "=> Waiting for service to become available"
sleep 2s
done
- name: Run tests
working-directory: ${{ env.FRONTEND_MONOREPO_DIR }}
run: |
yarn test:integration
- name: Kill server
if: always()
continue-on-error: true
run: kill -9 "${{ steps.run-server.outputs.pid }}"
43 changes: 43 additions & 0 deletions .github/workflows/tests-yarn-unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "yarn unit"

on:
workflow_call:
inputs:
head_sha:
required: true
type: string

env:
NODE: "18"
FRONTEND_MONOREPO_DIR: "web"

jobs:
main:
name: "yarn unit"
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: hmarr/[email protected]

- name: Configure git
shell: bash
run: |
set -xeuo pipefail
git config --global user.name 'robot-ci-heartex'
git config --global user.email '[email protected]'
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- name: Setup frontend environment
uses: ./.github/actions/setup-frontend-environment
with:
node-version: "${{ env.NODE }}"
directory: "${{ env.FRONTEND_MONOREPO_DIR }}"

- name: Run tests
working-directory: ${{ env.FRONTEND_MONOREPO_DIR }}
run: |
yarn test:unit
2 changes: 1 addition & 1 deletion web/dist/libs/editor/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/dist/libs/editor/main.js.map

Large diffs are not rendered by default.

0 comments on commit 522b241

Please sign in to comment.