Skip to content

Commit

Permalink
Merge branch 'main' into refactor/model-database
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1026 committed Dec 3, 2024
2 parents 15fda1e + 2100d4c commit 9f83afd
Show file tree
Hide file tree
Showing 73 changed files with 855 additions and 360 deletions.
9 changes: 8 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
APP_NAME=Urban Tree 5.0
DB_HOST=database

ENV=development

#* Database

DB_NAME=urbantree
DB_USER=root
DB_PASS=J0HMXAJ6XE
# If you are using docker-compose, you can ignore the following variables
DB_HOST=database
DB_PORT=3306
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.

12 changes: 2 additions & 10 deletions database/start-scripts/0-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ create table photos (
deleted_at timestamp
);

--* Roles, users, contracts and machines
create table roles (
id int auto_increment primary key,
name varchar(255) unique,
created_at timestamp default current_timestamp,
updated_at timestamp,
deleted_at timestamp
);
--* Users, contracts and machines

create table users (
id int auto_increment primary key,
Expand All @@ -25,12 +18,11 @@ create table users (
dni varchar(255) unique,
password varchar(255) not null,
email varchar(255) not null,
role_id int not null,
role int not null, -- 0: customer, 1: worker, 2: admin
photo_id int,
created_at timestamp default current_timestamp,
updated_at timestamp,
deleted_at timestamp,
foreign key (role_id) references roles(id),
foreign key (photo_id) references photos(id)
);

Expand Down
36 changes: 12 additions & 24 deletions database/start-scripts/1-seed.sql
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
--* Photos
INSERT INTO photos (name, path) VALUES
('Foto Usuario 1', '/uploads/users/photo1.jpg'),
('Foto Usuario 2', '/uploads/users/photo2.jpg'),
('Foto Máquina 1', '/uploads/machines/photo1.jpg');

--* Roles
INSERT INTO roles (name) VALUES
('Administrador'),
('Gerente'),
('Trabajador');

--* Users
INSERT INTO users (company, name, surname, dni, password, email, role_id, photo_id) VALUES
('Projar', 'Carlos', 'García', '12345678A', 'hashedpassword1', '[email protected]', 1, 1),
('Projar', 'Ana', 'Martínez', '23456789B', 'hashedpassword2', '[email protected]', 2, 2),
('Projar', 'José', 'Rodríguez', '34567890C', 'hashedpassword3', '[email protected]', 3, NULL);
INSERT INTO users (company, name, surname, dni, password, email, role) VALUES
('TechCorp', 'Carlos', 'García', '12345678A', 'hashedpassword1', '[email protected]', 1),
('InnovaTech', 'Ana', 'Martínez', '23456789B', 'hashedpassword2', '[email protected]', 1),
('DesignWorks', 'José', 'Rodríguez', '34567890C', 'hashedpassword3', '[email protected]', 2);

--* Contracts
INSERT INTO contracts (name, start_date, end_date, invoice_proposed, invoice_agreed, invoice_paid) VALUES
Expand All @@ -23,10 +11,10 @@ INSERT INTO contracts (name, start_date, end_date, invoice_proposed, invoice_agr
('Ayuntamiento de Carlet', '2021-01-01', '2021-12-31', 3000.00, 2700.00, 2700.00);

--* Machines
INSERT INTO machines (name, max_basket_size, photo_id) VALUES
('Cesta elevadora', 200.00, 3),
('Plataforma elevadora', 300.00, NULL),
('Tijera elevadora', 400.00, NULL);
INSERT INTO machines (name, max_basket_size) VALUES
('Cesta elevadora', 200.00),
('Plataforma elevadora', 300.00),
('Tijera elevadora', 400.00);

--* Element Types
INSERT INTO element_types (name, description) VALUES
Expand Down Expand Up @@ -65,10 +53,10 @@ INSERT INTO elements (element_type_id, contract_id, zone_id, point_id, tree_type
(3, 3, 3, 3, NULL);

--* Incidences
INSERT INTO incidences (element_id, name, description, photo_id) VALUES
(1, 'Rama caída', 'Rama caída en el suelo', NULL),
(2, 'Banco roto', 'Banco roto en el parque', NULL),
(3, 'Fuente sin agua', 'Fuente sin agua en el parque', NULL);
INSERT INTO incidences (element_id, name, description) VALUES
(1, 'Rama caída', 'Rama caída en el suelo'),
(2, 'Banco roto', 'Banco roto en el parque'),
(3, 'Fuente sin agua', 'Fuente sin agua en el parque');

--* Work Orders
INSERT INTO work_orders (contract_id) VALUES
Expand Down
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>
Loading

0 comments on commit 9f83afd

Please sign in to comment.