Skip to content

Commit

Permalink
refactor: extract jobs from main build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
wolverian committed Nov 19, 2024
1 parent 0e94550 commit 1bf7e92
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 68 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/_build_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build Image

on:
workflow_call:
inputs:
github_ref_name:
type: string
github_sha:
type: string
secrets:
GITHUB_TOKEN:
required: true

jobs:
build_image:
name: Build image
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Install tools
uses: jdx/mise-action@v2
with:
experimental: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to utility account
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: eu-west-1
role-to-assume: arn:aws:iam::961341524988:role/kitu-github-actions-role
- uses: aws-actions/amazon-ecr-login@v2
id: login-ecr
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v6
with:
push: ${{ inputs.github_ref_name == 'main' }}
tags: ${{ steps.login-ecr.outputs.registry }}/kitu:${{ inputs.github_sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
39 changes: 39 additions & 0 deletions .github/workflows/_frontend_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Frontend Tests

on:
workflow_call:
secrets:
GITHUB_TOKEN:
required: true

jobs:
frontend_tests:
name: Frontend tests
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install tools
uses: jdx/mise-action@v2
with:
experimental: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Start DB
run: docker compose up -d db
working-directory: server
- name: Install dependencies
run: npm ci
working-directory: e2e
- name: Install Playwright Browsers
run: npx playwright install --with-deps
working-directory: e2e
- name: Run Playwright tests
run: npx playwright test
working-directory: e2e
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: e2e/playwright-report/
retention-days: 30
25 changes: 25 additions & 0 deletions .github/workflows/_server_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Server Tests

on:
workflow_call:
secrets:
GITHUB_TOKEN:
required: true

jobs:
server_tests:
name: Server tests
runs-on: ubuntu-latest
env:
MISE_ENV: ci
steps:
- uses: actions/checkout@v4
- name: Install tools
uses: jdx/mise-action@v2
with:
experimental: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build with Maven
run: mvn -B package --file pom.xml
working-directory: server
78 changes: 10 additions & 68 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,53 +86,17 @@ jobs:

server_tests:
name: Server tests
runs-on: ubuntu-latest
needs: update_tools_cache
env:
MISE_ENV: ci
steps:
- uses: actions/checkout@v4
- name: Install tools
uses: jdx/mise-action@v2
with:
experimental: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build with Maven
run: mvn -B package --file pom.xml
working-directory: server
uses: ./.github/workflows/_server_tests.yml
secrets:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

frontend_tests:
name: Frontend tests
timeout-minutes: 60
runs-on: ubuntu-latest
uses: ./.github/workflows/_frontend_tests.yml
needs: update_tools_cache
steps:
- uses: actions/checkout@v4
- name: Install tools
uses: jdx/mise-action@v2
with:
experimental: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Start DB
run: docker compose up -d db
working-directory: server
- name: Install dependencies
run: npm ci
working-directory: e2e
- name: Install Playwright Browsers
run: npx playwright install --with-deps
working-directory: e2e
- name: Run Playwright tests
run: npx playwright test
working-directory: e2e
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: e2e/playwright-report/
retention-days: 30
secrets:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

lint:
name: Check code formatting
Expand All @@ -151,37 +115,15 @@ jobs:

build_image:
name: Build image
runs-on: ubuntu-latest
uses: ./.github/workflows/_build_image.yml
needs:
- check_generated_sources
- server_tests
- frontend_tests
- lint
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Install tools
uses: jdx/mise-action@v2
with:
experimental: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to utility account
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: eu-west-1
role-to-assume: arn:aws:iam::961341524988:role/kitu-github-actions-role
- uses: aws-actions/amazon-ecr-login@v2
id: login-ecr
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v6
with:
push: ${{ github.ref_name == 'main' }}
tags: ${{ steps.login-ecr.outputs.registry }}/kitu:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
with:
github_ref_name: ${{ github.ref_name }}
github_sha: ${{ github.sha }}

deploy_util:
name: Util
Expand Down

0 comments on commit 1bf7e92

Please sign in to comment.