Skip to content

Commit

Permalink
refactor(ci): consolidate test jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1026 committed Dec 2, 2024
1 parent 31491ff commit 8b19f83
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 54 deletions.
29 changes: 0 additions & 29 deletions .github/test-urbantree/action.yml

This file was deleted.

59 changes: 34 additions & 25 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,42 @@ env:

jobs:
changes:
name: 🔄 Detect image changes
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
images: ${{ steps.filter.outputs.changes }}
steps:
# https://github.com/actions/checkout/tree/11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
# https://github.com/dorny/paths-filter/tree/de90cc6fb38fc0963ad72b210f1f284cd68cea36
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
id: filter
with:
filters: .github/file-filters.yml

tests:
needs: changes
strategy:
fail-fast: true
matrix:
image: ${{ fromJSON(needs.changes.outputs.images) }}
include:
- image: urbantree
coverage-file: junit.xml
- image: api
coverage-file: api/junit.xml
uses: ./.github/workflows/tests.yml
with:
image: ${{ matrix.image }}
coverage-file: ${{ matrix.coverage-file }}
secrets: inherit

build:
name: 🏗️ Build and push Docker image
runs-on: ubuntu-latest
needs: tests
strategy:
fail-fast: false
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow#example-adding-configurations
Expand All @@ -37,11 +59,8 @@ jobs:
include:
- image: urbantree
context: .
coverage-file: ./coverage/web.xml
- image: api
context: ./api
coverage-file: ./coverage/api.xml
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
Expand Down Expand Up @@ -105,29 +124,19 @@ jobs:
}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}

# https://github.com/docker/build-push-action/tree/48aba3b46d1b1fec4febb7c5d0c644b249a11355
- name: 🧪 Test UrbanTree
uses: ./.github/test-urbantree/action.yml
if: ${{ matrix.image == 'urbantree' }}

- name: 🧪 Test API
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
if: ${{ matrix.image == 'api' }}
with:
context: ${{ matrix.context }}
target: test
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
# - name: 🧪 Test ${{ matrix.image }}
# uses: ${{ matrix.action }}

# https://github.com/codecov/test-results-action/tree/9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820
- name: 📊 Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820
with:
files: ${{ matrix.coverage-file }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# https://github.com/docker/build-push-action/tree/48aba3b46d1b1fec4febb7c5d0c644b249a11355
# - name: 🧪 Test ${{ matrix.image }}
# uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
# if: ${{ matrix.image == 'api' }}
# with:
# context: ${{ matrix.context }}
# target: test
# load: true
# cache-from: type=gha
# cache-to: type=gha,mode=max

# https://github.com/docker/build-push-action/tree/48aba3b46d1b1fec4febb7c5d0c644b249a11355
- name: 🏗️ Build final stage and push to ${{ env.REGISTRY }}
Expand Down
110 changes: 110 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: 🧪 Tests

on:
workflow_call:
inputs:
image:
required: true
type: string
coverage-file:
required: true
type: string

jobs:
urbantree:
name: 🧪 Test UrbanTree
runs-on: ubuntu-latest
if: ${{ github.event.inputs.image == 'urbantree' }}
steps:
# https://github.com/actions/checkout/tree/11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
# https://github.com/actions/cache/tree/6849a6489940f00c2f30c0fb92c6274307ccb58a
- name: 📦 Cache Composer dependencies
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

# https://github.com/shivammathur/setup-php/tree/c541c155eee45413f5b09a52248675b1a2575231
- name: 🐘 Setup PHP with extensions
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231
with:
php-version: 8.4
coverage: xdebug
extensions: none, ctype, curl, dom, json, libxml, mbstring, pdo, phar, tokenizer, xml, xmlwriter
ini-values: zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
tools: none

# https://github.com/php-actions/composer/tree/8a65f0d3c6a1d17ca4800491a40b5756a4c164f3
- name: 📦 Install Composer dependencies
uses: php-actions/composer@8a65f0d3c6a1d17ca4800491a40b5756a4c164f3

- name: 🧪 Run PHPUnit tests with coverage
shell: bash
run: ./vendor/bin/phpunit --log-junit junit.xml --coverage-clover=coverage.xml

# https://github.com/codecov/test-results-action/tree/9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820
- name: 📊 Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820
with:
files: ${{ github.event.inputs.coverage-file }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

# https://github.com/codecov/codecov-action/tree/015f24e6818733317a2da2edd6290ab26238649a
- name: Upload coverage to Codecov
uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a
with:
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

api:
name: 🧪 Test API
runs-on: ubuntu-latest
if: ${{ github.event.inputs.image == 'api' }}
steps:
# https://github.com/actions/checkout/tree/11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
# https://github.com/actions/cache/tree/6849a6489940f00c2f30c0fb92c6274307ccb58a
- name: 📦 Cache Python dependencies
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
with:
path: /root/.cache/pip
key: ${{ runner.os }}-${{ hashFiles('**/requirements-dev.txt') }}

# https://github.com/actions/setup-python/tree/0b93645e9fea7318ecaed2b359559ac225c90a2b
- name: 🐍 Setup Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
with:
python-version: "3.13.0"

- name: 📂 Change directory to API
shell: bash
run: cd api

- name: 📦 Install Python dependencies
shell: bash
run: pip install -r requirements-dev.txt

- name: 🧪 Run Python tests with coverage
shell: bash
run: pytest tests --cov=./src --cov-report=xml --junitxml=junit.xml

# https://github.com/codecov/test-results-action/tree/9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820
- name: 📊 Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820
with:
files: ${{ github.event.inputs.coverage-file }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

# https://github.com/codecov/codecov-action/tree/015f24e6818733317a2da2edd6290ab26238649a
- name: Upload coverage to Codecov
uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a
with:
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

0 comments on commit 8b19f83

Please sign in to comment.