https://github.com/mondeja/starts-with-line-replacer
GitHub Action that replaces lines in a file which start with a specific string.
https://github.com/mondeja/starts-with-line-replacer
github-actions
Last synced: 4 months ago
JSON representation
GitHub Action that replaces lines in a file which start with a specific string.
- Host: GitHub
- URL: https://github.com/mondeja/starts-with-line-replacer
- Owner: mondeja
- Created: 2025-05-28T14:34:04.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-05-28T15:21:43.000Z (4 months ago)
- Last Synced: 2025-06-07T14:05:42.643Z (4 months ago)
- Topics: github-actions
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# starts-with-line-replacer
[](https://github.com/mondeja/starts-with-line-replacer/actions)
GitHub Action that replaces lines in a file which start with a specific string.
> [!WARNING]
> This action is not intended to be used with untrusted input.## Usage
For example, given the next file
```toml
# Cargo.toml
[package]
name = "my-package"
version = "0.1.0"
```the version can be updated with
```yaml
jobs:
update-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Update version
uses: mondeja/starts-with-line-replacer@main
with:
file: Cargo.toml
starts-with: 'version ='
replace-by: 'version = "0.2.0"'
```- If the input file is not found, the action will fail.
- If the line that starts with the specified string is not found, the action will fail.## How it works
It uses a `sed -i 's/^${{ inputs.starts-with }}.*/${{ inputs.replace-by }}/'` command in a composite action to replace the line that starts with `starts` with `replace`.