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:VALUElist 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
Payloadwith theValueasmyapp-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:
AppThe project/app data created via Init API.
Reserved since Monteur version
v0.0.1.
ArchDenotes current workstation CPU architecture.
Reserved since Monteur version
v0.0.1.
ArchiveDenotes an archive filepath in a task.
Used by Setup CI Job.
Reserved since Monteur version
v0.0.1.
BaseDirDenotes 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.
BuildDirDenotes the artifact directory output by Build CI Job.
Reserved since Monteur version
v0.0.1.
BinDirDenotes the directory holding all localized executables created by Setup CI Job.
Reserved since Monteur version
v0.0.1.
ConfigDirDenotes 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.
ChangelogEntriesHolds all changelog template data.
Reserved since Monteur version
v0.0.1.
ComputeSystemThe workstation's Monteur Platform ID.
Reserved since Monteur version
v0.0.1.
DataDirMonteur data directory for persistent storage.
Reserved since Monteur version
v0.0.1.
DocsDirThe directory holding the project/app documentation.
Reserved since Monteur version
v0.0.1.
FormatDenotes a format of a task.
Reserved since Monteur version
v0.0.1.
HomeDirDenotes the user's home directory.
Reserved since Monteur version
v0.0.1.
LogDirDenotes Monteur's logging output directory.
Reserved since Monteur version
v0.0.1.
MethodDenotes a method of a task.
Used by Setup CI Job.
Reserved since Monteur version
v0.0.1.
OSDenotes workstation's OS.
Reserved since Monteur version
v0.0.1.
PackageDirDenotes Monteur's output directory from Package CI Job.
Reserved since Monteur version
v0.0.1.
PkgArchCPU architecture of a package.
Used by Package CI Job.
Reserved since Monteur version
v0.0.1.
PkgNameName of a package.
Used by Package CI Job.
Reserved since Monteur version
v0.0.1.
PkgOSOpreating system of a package.
Used by Package CI Job.
Reserved since Monteur version
v0.0.1.
PkgVersionVersion of a package.
Used by Package CI Job.
Reserved since Monteur version
v0.0.1.
PkgVersionDigitLedVersion of a package where it is digit-led.
Used by Package CI Job.
Reserved since Monteur version
v0.0.1.
ReleaseDirDenotes the release directory for Release CI Job.
Reserved since Monteur version
v0.0.1.
RootDirDenotes the root directory of the project/app repository.
Reserved since Monteur version
v0.0.1.
SecretsDenotes Monteur's secret data.
Monteur internal use only.
Reserved since Monteur version
v0.0.1.
SourceDenotes a source input of a task.
Used by Commands Execution Unit.
Reserved since Monteur version
v0.0.1.
SourceArchDenotes the CPU architecture of the source input of a task.
Used by Setup CI Job.
Reserved since Monteur version
v0.0.1.
SourceComputeDenotes the platform ID of the source input of a task.
Used by Setup CI Job.
Reserved since Monteur version
v0.0.1.
SourceOSDenotes the OS of the source input of a task.
Used by Setup CI Job.
Reserved since Monteur version
v0.0.1.
TargetDenotes a target input of a task.
Used by Commands Execution Unit.
Reserved since Monteur version
v0.0.1.
TimestampDenotes a full timestamp of a task when Monteur is invoked.
Reserved since Monteur version
v0.0.1.
URLDenotes an URL usable in a task.
Used by Setup CI Job.
Reserved since Monteur version
v0.0.1.
WorkingDirDenotes 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.