feat: Add justfiles module (#270)
This commit is contained in:
commit
d89afaeb16
3 changed files with 143 additions and 0 deletions
49
modules/justfiles/README.md
Normal file
49
modules/justfiles/README.md
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# `justfiles`
|
||||
|
||||
:::note The module is only compatible with Universal Blue images. :::
|
||||
|
||||
The `justfiles` module makes it easy to include [just](https://just.systems/) recipes from multiple files in Universal Blue -based images. It can be useful for example when utilizing DE-specific justfiles when building multiple images. On the other hand, you likely wont need the module if you're building just one image or need just one justfile for all your images.
|
||||
|
||||
## What is just ?
|
||||
|
||||
Just is a command runner (kind of like make) that can be used to supply arbitrary scripts under a single shell command. Images based on Universal Blue bundle a set of these scripts, called recipes, which can be accessed with the `ujust` command.
|
||||
|
||||
For more information, refer to these links:
|
||||
|
||||
* [Official just documentation](https://just.systems/man/en)
|
||||
* [Universal Blue documentation](https://universal-blue.discourse.group/docs?topic=42)
|
||||
* [BlueBuild documentation](https://blue-build.org/learn/universal-blue/#custom-just-recipes)
|
||||
|
||||
## What the module does
|
||||
|
||||
1. The module checks if the `config/justfiles/` folder is present.
|
||||
|
||||
* If it's not there, it fails.
|
||||
|
||||
2. The module finds all `.just` files inside of the `config/justfiles/` folder or starting from the relative path specified under `include`.
|
||||
|
||||
* If no `.just` files are found, it fails.
|
||||
|
||||
* The structure of the `config/justfiles/` folder does not matter, folders/files can be placed in there however desired, the module will find all `.just` files.
|
||||
|
||||
* Optionally, the `.just` files can be validated.
|
||||
|
||||
3. The module copies over the files/folders containing `.just` files to `/usr/share/bluebuild/justfiles/`.
|
||||
|
||||
* The folder structure of the copy destination remains the same as in the config folder.
|
||||
|
||||
4. The module generates import lines and appends them to the `/usr/share/ublue-os/just/60-custom.just` file.
|
||||
|
||||
* The module does not overwrite the destination file. New lines are added to an existing file.
|
||||
|
||||
* If the generated import lines are already present, the module skips them to avoid duplications.
|
||||
|
||||
## How to use the module
|
||||
|
||||
Place all your `.just` files or folders with `.just` files inside the `config/justfiles/` folder. If that folder doesn't exist, create it.
|
||||
|
||||
By default, the module will import all files with names ending in `.just` from `config/justfiles/`. You can also specify files or subfolders under `include`, and they will be the only ones imported.
|
||||
|
||||
If you also want to validate your justfiles, set `validate: true`. The validation can be very unforgiving and is turned off by default.
|
||||
|
||||
* The validation command usually prints huge number of lines. To avoid cluttering up the logs, the module will only tell you which files did not pass the validation. You can then use the command `just --fmt --check --unstable --justfile <DESTINATION FILE>` to troubleshoot them.
|
||||
83
modules/justfiles/justfiles.sh
Normal file
83
modules/justfiles/justfiles.sh
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
get_yaml_array CONFIG_SELECTION '.include[]' "$1"
|
||||
VALIDATE="$(echo "$1" | yq -I=0 ".validate")"
|
||||
|
||||
IMPORT_FILE="/usr/share/ublue-os/just/60-custom.just"
|
||||
CONFIG_FOLDER="${CONFIG_DIRECTORY}/justfiles"
|
||||
DEST_FOLDER="/usr/share/bluebuild/justfiles"
|
||||
|
||||
# Abort if justfiles folder is not present
|
||||
if [ ! -d "${CONFIG_FOLDER}" ]; then
|
||||
echo "Error: The config folder '${CONFIG_FOLDER}' was not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Include all files in the folder if none specified
|
||||
if [[ ${#CONFIG_SELECTION[@]} == 0 ]]; then
|
||||
CONFIG_SELECTION=($(find "${CONFIG_FOLDER}" -mindepth 1 -maxdepth 1 -exec basename {} \;))
|
||||
fi
|
||||
|
||||
for SELECTED in "${CONFIG_SELECTION[@]}"; do
|
||||
|
||||
echo "------------------------------------------------------------------------"
|
||||
echo "--- Adding folder/file '${SELECTED}'"
|
||||
echo "------------------------------------------------------------------------"
|
||||
|
||||
# Find all justfiles, starting from 'SELECTED' and get their paths
|
||||
JUSTFILES=($(find "${CONFIG_FOLDER}/${SELECTED}" -type f -name "*.just" | sed "s|${CONFIG_FOLDER}/||g"))
|
||||
|
||||
# Abort if no justfiles found at 'SELECTED'
|
||||
if [[ ${#JUSTFILES[@]} == 0 ]]; then
|
||||
echo "Error: No justfiles were found in '${CONFIG_FOLDER}/${SELECTED}'."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate all found justfiles if set to do so
|
||||
if [ "${VALIDATE}" == "true" ]; then
|
||||
|
||||
echo "Validating justfiles"
|
||||
VALIDATION_FAILED=0
|
||||
for JUSTFILE in "${JUSTFILES[@]}"; do
|
||||
if ! /usr/bin/just --fmt --check --unstable --justfile "${CONFIG_FOLDER}/${JUSTFILE}" &> /dev/null; then
|
||||
echo "- The justfile '${JUSTFILE}' FAILED validation."
|
||||
VALIDATION_FAILED=1
|
||||
fi
|
||||
done
|
||||
|
||||
# Exit if any justfiles are not valid
|
||||
if [ ${VALIDATION_FAILED} -eq 1 ]; then
|
||||
echo "Error: Some justfiles didn't pass validation."
|
||||
exit 1
|
||||
else
|
||||
echo "- All justfiles passed validation."
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# Copy 'SELECTED' to destination folder
|
||||
echo "Copying folders/files"
|
||||
mkdir -p "${DEST_FOLDER}/$(dirname ${SELECTED})"
|
||||
cp -rfT "${CONFIG_FOLDER}/${SELECTED}" "${DEST_FOLDER}/${SELECTED}"
|
||||
echo "- Copied '${CONFIG_FOLDER}/${SELECTED}' to '${DEST_FOLDER}/${SELECTED}'."
|
||||
|
||||
# Generate import lines for all found justfiles
|
||||
echo "Adding import lines"
|
||||
for JUSTFILE in "${JUSTFILES[@]}"; do
|
||||
|
||||
# Create an import line
|
||||
IMPORT_LINE="import \"${DEST_FOLDER}/${JUSTFILE}\""
|
||||
|
||||
# Skip the import line if it already exists, else append it to import file
|
||||
if grep -wq "${IMPORT_LINE}" "${IMPORT_FILE}"; then
|
||||
echo "- Skipped: '${IMPORT_LINE}' (already present)"
|
||||
else
|
||||
echo "${IMPORT_LINE}" >> "${IMPORT_FILE}"
|
||||
echo "- Added: '${IMPORT_LINE}'"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
done
|
||||
11
modules/justfiles/module.yml
Normal file
11
modules/justfiles/module.yml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
name: justfiles
|
||||
shortdesc: The justfiles module makes it easy to include just recipes from multiple files in Universal Blue -based images.
|
||||
readme: https://raw.githubusercontent.com/blue-build/modules/main/modules/justfiles/README.md
|
||||
example: |
|
||||
type: justfiles
|
||||
validate: true
|
||||
include:
|
||||
- common
|
||||
- gnome/monitors.just
|
||||
- shared/flatpak/fix-theming.just
|
||||
- justfile1.just
|
||||
Loading…
Add table
Add a link
Reference in a new issue