40 lines
1.5 KiB
Markdown
40 lines
1.5 KiB
Markdown
# inject-content
|
|
|
|
Inject content into a file by appending or overwriting. Useful for writing secrets, configuration snippets, or any multi-line content into an existing file at runtime.
|
|
|
|
## Inputs
|
|
|
|
| Input | Required | Default | Description |
|
|
|-------|----------|---------|-------------|
|
|
| `content` | Yes | | Content to write into the target file |
|
|
| `target-file` | Yes | | Path to the target file |
|
|
| `mode` | No | `append` | Write mode: `append` adds to the end of the file; `overwrite` replaces its contents |
|
|
|
|
## Usage
|
|
|
|
Append secrets to a Java `.properties` file:
|
|
|
|
```yaml
|
|
- uses: https://schmalz-git.git.onstackit.cloud/schmalz/shared-actions/inject-content@inject-content-v1
|
|
with:
|
|
content: ${{ secrets.APP_PROPERTIES }}
|
|
target-file: src/main/resources/application.properties
|
|
```
|
|
|
|
Overwrite a `.env` file:
|
|
|
|
```yaml
|
|
- uses: https://schmalz-git.git.onstackit.cloud/schmalz/shared-actions/inject-content@inject-content-v1
|
|
with:
|
|
content: ${{ secrets.DOTENV_CONTENT }}
|
|
target-file: .env
|
|
mode: overwrite
|
|
```
|
|
|
|
## Notes
|
|
|
|
- Content is passed via an environment variable to avoid shell injection vulnerabilities.
|
|
- In `append` mode a blank line is inserted between existing content and the new content. If the target file is empty or does not exist, no leading blank line is added.
|
|
- In `overwrite` mode the file is replaced entirely; if the file does not exist it is created.
|
|
- Both modes ensure the written content ends with a trailing newline.
|
|
- Parent directories of `target-file` are created automatically if they do not exist.
|