2020-09-03 15:13:19 +00:00
---
date: "2019-02-12:00:00+02:00"
title: "Magefile"
draft: false
type: "doc"
menu:
sidebar:
parent: "development"
---
# Mage
Vikunja uses [Mage ](https://magefile.org/ ) to script common development tasks and even releasing.
2022-01-23 12:59:43 +00:00
Mage is a pure go solution which allows for greater flexibility and things like better parallelization.
2020-09-03 15:13:19 +00:00
2022-01-23 12:59:43 +00:00
This document explains what tasks are available and what they do.
2020-09-03 15:13:19 +00:00
2020-09-03 15:34:44 +00:00
{{< table_of_contents > }}
2020-09-03 15:13:19 +00:00
## Installation
To use mage, you'll need to install the mage cli.
To install it, run the following command:
```
go install github.com/magefile/mage
```
## Categories
There are multiple categories of subcommands in the magefile:
* `build` : Contains commands to build a single binary
2023-04-03 09:47:37 +00:00
* `check` : Contains commands to statically check the source code
2020-09-03 15:13:19 +00:00
* `release` : Contains commands to release Vikunja with everything that's required
* `test` : Contains commands to run all kinds of tests
2020-09-04 08:15:33 +00:00
* `dev` : Contains commands to run development tasks
2020-09-03 15:13:19 +00:00
* `misc` : Commands which do not belong in either of the other categories
## CI
2021-05-17 10:53:12 +00:00
These tasks are automatically run in our CI every time someone pushes to main or you update a pull request:
2020-09-03 15:13:19 +00:00
2024-02-14 14:05:11 +00:00
* `mage lint`
2020-09-03 15:13:19 +00:00
* `mage build:build`
## Build
### Build Vikunja
2024-02-09 18:09:19 +00:00
```
2021-07-13 22:25:12 +00:00
mage build
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
2021-07-13 22:25:12 +00:00
Builds a `vikunja` -binary in the root directory of the repo for the platform it is run on.
2020-09-03 15:13:19 +00:00
### clean
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
mage build:clean
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
2021-07-13 22:25:12 +00:00
Cleans all build and executable files
2020-09-03 15:13:19 +00:00
## Check
All check sub-commands exit with a status code of 1 if the check fails.
Various code-checks are available:
2024-02-14 14:05:11 +00:00
* `mage check:all` : Runs golangci and swagger documentation check
* `mage lint` : Checks if the code follows the rules as defined in the `.golangci.yml` config file.
* `mage lint:fix` : Fixes all code style issues which are easily fixable.
2020-09-03 15:13:19 +00:00
## Release
### Build Releases
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
mage release
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
Builds binaries for all platforms and zips them with a copy of the `templates/` folder.
All built zip files are stored into `dist/zips/` . Binaries are stored in `dist/binaries/` ,
binaries bundled with `templates` are stored in `dist/releases/` .
All cross-platform binaries built using this series of commands are built with the help of
[xgo ](https://github.com/techknowlogick/xgo ). The mage command will automatically install the
binary to be able to use it.
`mage release:release` is a shortcut to execute `mage release:dirs release:windows release:linux release:darwin release:copy release:check release:os-package release:zip` .
* `mage release:dirs` creates all directories needed
* `mage release:windows` /`release:linux`/`release:darwin` execute xgo to build for their respective platforms
* `mage release:copy` bundles binaries with a copy of the `LICENSE` and sample config files to then be zipped
* `mage release:check` creates sha256 checksums for each binary which will be included in the zip file
* `mage release:os-package` bundles a binary with the `sha256` checksum file, a sample `config.yml` and a copy of the license in a folder for each architecture
* `mage release:compress` compresses all build binaries with `upx` to save space
2023-04-03 09:47:37 +00:00
* `mage release:zip` packages a zip file for the files created by `release:os-package`
2020-09-03 15:13:19 +00:00
2020-10-18 11:41:27 +00:00
### Build os packages
2020-09-03 15:13:19 +00:00
2024-02-09 18:09:19 +00:00
```
2020-10-18 11:41:27 +00:00
mage release:packages
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
2020-10-18 11:41:27 +00:00
Will build `.deb` , `.rpm` and `.apk` packages to `dist/os-packages` .
2020-09-03 15:13:19 +00:00
### Make a debian repo
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
mage release:reprepro
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
Takes an already built debian package and creates a debian repo structure around it.
Used to be run inside a [docker container ](https://git.kolaente.de/konrad/reprepro-docker ) in the CI process when releasing.
## Test
### unit
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
mage test:unit
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
Runs all tests except integration tests.
### coverage
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
mage test:coverage
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
Runs all tests except integration tests and generates a `coverage.html` file to inspect the code coverage.
### integration
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
mage test:integration
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
Runs all integration tests.
2020-09-04 08:15:33 +00:00
## Dev
### Create a new migration
2024-02-09 18:09:19 +00:00
```
2020-09-04 08:15:33 +00:00
mage dev:create-migration
2024-02-09 18:09:19 +00:00
```
2020-09-04 08:15:33 +00:00
2023-04-03 09:47:37 +00:00
Creates a new migration with the current date.
2020-09-04 08:15:33 +00:00
Will ask for the name of the struct you want to create a migration for.
2021-07-13 22:25:12 +00:00
See also [migration docs ]({{< ref "mage.md" >}} ).
2020-09-03 15:13:19 +00:00
## Misc
### Format the code
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
mage fmt
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
Formats all source code using `go fmt` .
### Generate swagger definitions from code comments
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
mage do-the-swag
2024-02-09 18:09:19 +00:00
```
2020-09-03 15:13:19 +00:00
Generates swagger definitions from the comment annotations in the code.