Variables Processing
To reduce and prevent duplications, Monteur offers its variables system for dynamic processing in its config files. It's unique and clean!
The Problem
During the first CI Job design and creation, the team bumped into a big problem when:
There is a need to dynamically formulate a field. A good case study would be to formulate a package name for a given project/app version. Constantly modifying many Package API recipe because of the version changes is not maintainable as there are too many duplications.
Too many dynamic values duplications. Likewise, a lot of project/app info can be made available in a single app data file and query from there.
Specific CI Job customization needs. Some CI Job recipes, due to the reliance on interfacting with third-party program, can have its own specific parameters and inputs processing.
The Solution
To solve the problem above, Monteur facilitates variables formatting for the following purposes to applicable data fields:
Comply to Don't Repeat Yourself principle.
Permits the ability to dynamically create configurations data for adaptive environment.
Permits an algorithmic approach to simplify all CI Job's recipe whenever applicable.
Location
field is
dynamically filled with the value from .WorkingDir
:
|
|
Variables Processing function is available since Monteur version
v0.0.1
.
Data Structure
The variable processing function deploys 2 different types of
variables: the plain variables and the formattable
variables. Although both have different roles and purposes,
they share the same operating mechanics which are a common and
unique list of KEY:VALUE
data.
The KEY
from the variable is used as the ID for the
formattable variables is strictly a string
data
type.
The VALUE
however, can be any data types.
Monteur always maintain a SINGLE common and uniquely
identified list of variables and carries out the "create
or overwrite" policy. Hence, any duplicated variables entry
having the same KEY
shall overwrites its existing
value.
Plain Variables Definition
The first type is the plain variables. These
variables are straight-up basic values meant to be used
directly or for formatting. They are parsed as it is.
The data structure usually looks something as such:
|
|
The table indicator is
[Variables]
.Sub-definitions (e.g.
[Variables.MyDef]
) are strictly prohibited.
Formattable Variables Definition
The second type is the formattable variables.
These variables can be formatted with existing available
variables before being parsed into the variables list.
The data structure is usually looks something as such:
|
|
The table indicator is
[FMTVariables]
.Sub-definitions (e.g.
[FMTVariables.MyDef]
) are strictly prohibited.Due to the
KEY:VALUE
list nature, there is no guarentee that the items are parsed in a consistent and orderly manner. Therefore, ONLY create formattable variables independent of one another.The above example shall create or overwrite the variable
Payload
with theValue
asmyapp-1.17.3.tar.gz
, asVersion = '1.17.3'
was supplied as a plain variable right above.
Variables Formatting
It's quite easy to use variable formatting. Consider the following fields as our case study:
|
|
|
|
KEY
called Version
pointing
to its string value 1.0.0
. Hence, the above case
study yields:
|
|
-
) right after/before the opening/closing template
braces instructs the removal of whitespaces like
space " "
, new line (\n
),
return carriage (\r
), and tab (\t
) in
that direction.
Variables Formatting Availability
Not all data fields have variable formatting
function. One good case is
the plain variables above where it makes no sense
to faclitate variable formatting.
Therefore, you need to consult the component's
documentation to check the variable formatting's
availability.
Parsing Mechanism
To achieve the solution presented earlier, Monteur maintains multi-layer overwriting policy for parsing all variables across different data sources. Here, we will briefly walkthrough each key activities in sequences.
Level 1: Parsing Main Source
Monteur starts off by parsing all plain variables
ONLY from the main configuration files located in
.configs/monteur/workspace.toml
by default.
This will serve as the foundation of the variables list.
All variables here are visible globally across
all
CI Jobs.
Level 2: Parsing CI Configuration Source
Monteur then parse the CI Job's common configuration
plain and formattable variables. All formattable
variables are processed before being saved into the
variable list. The data source are located in your CI
Job recipe file usually located in
.configs/monteur/[CI-JOB]/config.toml
.
Any new variables created at this level ONLY visible
to all the recipes in this CI Job while any existing
global variables shall remain globally visible.
Also, any conflicting variables (same KEY
)
shall be overwritten by the new ones.
Level 3: Parsing Recipe Source
Monteur then parse the recipe-level plain and
formattable variables. All formattable variables are
processed before being saved into the variable list. The
data source are located in your CI Job recipe file
usually located in
.configs/monteur/[CI-JOB]/jobs/[recipe].toml
.
Any new variables created at this level ONLY visible
to THIS recipe while any existing variables
retains its status quo visibility.
Also, any conflicting variables (same KEY
)
shall be overwritten by the new ones.
Reserved Variables
In common cases, Monteur reserved and use a set of pre-defined
variables for its CI Job operations, made visibly available via
the variables list. Hence, you should avoid these pre-defined
KEY
when creating your own variables!
Among them are:
App
The project/app data created via Init API.
Reserved since Monteur version
v0.0.1
.
Arch
Denotes current workstation CPU architecture.
Reserved since Monteur version
v0.0.1
.
Archive
Denotes an archive filepath in a task.
Used by Setup CI Job.
Reserved since Monteur version
v0.0.1
.
BaseDir
Denotes the directory that acts as the foundation of the work (e.g. root directory of your source codes).
Reserved since Monteur version
v0.0.1
.
BuildDir
Denotes the artifact directory output by Build CI Job.
Reserved since Monteur version
v0.0.1
.
BinDir
Denotes the directory holding all localized executables created by Setup CI Job.
Reserved since Monteur version
v0.0.1
.
ConfigDir
Denotes the directory holding all Monteur Filesystem's config directory.
Used for setting up the terminal to match the project/app working environment.
Reserved since Monteur version
v0.0.1
.
ChangelogEntries
Holds all changelog template data.
Reserved since Monteur version
v0.0.1
.
ComputeSystem
The workstation's Monteur Platform ID.
Reserved since Monteur version
v0.0.1
.
DataDir
Monteur data directory for persistent storage.
Reserved since Monteur version
v0.0.1
.
DocsDir
The directory holding the project/app documentation.
Reserved since Monteur version
v0.0.1
.
Format
Denotes a format of a task.
Reserved since Monteur version
v0.0.1
.
HomeDir
Denotes the user's home directory.
Reserved since Monteur version
v0.0.1
.
LogDir
Denotes Monteur's logging output directory.
Reserved since Monteur version
v0.0.1
.
Method
Denotes a method of a task.
Used by Setup CI Job.
Reserved since Monteur version
v0.0.1
.
OS
Denotes workstation's OS.
Reserved since Monteur version
v0.0.1
.
PackageDir
Denotes Monteur's output directory from Package CI Job.
Reserved since Monteur version
v0.0.1
.
PkgArch
CPU architecture of a package.
Used by Package CI Job.
Reserved since Monteur version
v0.0.1
.
PkgName
Name of a package.
Used by Package CI Job.
Reserved since Monteur version
v0.0.1
.
PkgOS
Opreating system of a package.
Used by Package CI Job.
Reserved since Monteur version
v0.0.1
.
PkgVersion
Version of a package.
Used by Package CI Job.
Reserved since Monteur version
v0.0.1
.
PkgVersionDigitLed
Version of a package where it is digit-led.
Used by Package CI Job.
Reserved since Monteur version
v0.0.1
.
ReleaseDir
Denotes the release directory for Release CI Job.
Reserved since Monteur version
v0.0.1
.
RootDir
Denotes the root directory of the project/app repository.
Reserved since Monteur version
v0.0.1
.
Secrets
Denotes Monteur's secret data.
Monteur internal use only.
Reserved since Monteur version
v0.0.1
.
Source
Denotes a source input of a task.
Used by Commands Execution Unit.
Reserved since Monteur version
v0.0.1
.
SourceArch
Denotes the CPU architecture of the source input of a task.
Used by Setup CI Job.
Reserved since Monteur version
v0.0.1
.
SourceCompute
Denotes the platform ID of the source input of a task.
Used by Setup CI Job.
Reserved since Monteur version
v0.0.1
.
SourceOS
Denotes the OS of the source input of a task.
Used by Setup CI Job.
Reserved since Monteur version
v0.0.1
.
Target
Denotes a target input of a task.
Used by Commands Execution Unit.
Reserved since Monteur version
v0.0.1
.
Timestamp
Denotes a full timestamp of a task when Monteur is invoked.
Reserved since Monteur version
v0.0.1
.
URL
Denotes an URL usable in a task.
Used by Setup CI Job.
Reserved since Monteur version
v0.0.1
.
WorkingDir
Denotes the temporary workspace directory for executing the task.
Reserved since Monteur version
v0.0.1
.
Epilogue
That's all for Monteur's Variable Processing Function. If you have any question, please feel free to raise your question at our Issues Section.