Skip to content

Commit

Permalink
CI: Optimize CI workflow to run tests and linting only on relevant fi…
Browse files Browse the repository at this point in the history
…le changes (#1149)

* ci: Optimize CI workflow to run tests and linting only on relevant file changes

* refactor: Only run storybook workflow on relevant changes

* temp: Update frontend file to trigger test

* temp: Remove workflow paths condition

* refactor: Split CI workflow for frontend and backend test & linting

* chore: Update CI workflows to include pull requests for backend and frontend

* chore: Remove backend path condition from CI workflow

* chore: Remove change from frontend & add one to backend to test trigger backend test & lint workflow

* refactor: Remove trigger backend test & lint jobs from base settings

* ci: Start storybook workflow only when specific files have changes in a push or PR

* chore: Remove trailing whitespace in App.tsx file

* chore: Remove trailing whitespace in App.tsx file

* chore: Update CI workflows to include .yarn folder in paths for frontend and pull requests

* chore: Update CI workflows to include changes in their own workflow file, .env-github-actions and docker-compose.yaml as conditions to run
  • Loading branch information
drikusroor authored Jul 1, 2024
1 parent 4ab1db5 commit 8786e75
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 52 deletions.
64 changes: 12 additions & 52 deletions .github/workflows/ci.yml → .github/workflows/ci-backend.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
name: Test suite
name: Backend Test & Lint

on:
push:
paths:
- 'backend/**'
- '.github/workflows/ci-backend.yml'
- 'docker-compose.yaml'
- '.env-github-actions'
pull_request:
paths:
- 'backend/**'
- '.github/workflows/ci-backend.yml'
- 'docker-compose.yaml'
- '.env-github-actions'

jobs:

Expand Down Expand Up @@ -56,54 +67,3 @@ jobs:
- name: Lint Backend
continue-on-error: false
run: sudo docker-compose --env-file .env-github-actions run server bash -c "flake8"

frontend-test:
name: Test Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Frontend Tests
run: sudo docker-compose --env-file .env-github-actions run client yarn test:ci

frontend-coverage-badge:
name: Generate Frontend Coverage Badge
needs: frontend-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
steps:
- uses: actions/checkout@v3
- name: Generate Frontend Coverage Report (XML) and Badge
run: |
sudo docker-compose --env-file .env-github-actions run client yarn test:ci
sudo docker-compose --env-file .env-github-actions run client yarn coverage-badges -s public/coverage/coverage-summary.json -o public/coverage/coverage-frontend-badge-new.svg --label 'Frontend Code Coverage'
- name: Push Frontend Coverage Badge to separate branch
continue-on-error: true
run: |
if git ls-remote --heads origin code-coverage-badges; then
git fetch origin code-coverage-badges
git checkout code-coverage-badges
else
git checkout -b code-coverage-badges
git push origin code-coverage-badges
fi
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
rm frontend/coverage-frontend-badge.svg -f
sudo mv frontend/public/coverage/coverage-frontend-badge-new.svg frontend/coverage-frontend-badge.svg
git add frontend/coverage-frontend-badge.svg
git commit -m "Add frontend coverage badge for commit $GITHUB_SHA"
git push origin code-coverage-badges
# Check if there are any changes
if git diff --staged --quiet; then
echo "No changes in coverage badge. Skipping commit and push."
else
git commit -m "Add frontend coverage badge for commit $GITHUB_SHA"
git push origin code-coverage-badges
fi
frontend-lint:
name: Lint Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: sudo docker-compose --env-file .env-github-actions run client yarn lint
68 changes: 68 additions & 0 deletions .github/workflows/ci-frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Frontend Test & Lint

on:
push:
paths:
- 'frontend/**'
- '.yarn'
- '.github/workflows/ci-frontend.yml'
- 'docker-compose.yaml'
pull_request:
paths:
- 'frontend/**'
- '.yarn'
- '.github/workflows/ci-frontend.yml'
- 'docker-compose.yaml'

jobs:

frontend-test:
name: Test Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Frontend Tests
run: sudo docker-compose --env-file .env-github-actions run client yarn test:ci

frontend-coverage-badge:
name: Generate Frontend Coverage Badge
needs: frontend-test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
steps:
- uses: actions/checkout@v3
- name: Generate Frontend Coverage Report (XML) and Badge
run: |
sudo docker-compose --env-file .env-github-actions run client yarn test:ci
sudo docker-compose --env-file .env-github-actions run client yarn coverage-badges -s public/coverage/coverage-summary.json -o public/coverage/coverage-frontend-badge-new.svg --label 'Frontend Code Coverage'
- name: Push Frontend Coverage Badge to separate branch
continue-on-error: true
run: |
if git ls-remote --heads origin code-coverage-badges; then
git fetch origin code-coverage-badges
git checkout code-coverage-badges
else
git checkout -b code-coverage-badges
git push origin code-coverage-badges
fi
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
rm frontend/coverage-frontend-badge.svg -f
sudo mv frontend/public/coverage/coverage-frontend-badge-new.svg frontend/coverage-frontend-badge.svg
git add frontend/coverage-frontend-badge.svg
git commit -m "Add frontend coverage badge for commit $GITHUB_SHA"
git push origin code-coverage-badges
# Check if there are any changes
if git diff --staged --quiet; then
echo "No changes in coverage badge. Skipping commit and push."
else
git commit -m "Add frontend coverage badge for commit $GITHUB_SHA"
git push origin code-coverage-badges
fi
frontend-lint:
name: Lint Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: sudo docker-compose --env-file .env-github-actions run client yarn lint
10 changes: 10 additions & 0 deletions .github/workflows/storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ on:
branches:
- main
- develop
paths:
- 'frontend/**'
- '.github/workflows/storybook.yml'
- '.yarn/**'
- '.storybook/**'
pull_request:
paths:
- 'frontend/**'
- '.github/workflows/storybook.yml'
- '.yarn/**'
- '.storybook/**'

permissions:
contents: read
Expand Down

0 comments on commit 8786e75

Please sign in to comment.