Skip to content

Commit

Permalink
Add some GNUMake automations
Browse files Browse the repository at this point in the history
  • Loading branch information
rafael-santiago committed Aug 29, 2024
1 parent b32c106 commit 8cafe1b
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 0 deletions.
57 changes: 57 additions & 0 deletions doc/BUILD-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ is intended to development folks.
- [`How I can build the Eutherpe binary?`](#how-i-can-build-the-eutherpe-binary)
- [`How I run the tests?`](#how-i-run-the-tests)
- [`I have installed go in Raspberry Pi but I cannot run it`](#i-have-installed-go-in-raspberry-pi-but-i-cannot-run-it)
- [`Using the GNUMake rules`](#using-the-gnumake-rules)

### How I can build the Eutherpe binary?

Expand Down Expand Up @@ -60,3 +61,59 @@ following command:
```
[`Back`](#topics)
### Using the GNUMake rules
It is a kind of uncommon a `software` written in `Golang` have automations based on `make`, but
`Eutherpe` it is about much more than just compiling, testing and installing. There are a bunch
of operations executed between the compilation and installation. Taking it into consideration,
I made up my mind to automate certain common operations that developers need to do.
This operations following automated in `src/Makefile`.
Until now there are four implemented `rules`:
- `eutherpe`
- `tests`
- `bootstrap`
- `update`
If you want to build the `eutherpe` application, being into the toplevel `src` directory, execute:
```
$ make eutherpe
```
This `rule` is capable of setting up your `GOENV` on its own.
Do you want to run the tests (ignoring the cached stuff), from the toplevel `src` directory, execute:
```
$ make tests
```
Does the development environment is clean, without a previous `Eutherpe` installation? You can
run `bootstrap` in order to install and configure everything. It is necessary to be `root` when
running this `rule`, being into the toplevel `src` directory, execute:
```
# make bootstrap
```
Have you done an adjustment in the application and you are wanting to update the `binary`
used by the `service` that is currently running in your development environment? Being `root` and
from the toplevel `src` directory, execute `update`:
```
# make update
```
> [!IMPORTANT]
> This update only refreshes the `Eutherpe` application and its `web assets` that compounds the
> `Eutherpe`'s `core`. If you have done changes in `services` or in `shell scripts` it is more
> indicated running `bootstrap`. Doing it, the `bootstrap` rule will detect that already exists
> a previous installation and it will not reinstall `bluealsa` nor recreate the `eutherpe` user
> and reboot the system neither. Even so, it will refresh the `services` and the `shell scripts`,
> too.
[`Back`](#topics)
55 changes: 55 additions & 0 deletions doc/BUILD-PT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ documento é mais voltado para o pessoal do desenvolvimento.
- [`Como construo o binário Eutherpe?`](#como-construo-o-binário-eutherpe)
- [`Como executo os testes?`](#como-executo-os-testes)
- [`Instalei go no Raspberry Pi mas não consigo rodá-lo`](#instalei-go-no-raspberry-pi-mas-não-consigo-rodá-lo)
- [`Utilizando as rules GNUMake`](#utilizando-as-rules-gnumake)

### Como construo o binário Eutherpe?

Expand Down Expand Up @@ -59,3 +60,57 @@ Se você fez o processo de [`bootstrapping`](MANUAL-PT.md#bootstrapping), tente
```
[`Voltar`](#tópicos)
### Utilizando as rules GNUMake
É pouco usual um `software` escrito em `Golang` dispor de automações via `make`, porém `Eutherpe`
vai muito além de compilar, testar e instalar. Existe muitas outras operações que se desenrolam
entre compilar e instalar. Levando isso em consideração, resolvi automatizar algumas operações
comuns dos desenvolvedores precisarem fazer.
Essas operações seguem automatizadas em `src/Makefile`.
Até o momento existem quatro `rules` implementadas:
- `eutherpe`
- `tests`
- `bootstrap`
- `update`
Se você quiser gerar o aplicativo `eutherpe`, estando no diretório `src`, rode:
```
$ make eutherpe
```
Essa `rule` é capaz de setar seu `GOENV` por conta própria.
Quer rodar os testes (ignorando os caches), a partir do diretório `src`, rode:
```
$ make tests
```
O ambiente de desenvolvimento está limpo, sem uma instalação de `Eutherpe`? Você pode rodar `bootstrap`
para instalar e configurar tudo. Para rodar essa `rule` é necessário ser `root`, estando em `src`, rode:
```
# make bootstrap
```
Você fez um ajuste no aplicativo e quer atualizar o `binário` utilizado pelo serviço que
está rodando em seu ambiente de desenvolvimento? Sendo `root` e estando no diretório `src`, rode
`update`:
```
# make update
```
> [!IMPORTANT]
> Esse update apenas atualiza a aplicação `Eutherpe` e nos seus `web assets` que
> compõem o `core` de `Eutherpe`. Caso você tenha feito alterações nos `serviços` ou nos `shell scripts`
> é mais indicado rodar `bootstrap`. Nesse caso, ele vai detectar que já existe uma instalação prévia
> e não vai reinstalar o `bluealsa`, não vai recriar o usuário `eutherpe` e nem `rebootar` o sistema.
> Porém vai atualizar também os `serviços` e os `shell scripts`.
[`Voltar`](#tópicos)
48 changes: 48 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# Copyright (c) 2024, Rafael Santiago
# All rights reserved.
#
# This source code is licensed under the GPLv2 license found in the
# COPYING.GPLv2 file in the root directory of Eutherpe's source tree.
#

define do_update
@if [ "$(USER)" != "root" ]; then\
echo error: You are not root.;\
exit 1;\
fi
@if [ ! -d /etc/eutherpe ]; then\
echo error: You have not ran bootstrap yet.;\
exit 1;\
fi
@if [ "$$(systemctl status eutherpe | grep 'active (' | wc -l)" = "1" ]; then\
systemctl stop eutherpe;\
while [ "$$(systemctl status eutherpe | grep 'inactive (' | wc -l)" != "1" ]; do\
sleep 1s;\
done;\
fi
@cp eutherpe $$(which eutherpe) && \
cp -rf web/ /etc/eutherpe/web/ && \
systemctl start eutherpe && \
echo info: Your Eutherpe\'s core was updated.
endef

eutherpe:
@ if [ -f /etc/profile.d/goenv.sh ] ; then\
. /etc/profile.d/goenv.sh ;\
go build ;\
else \
go build ;\
fi

tests:
@go clean -testcache
@go test internal/... -v

bootstrap:
@$(shell cd .. && ./bootstrap.sh)

update: eutherpe
@$(call do_update)

.PHONY: bootstrap eutherpe tests update

0 comments on commit 8cafe1b

Please sign in to comment.