Skip to content

Use a VERSION file🔗

You may want to use a version number for multiple purposes in your projects:

  • displaying it somewhere in your app (e.g: backoffice footer, mobile app login/main screen, ...)
  • providing it to Sentry for identifying releases and artefacts (sourcemaps) as well as triggered events

One way is to create a VERSION file at the root of your project, containing the current version number:

1
1.0.0

The Manala - elao.app.docker recipes provides a helper to bump and commit this file with a predefined message.
You can add a make version target like this:

1
2
3
4
5
6
7
8
# Makefile

version:
    $(call semver_bump,VERSION,$(VERSION))

# You may need to handle multiple files in case of a mono-repo with multiple apps:
version:
    $(call semver_bump,api/VERSION,front/VERSION,$(VERSION))

Then, call make version so you'll be prompted to enter a new version number (the current one is reminded to you in the output).
Alternatively, use VERSION=1.2.3 make version to directly provide the version number non-interactively.

A "Bump version X.X.X" commit is automatically made with current changes (so you can even modify and automatically include other files you need to update before a release, for instance changelogs of a mobile app).

If you're using an .editorconfig file and a compatible IDE (or if your teammates do), ensure this is present in the file:

1
2
[VERSION]
insert_final_newline = false

So no newline is automatically appended by your editor at the end of the file.

⚠️ Be sure to include this file in your .manala.yaml releases:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
##############
# Deliveries #
##############

deliveries:

  - &release
    mode: production
    # ...
    release_add:
      # ...
      - VERSION

In a Symfony app🔗

Here is a simple way to exploit the version number in your app:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# config/services.yaml

# [...]

parameters:
    # Read the version number from a VERSION file. 
    # Update this file before each new release.
    env(APP_VERSION_FILE): '%kernel.project_dir%/VERSION'
    app_version: '%env(trim:file:APP_VERSION_FILE)%'

# [...]

Then, simply inject this parameter anywhere you need it.
You may also want to make it available gloablly in Twig templates:

1
2
3
4
5
6
# packages/twig.yaml
twig:
    # [...]
    globals:
        # [...]
        APP_VERSION: '%app_version%'

In a Webpack Encore config🔗

1
2
3
// webpack.config.js

const APP_VERSION = require('fs').readFileSync('./VERSION', 'utf8').trim();

This is especially useful to configure Sentry releases and to provide the release number to each of the triggered events.

Projects references🔗


Last update: December 20, 2024