The script masked the exit codes of every command substitution it ran. `local` and `export` are commands
themselves, so their own return value overwrites the one of the substitution and `set -e` never sees a failure.
This was not only cosmetic: when `gitea generate secret` failed, the init container happily continued and exported
an empty `INTERNAL_TOKEN`, `SECRET_KEY`, `JWT_SECRET` and `LFS_JWT_SECRET`. Declaration and assignment are now
separated, which lets `set -e` abort instead of writing an app.ini with empty secrets. (SC2155)
`env2ini::log` passed its argument as the format string of `printf`. Settings names and section names are read from
user supplied configuration and are logged verbatim, so a value containing a `%` directive made `printf` consume
non-existing arguments. The message is passed as data now. `%b` instead of `%s` keeps the `\n` escapes of the
existing call sites working. (SC2059)
The remaining changes quote the file name variables and add `-r` to the `read` of the `find -print0` loop, where an
unquoted path or a backslash in a mount point would have been mangled. (SC2086, SC2162)
Co-authored-by: Copilot <copilot@github.com>
### Description of the change
This adds an environment for unit testing our bash scripts, using [BATS](https://github.com/bats-core/bats-core).
It implements first tests for `config_environment.sh`.
### Benefits
Writing unit tests for bash scripts documents the expected behavior and allows it being a quality gate in our CI.
### Possible drawbacks
Not everyone is familiar with this approach and unit testing framework. Me neither, it took me some hours to get into it.
### Applicable issues
- Related to #691 where an issue in `config_environment.sh` was detected. It doesn't fixes it yet. This will be a dedicated Pull Request.
### Additional information
I've verified that the changes for Renovate are indeed working.
You may wonder why there is only one `run $PROJECT_ROOT/scripts/init-containers/config/config_environment.sh` and many `run execute_test_script` calls.
Usually, testing a script itself would be executing `run $PROJECT_ROOT/scripts/init-containers/config/config_environment.sh`. You then can assert the exit code and other things. Since the `config_environment.sh` exports environment variables and we are not able to access them from outside a `run` execution, the function `execute_test_script` wraps our script execution between environment comparison. Doing so allows us capture environment variables that were added/removed during script execution.
Reviewed-on: https://gitea.com/gitea/helm-chart/pulls/724
Reviewed-by: pat-s <pat-s@noreply.gitea.com>
Co-authored-by: justusbunsi <sk.bunsenbrenner@gmail.com>
Co-committed-by: justusbunsi <sk.bunsenbrenner@gmail.com>
### Description of the change
This is a preparation for #724 (bash script testing) which would be too complex to review if done there. I haven't changed the script contents.
### Benefits
Better IDE support, possibility for shell checks, tests.
### Possible drawbacks
-
### Additional information
I only extracted files that are native bash scripts. There are others, being a mix of Helm templating and shell scripts. Those scripts must be cleared first before extracting them as well.
Reviewed-on: https://gitea.com/gitea/helm-chart/pulls/751
Co-authored-by: justusbunsi <sk.bunsenbrenner@gmail.com>
Co-committed-by: justusbunsi <sk.bunsenbrenner@gmail.com>