Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/auto_cherry_pick.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Auto Cherry-Pick from Upstream

on:
workflow_dispatch:
inputs:
base_branch:
description: "Base branch to create the PR against"
required: true
default: "main"

permissions:
contents: write
pull-requests: write
packages: read
issues: write

jobs:
cherry-pick:
uses: step-security/reusable-workflows/.github/workflows/auto_cherry_pick.yaml@v1
with:
original-owner: "mad9000"
repo-name: "actions-find-and-replace-string"
base_branch: ${{ inputs.base_branch }}
4 changes: 4 additions & 0 deletions .github/workflows/main.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ jobs:

- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Run find-and-replace to remove refs/heads/
uses: ./
id: findandreplace
with:
source: ${{ github.ref }}
find: 'refs/heads/'
replace: ''

- name: Get the above output
run: echo "The replaced value is ${{ steps.findandreplace.outputs.value }}"

- name: Run find-and-replace to remove slashes
uses: ./
id: findandreplace2
with:
source: ${{ steps.findandreplace.outputs.value }}
find: '/'
replace: '-'

- name: Get the final output
run: echo "The replaced value is ${{ steps.findandreplace2.outputs.value }}"
18 changes: 18 additions & 0 deletions .github/workflows/claude_review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Claude Code Review

on:
pull_request:
types: [opened, synchronize, labeled]

jobs:
code-review:
uses: step-security/reusable-workflows/.github/workflows/claude_review.yml@v1
secrets:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}

permissions:
contents: write
pull-requests: write
packages: read
issues: write
id-token: write
114 changes: 1 addition & 113 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,117 +1,5 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.idea
.env.testßß

node_modules/
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2023 StepSecurity
Copyright (c) 2025 StepSecurity

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
79 changes: 64 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,91 @@
# Find and replace strings
# Find and Replace Strings

This action executes find-and-replace on a given string (hint: use `${{ github.ref }}` to get your branch name and apply this on it for use in another action).
A GitHub Action that performs find and replace operations on strings. Perfect for transforming branch names, processing environment variables, or manipulating any string data in your workflows.

## Features

- Find and replace text within any string
- Option to replace first occurrence or all occurrences
- TypeScript implementation with comprehensive testing
- Lightweight and fast execution

## Inputs

### `source`

**Required** The source string to apply this action to
**Required** The source string to perform find and replace on

### `find`

**Required** The text you want to search for within the branch name (eg. `ref/heads/`)
**Required** The text to search for within the source string

### `replace`

**Required** The text you want to replace (eg. `head-`, ``, `root_`)
**Required** The text to replace found occurrences with

### `replaceAll`

**Optional** Should replace all occurrences? (only 'true' string will be interpreted positive)
**Optional** Replace all occurrences (`true`) or just the first one (`false`, default)

## Outputs

### `value`

The new value containing the found-and-replaced string.
The resulting string after find and replace operation

## Example Usage

### Basic Usage

```yaml
- name: Remove refs/heads/ from branch name
uses: step-security/actions-find-and-replace-string@v5
id: branch-name
with:
source: ${{ github.ref }}
find: 'refs/heads/'
replace: ''

- name: Use cleaned branch name
run: echo "Branch: ${{ steps.branch-name.outputs.value }}"
```

### Example usage
### Replace All Occurrences

```yaml
uses: step-security/actions-find-and-replace-string@v5
with:
source: ${{ github.ref }} # this translates to ref/heads/main on the main branch, but can be any arbitrary string
find: 'ref/heads/' # we want to remove ref/heads/ from source
replace: '' # and replace it with a blank string (ie. removing it)
- name: Replace dots with dashes
uses: step-security/actions-find-and-replace-string@v5
id: sanitize
with:
source: 'test.example.com'
find: '.'
replace: '-'
replaceAll: 'true'
# Output: test-example-com
```

This will output `main`.
### Processing Environment Variables

```yaml
- name: Transform environment name
uses: step-security/actions-find-and-replace-string@v5
id: env-name
with:
source: ${{ github.event.pull_request.head.ref }}
find: 'feature/'
replace: 'preview-'
# Transforms: feature/new-login -> preview-new-login
```

## Common Use Cases

- Extracting branch names from git references
- Sanitizing strings for use in URLs or file names
- Transforming environment variable values
- Processing configuration strings
- Cleaning up user input or external data

## Development

Check out `.github/workflows/main.yml` for more examples
This action is built with TypeScript and includes comprehensive tests. The codebase follows modern development practices with proper type safety and error handling.

16 changes: 8 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
name: 'Find-and-replace strings'
description: 'Finds and replaces text on a string'
description: 'A GitHub Action that performs find and replace operations on strings.'
branding:
color: purple
icon: copy
icon: 'file-text'
color: 'blue'
inputs:
source:
description: 'The text you want to run this action on'
description: 'The source string to perform find and replace on'
required: true
find:
description: 'The text you are looking for'
description: 'The text to search for within the source string'
required: true
replace:
description: 'The text you want to replace with'
description: 'The text to replace found occurrences with'
required: true
replaceAll:
description: 'Replace all occurrences?'
description: 'Replace all occurrences (true) or just the first one (false, default)'
required: false
outputs:
value:
description: 'The new value after find-and-replace has been run'
description: 'The resulting string after find and replace operation'
runs:
using: 'node20'
main: 'dist/index.js'
10 changes: 10 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface FindReplaceInputs {
source: string;
find: string;
replace: string;
replaceAll: boolean;
}
export declare function validateSubscription(): Promise<void>;
export declare function getInputs(): FindReplaceInputs;
export declare function performFindReplace(inputs: FindReplaceInputs): string;
export declare function main(): Promise<void>;
1 change: 1 addition & 0 deletions dist/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading