diff --git a/.github/test-urbantree/action.yml b/.github/test-urbantree/action.yml deleted file mode 100644 index 816e3055..00000000 --- a/.github/test-urbantree/action.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: ๐Ÿงช Test UrbanTree -description: Run PHPUnit tests with code coverage -runs: - using: composite - steps: - # 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 diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index c8460cbd..145222d9 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -15,20 +15,33 @@ 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: + name: ๐Ÿงช Tests + needs: changes + uses: ./.github/workflows/tests.yml + with: + images: ${{ needs.changes.outputs.images }} + 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 @@ -37,11 +50,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 @@ -105,29 +115,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 ${{ matrix.image }} + # uses: ${{ matrix.action }} - - 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 - - # 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 }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..7611bfd3 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,99 @@ +name: ๐Ÿงช Tests + +on: + workflow_call: + inputs: + images: + required: true + type: string + +jobs: + urbantree: + name: ๐Ÿงช Test UrbanTree + runs-on: ubuntu-latest + if: ${{ contains(fromJSON(inputs.images), '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 + 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: ${{ contains(fromJSON(inputs.images), '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: ๐Ÿ“ฆ Install Python dependencies + shell: bash + run: pip install -r api/requirements-dev.txt + + - name: ๐Ÿงช Run Python tests with coverage + shell: bash + run: pytest api/tests --cov=./api/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 + 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 }}