Skip to content

Commit

Permalink
dev: Improve the Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
marienfressinaud committed Dec 8, 2024
1 parent 1fc4746 commit 82f389f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
run: composer install

- name: Setup the application
run: make setup
run: make db-setup
env:
DB_PORT: ${{ job.services.postgres.ports[5432] }}

Expand Down
97 changes: 60 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,87 +16,110 @@ else
CLI = ./docker/bin/cli
endif

ifndef COVERAGE
COVERAGE = --coverage-html ./coverage
endif

ifdef FILTER
PHPUNIT_FILTER = --filter=$(FILTER)
else
PHPUNIT_FILTER =
endif

ifdef FILE
PHPUNIT_FILE = $(FILE)
else
PHPUNIT_FILE = ./tests
endif

.PHONY: docker-start
docker-start: .env ## Start a development server with Docker
@echo "Running webserver on http://localhost:8000"
docker-start: PORT ?= 8000
docker-start: .env ## Start a development server (can take a PORT argument)
@echo "Running webserver on http://localhost:$(PORT)"
$(DOCKER_COMPOSE) up

.PHONY: docker-clean
docker-clean: ## Stop and clean Docker server
$(DOCKER_COMPOSE) down

.PHONY: docker-build
docker-build: ## Rebuild the Docker images
$(DOCKER_COMPOSE) build
$(DOCKER_COMPOSE) build --pull

.PHONY: docker-pull
docker-pull: ## Pull the Docker images from the Docker Hub
$(DOCKER_COMPOSE) pull --ignore-buildable

.PHONY: docker-clean
docker-clean: ## Clean the Docker stuff
$(DOCKER_COMPOSE) down -v

.PHONY: install
install: ## Install the dependencies
install: INSTALLER ?= all
install: ## Install the dependencies (can take an INSTALLER argument)
ifeq ($(INSTALLER), $(filter $(INSTALLER), all composer))
$(COMPOSER) install
endif
ifeq ($(INSTALLER), $(filter $(INSTALLER), all npm))
$(NPM) install
endif

.PHONY: setup
setup: .env ## Setup the application system
.PHONY: db-setup
db-setup: .env ## Setup and migrate the application system
$(CLI) migrations setup --seed

.PHONY: rollback
rollback: ## Reverse the last migration
.PHONY: db-rollback
db-rollback: ## Reverse the last migration (can take a STEPS argument)
ifdef STEPS
$(CLI) migrations rollback --steps=$(STEPS)
else
$(CLI) migrations rollback
endif

.PHONY: reset
reset: ## Reset the database
.PHONY: db-reset
db-reset: ## Reset the database (take a FORCE argument)
ifndef FORCE
$(error Please run the operation with FORCE=true)
endif
ifndef NO_DOCKER
$(DOCKER_COMPOSE) stop job_worker
endif
$(CLI) migrations reset --force --seed
ifndef NO_DOCKER
$(DOCKER_COMPOSE) start job_worker
endif

.PHONY: icons-build
icons-build: ## Build the icons asset
.PHONY: icons
icons: ## Build the icons asset
$(NPM) run build:icons

.PHONY: test
test: ## Run the test suite
test: FILE ?= ./tests
ifdef FILTER
test: override FILTER := --filter=$(FILTER)
endif
test: COVERAGE ?= --coverage-html ./coverage
test: ## Run the test suite (can take FILE, FILTER and COVERAGE arguments)
$(PHP) ./vendor/bin/phpunit \
-c .phpunit.xml \
$(COVERAGE) \
$(PHPUNIT_FILTER) \
$(PHPUNIT_FILE)
$(FILTER) \
$(FILE)

.PHONY: lint
lint: ## Run the linters on the PHP and JS files
lint: LINTER ?= all
lint: ## Execute the linters (can take a LINTER argument)
ifeq ($(LINTER), $(filter $(LINTER), all phpstan))
$(PHP) vendor/bin/phpstan analyse --memory-limit 1G -c .phpstan.neon
endif
ifeq ($(LINTER), $(filter $(LINTER), all rector))
$(PHP) vendor/bin/rector process --dry-run --config .rector.php
endif
ifeq ($(LINTER), $(filter $(LINTER), all phpcs))
$(PHP) vendor/bin/phpcs
endif
ifeq ($(LINTER), $(filter $(LINTER), all js))
$(NPM) run lint-js
endif
ifeq ($(LINTER), $(filter $(LINTER), all css))
$(NPM) run lint-css
endif

.PHONY: lint-fix
lint-fix: ## Fix the errors detected by the linters
lint-fix: LINTER ?= all
lint-fix: ## Fix the errors detected by the linters (can take a LINTER argument)
ifeq ($(LINTER), $(filter $(LINTER), all rector))
$(PHP) vendor/bin/rector process --config .rector.php
endif
ifeq ($(LINTER), $(filter $(LINTER), all phpcs))
$(PHP) vendor/bin/phpcbf
endif
ifeq ($(LINTER), $(filter $(LINTER), all js))
$(NPM) run lint-js-fix
endif
ifeq ($(LINTER), $(filter $(LINTER), all css))
$(NPM) run lint-css-fix
endif

.PHONY: release
release: ## Release a new version (take a VERSION argument)
Expand Down
2 changes: 1 addition & 1 deletion docker/development/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ services:
image: nginx:alpine
restart: unless-stopped
ports:
- "8000:8000"
- "${PORT:-8000}:8000"
- "8001:8001"
volumes:
- ../..:/var/www/html:z
Expand Down
11 changes: 9 additions & 2 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,21 @@ Once this is done, you should start the services:
$ make docker-start
```

> [!TIP]
> You can change the port of the application by passing the `PORT` parameter:
>
> ```console
> $ make docker-start PORT=9000
> ```
This command calls `docker compose` with the file under the `docker/development` folder.
The first time you call it, it will download the Docker images and build the
`php` one with the information from the `docker/development/Dockerfile.php` file.
The last step is to setup the environment with:
```console
$ make setup
$ make db-setup
```
It will copy the `env.sample` file to `.env` and call the Flus CLI to
Expand Down Expand Up @@ -101,7 +108,7 @@ You should now install the dependencies and setup the database with:
```console
$ export NO_DOCKER=true # tell the `make` commands to use native commands
$ make install
$ make setup
$ make db-setup
```

You’re all good now, just start a PHP development server:
Expand Down
2 changes: 0 additions & 2 deletions docs/production.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ You must now load the SQL schema to your database. You can do it with:

```console
flus# sudo -u www-data php cli migrations setup --seed
flus# # OR via make
flus# sudo -u www-data make setup NO_DOCKER=true
```

If the permissions are correct, you should have a message to tell you the
Expand Down
9 changes: 6 additions & 3 deletions docs/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ flus# chown -R www-data:www-data .
Then, apply the migrations and load seeds with:

```console
flus$ sudo -u www-data make setup NO_DOCKER=true
flus$ # In production
flus# sudo -u www-data php cli migrations setup --seed
flus$ # In development
flus$ make db-setup
```

Finally, you might need to restart PHP and the job worker so it detects
Expand All @@ -59,7 +62,7 @@ If at any time something goes wrong and you need to reset the application to
its previous state, you should start by reverse the migrations with:

```console
flus$ sudo -u www-data make rollback STEP=1 NO_DOCKER=true
flus$ sudo -u www-data php cli migrations rollback --steps=1
```

You can increase `STEP` to rollback more migrations (its default value is `1`
Expand All @@ -72,7 +75,7 @@ flus$ git checkout PREVIOUS_TAG
If something goes really wrong with the database, you can use the joker command:

```console
flus$ sudo -u www-data make reset FORCE=true
flus$ make db-reset FORCE=true
```

It will reset the database and reload the schema. **Note this command doesn't
Expand Down

0 comments on commit 82f389f

Please sign in to comment.