Skip to content

Commit

Permalink
ci: rename Docker workflow to main.yml and add testing job
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1026 committed Dec 2, 2024
1 parent df1616d commit f43896f
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 32 deletions.
60 changes: 34 additions & 26 deletions .github/workflows/docker.yml → .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@
# separate terms of service, privacy policy, and support
# documentation.

name: 🐳 Docker CI/CD
name: 🌳 CI/CD
on:
push:
branches: ["main"]
tags: ["v*.*.*"]
tags: ["v*"]
pull_request:
branches: ["main"]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
tests:
name: 🧪 Tests
uses: ./.github/workflows/tests.yml
secrets: inherit

build:
name: 🏗️ Build and push Docker image
name: 🐳 Docker
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
matrix:
image: [urbantree]
include:
- image: urbantree
context: .
permissions:
contents: read
packages: write
Expand All @@ -28,18 +40,19 @@ jobs:
id-token: write

steps:
# https://github.com/actions/checkout/tree/11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683

# https://github.com/sigstore/cosign-installer
# https://github.com/sigstore/cosign-installer/tree/dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da
- uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da
if: github.event_name != 'pull_request'
with:
cosign-release: "v2.2.4"

# https://github.com/docker/setup-buildx-action
# https://github.com/docker/setup-buildx-action/tree/c47758b77c9736f4b2ef4073d4d51994fabfe349
- uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349

# https://github.com/docker/login-action
# https://github.com/docker/login-action/tree/7ca345011ac4304463197fac0e56eab1bc7e6af0
- name: 🪪 Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@7ca345011ac4304463197fac0e56eab1bc7e6af0
if: github.event_name != 'pull_request'
Expand All @@ -48,11 +61,11 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# https://github.com/docker/metadata-action
# https://github.com/docker/metadata-action/tree/b53be03109c4ef6f6cc7aa545b84b17a7fe51c1e
- uses: docker/metadata-action@b53be03109c4ef6f6cc7aa545b84b17a7fe51c1e
id: meta
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.image }}
tags: |
type=ref,event=branch
type=ref,event=pr
Expand All @@ -61,37 +74,30 @@ jobs:
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,manifest-descriptor,index,index-descriptor

# https://github.com/actions/cache/tree/6849a6489940f00c2f30c0fb92c6274307ccb58a
- name: 📦 Cache Docker layers
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
with:
path: tmp-cache
path: |
composer-cache
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}

# https://github.com/reproducible-containers/buildkit-cache-dance/tree/5b6db76d1da5c8b307d5d2e0706d266521b710de
- name: 📦 Load cache
uses: reproducible-containers/buildkit-cache-dance@5b6db76d1da5c8b307d5d2e0706d266521b710de
with:
cache-map: |
{
"tmp-cache": "/tmp/cache"
"composer-cache": "/tmp/cache"
}
skip-extraction: ${{ steps.cache.outputs.cache-hit }}

# https://github.com/docker/build-push-action
- name: 🧪 Tests
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
with:
context: .
target: test
load: true
cache-from: type=gha
cache-to: type=gha,mode=max

# https://github.com/docker/build-push-action
# https://github.com/docker/build-push-action/tree/48aba3b46d1b1fec4febb7c5d0c644b249a11355
- name: 🏗️ Build final stage and push to ${{ env.REGISTRY }}
id: build-and-push
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355
with:
context: .
context: ${{ matrix.context }}
push: ${{ github.event_name != 'pull_request' }}
target: final
tags: ${{ steps.meta.outputs.tags }}
Expand All @@ -115,11 +121,12 @@ jobs:
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

# https://github.com/actions/attest-build-provenance/tree/ef244123eb79f2f7a7e75d99086184180e6d0018
- name: 📝 Attest the build provenance
uses: actions/attest-build-provenance@v1
uses: actions/attest-build-provenance@ef244123eb79f2f7a7e75d99086184180e6d0018
if: ${{ github.event_name != 'pull_request' }}
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-name: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.image }}
subject-digest: ${{ steps.build-and-push.outputs.digest }}
push-to-registry: true

Expand All @@ -130,6 +137,7 @@ jobs:
if: ${{ github.event_name != 'pull_request' }}

steps:
# https://github.com/appleboy/ssh-action/tree/7eaf76671a0d7eec5d98ee897acda4f968735a17
- name: 🚚 SSH into production server
uses: appleboy/ssh-action@7eaf76671a0d7eec5d98ee897acda4f968735a17
with:
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: 🧪 Tests

on:
workflow_call:

jobs:
urbantree:
name: 🧪 UrbanTree
runs-on: ubuntu-latest
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 }}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require-dev": {
"phpunit/phpunit": "^11.4"
"phpunit/phpunit": "11.4.4"
},
"require": {
"php": "^8.2"
Expand Down
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
shortenArraysForExportThreshold="10"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
displayDetailsOnPhpunitDeprecations="true"
failOnPhpunitDeprecation="true"
failOnRisky="true"
failOnWarning="true"
colors="true"
>
<testsuites>
Expand All @@ -12,13 +22,15 @@
<directory>tests/Feature</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory>app</directory>
<directory>src</directory>
</include>
</source>

<php>
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
</php>
</phpunit>
</phpunit>

0 comments on commit f43896f

Please sign in to comment.