setup-redis/README.md

209 lines
4.5 KiB
Markdown
Raw Normal View History

2019-12-17 12:44:54 +00:00
<div align="center">
<a href="https://superchargejs.com">
<img width="471" style="max-width:100%;" src="https://superchargejs.com/images/supercharge-text.svg" />
</a>
<br/>
<br/>
<p>
2019-12-18 09:28:22 +00:00
<h3>Redis in GitHub Actions</h3>
2019-12-17 12:44:54 +00:00
</p>
<p>
Start a Redis server in your GitHub Actions.
</p>
<br/>
<p>
<a href="#usage"><strong>Usage</strong></a>
</p>
<br/>
<br/>
<p>
<em>Follow <a href="http://twitter.com/marcuspoehls">@marcuspoehls</a> and <a href="http://twitter.com/superchargejs">@superchargejs</a> for updates!</em>
</p>
</div>
---
## Introduction
This GitHub Action starts a Redis server on the default port `6379`.
This is useful when running tests against a Redis database.
## Usage
A code example says more than a 1000 words. Heres an exemplary GitHub Action using a Redis server in versions 4 and 5 to test a Node.js app:
```yaml
name: Run tests
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
2023-07-27 08:41:22 +00:00
node-version: [18.x, 20.x]
redis-version: [6, 7]
2019-12-17 12:44:54 +00:00
steps:
- name: Git checkout
2021-01-08 10:09:25 +00:00
uses: actions/checkout@v2
2019-12-17 12:44:54 +00:00
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Start Redis
2023-09-04 02:16:41 +00:00
uses: supercharge/redis-github-action@1.7.0
2019-12-17 12:44:54 +00:00
with:
redis-version: ${{ matrix.redis-version }}
- run: npm install
- run: npm test
env:
CI: true
```
2023-02-12 22:26:11 +00:00
### Using a Custom Redis Image
You can utilize an alternative Redis image using the `redis-image` input:
```yaml
name: Run tests
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
redis-version: [6.2.4-v4, 6.2.6-v3]
steps:
- name: Start Redis
2023-09-04 02:16:41 +00:00
uses: supercharge/redis-github-action@1.7.0
2023-02-12 22:26:11 +00:00
with:
redis-image: redis/redis-stack-server
redis-version: ${{ matrix.redis-version }}
- name: …
```
2021-12-27 05:41:35 +00:00
### Using Redis on a Custom Port
You can start the Redis instance on a custom port using the `redis-port` input:
```yaml
name: Run tests
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
2023-07-27 08:41:22 +00:00
redis-version: [6, 7]
2021-12-27 05:41:35 +00:00
steps:
- name: Start Redis
2023-09-04 02:16:41 +00:00
uses: supercharge/redis-github-action@1.7.0
2021-12-27 05:41:35 +00:00
with:
redis-version: ${{ matrix.redis-version }}
redis-port: 12345
- name: …
```
2021-12-28 06:06:28 +00:00
### Using a Custom Container Name
This GitHub Action provides a Redis Docker container. The default container name is `redis`. It can be helpful to customize the container name. For example, when running multiple Redis instances in parallel. You can customize the container name using the `redis-container-name` input:
```yaml
name: Run tests
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
2023-07-27 08:41:22 +00:00
redis-version: [6, 7]
2021-12-28 06:06:28 +00:00
steps:
- name: Start Redis
2023-09-04 02:16:41 +00:00
uses: supercharge/redis-github-action@1.7.0
2021-12-28 06:06:28 +00:00
with:
redis-version: ${{ matrix.redis-version }}
redis-container-name: redis-auth-token-cache
- name: …
```
2023-09-04 02:16:41 +00:00
### Remove container when exit
2023-07-27 08:41:22 +00:00
Starting in v1.6.0, when running this action on a self-hosted runner, its helpful to remove the container so its name wont conflict:
```yaml
name: Run tests
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
2023-07-27 08:41:22 +00:00
redis-version: [6, 7]
steps:
- name: Start Redis
2023-09-04 02:16:41 +00:00
uses: supercharge/redis-github-action@1.7.0
with:
redis-version: ${{ matrix.redis-version }}
redis-remove-container: true # false by default
- name: …
```
2023-09-04 02:16:41 +00:00
2023-08-11 20:34:55 +00:00
### Using Authentication
Starting in v1.7.0, You can start the Redis with Authentication using the `redis-password` input:
```yaml
name: Run tests
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
redis-version: [6, 7]
steps:
- name: Start Redis
2023-09-04 02:16:41 +00:00
uses: supercharge/redis-github-action@1.7.0
2023-08-11 20:34:55 +00:00
with:
redis-version: ${{ matrix.redis-version }}
redis-password: 'password'
- name: …
```
2021-12-28 06:06:28 +00:00
2023-09-04 02:16:41 +00:00
2019-12-17 12:44:54 +00:00
## License
MIT © [Supercharge](https://superchargejs.com)
---
> [superchargejs.com](https://superchargejs.com) &nbsp;&middot;&nbsp;
2021-07-09 07:58:37 +00:00
> GitHub [@supercharge](https://github.com/supercharge) &nbsp;&middot;&nbsp;
2019-12-17 12:44:54 +00:00
> Twitter [@superchargejs](https://twitter.com/superchargejs)