Skip to content

Commit

Permalink
refactor(workflows): DRY and speed up workflows
Browse files Browse the repository at this point in the history
Motivation
----------
Performance: We will run only *one* detect file changes job for each
subfolder.

Maintenance: Much less code.

Safetey: If anything under `./github/workflows` has changed, run all
jobs. It's dangerous to hard-code the workflow name in the file-filters
list.

How to test
-----------
1. Check the status checks for this PR
  • Loading branch information
roschaefer committed Jul 2, 2024
1 parent e90affd commit 71cccdc
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 269 deletions.
33 changes: 1 addition & 32 deletions .github/file-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,6 @@ presenter-test-build-storybook: &presenter-test-build-storybook
- '.github/file-filters.yml'
- 'presenter/**/*'

# frontend
frontend-test-lint-code: &frontend-test-lint-code
- 'frontend/**/*'

frontend-test-unit-code: &frontend-test-unit-code
- '.github/workflows/frontend.test.unit.code.yml'
- '.github/file-filters.yml'
- 'frontend/**/*'

frontend-test-build-code: &frontend-test-build-code
- '.github/workflows/frontend.test.build.code.yml'
- '.github/file-filters.yml'
- 'frontend/**/*'

frontend-test-build-docker: &frontend-test-build-docker
- '.github/workflows/frontend.test.build.docker.yml'
- '.github/file-filters.yml'
- 'frontend/**/*'

frontend-test-build-docs: &frontend-test-build-docs
- '.github/workflows/frontend.test.build.docs.yml'
- '.github/file-filters.yml'
- 'frontend/**/*.md'
- 'frontend/.vuepress/*'
- 'frontend/package.json'

frontend-test-build-storybook: &frontend-test-build-storybook
- '.github/workflows/frontend.test.build.storybook.yml'
- '.github/file-filters.yml'
- 'frontend/**/*'

# admin
admin-test-lint-code: &admin-test-lint-code
- 'admin/**/*'
Expand Down Expand Up @@ -131,4 +100,4 @@ e2e-docs:
- '.github/workflows/e2e.test.build.docs.yml'
- '.github/file-filter.yml'
- '.vuepress/*'
- 'package.json'
- 'package.json'
132 changes: 132 additions & 0 deletions .github/workflows/frontend..yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: "frontend:test:build test code"

on: [push,pull_request_target]

jobs:
# only (but most important) job from this workflow required for pull requests
# check results serve as run conditions for all other jobs here
files-changed:
name: Detect File Changes - frontend/
runs-on: ubuntu-latest
outputs:
frontend: ${{ steps.filter.outputs.frontend }}
frontend-docs: ${{ steps.filter.outputs.frontend-docs }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3.0.2
id: filter
with:
filters: |
frontend:
- '.github/workflows/**/*'
- 'frontend/**/*'
frontend-docs:
- '.github/workflows/**/*'
- 'frontend/**/*.md'
- 'frontend/.vuepress/*'
- 'frontend/package.json'
build:
if: needs.files-changed.outputs.frontend == 'true'
name: Build - Frontend
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./frontend
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Frontend | Build
run: npm install && npm run build
working-directory: ${{env.WORKING_DIRECTORY}}

build-docker-production:
if: needs.files-changed.outputs.frontend == 'true'
name: Build Docker Production - Frontend
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./frontend
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Frontend | Build Docker Production
run: docker compose -f docker-compose.yml build
working-directory: ${{env.WORKING_DIRECTORY}}

build-docker-development:
if: needs.files-changed.outputs.frontend == 'true'
name: Build Docker Development - Frontend
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./frontend
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Frontend | Build Docker Development
run: docker compose build
working-directory: ${{env.WORKING_DIRECTORY}}

build-docs:
if: needs.files-changed.outputs.frontend-docs == 'true'
name: Build Docs - Frontend
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./frontend
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Frontend | Build Docs
run: npm install && npm run docs:build
working-directory: ${{env.WORKING_DIRECTORY}}

storybook:
if: needs.files-changed.outputs.frontend == 'true'
name: Build Storybook - Frontend
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./frontend
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Frontend | Build Storybook
run: npm install && npm run storybook:build
working-directory: ${{env.WORKING_DIRECTORY}}

lint:
if: needs.files-changed.outputs.frontend == 'true'
name: Lint - Frontend
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./frontend
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Frontend | Lint
run: npm install && npm run test:lint
working-directory: ${{env.WORKING_DIRECTORY}}

unit:
if: needs.files-changed.outputs.frontend == 'true'
name: Unit - Frontend
needs: files-changed
runs-on: ubuntu-latest
env:
WORKING_DIRECTORY: ./frontend
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Frontend | Unit
run: npm install && npm run test:unit
working-directory: ${{env.WORKING_DIRECTORY}}
37 changes: 0 additions & 37 deletions .github/workflows/frontend.test.build.code.yml

This file was deleted.

52 changes: 0 additions & 52 deletions .github/workflows/frontend.test.build.docker.yml

This file was deleted.

37 changes: 0 additions & 37 deletions .github/workflows/frontend.test.build.docs.yml

This file was deleted.

37 changes: 0 additions & 37 deletions .github/workflows/frontend.test.build.storybook.yml

This file was deleted.

37 changes: 0 additions & 37 deletions .github/workflows/frontend.test.lint.code.yml

This file was deleted.

Loading

0 comments on commit 71cccdc

Please sign in to comment.