├── .github └── workflows │ ├── authentication.yml │ ├── container-name.yml │ ├── custom-image.yml │ ├── custom-port.yml │ ├── fallback-to-latest-version.yml │ └── main.yml ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── README.md ├── action.yml ├── docs └── new-release.md └── start-redis.sh /.github/workflows/authentication.yml: -------------------------------------------------------------------------------- 1 | name: Start Redis server with Authentication 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | redis-action: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | redis-version: [5, 6, 7] 11 | 12 | name: Start Redis Server v${{ matrix.redis-version }} 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v4 16 | 17 | - name: Start Redis Server 18 | uses: ./ 19 | with: 20 | redis-version: ${{ matrix.redis-version }} 21 | redis-password: password 22 | -------------------------------------------------------------------------------- /.github/workflows/container-name.yml: -------------------------------------------------------------------------------- 1 | name: Start Redis server with custom container name 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | redis-action: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | redis-version: [5, 6, 7] 11 | 12 | name: Start Redis Server v${{ matrix.redis-version }} 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v4 16 | 17 | - name: Start Redis Server 18 | uses: ./ 19 | with: 20 | redis-version: ${{ matrix.redis-version }} 21 | redis-container-name: redis-auth-token-cache 22 | -------------------------------------------------------------------------------- /.github/workflows/custom-image.yml: -------------------------------------------------------------------------------- 1 | name: Start Redis server from a custom image 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | redis-action: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | redis-version: [6.2.4-v4, 6.2.6-v3] 11 | 12 | name: Start Redis Stack Server v${{ matrix.redis-version }} 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v4 16 | 17 | - name: Start Redis Stack Server 18 | uses: ./ 19 | with: 20 | redis-image: redis/redis-stack-server 21 | redis-version: ${{ matrix.redis-version }} 22 | -------------------------------------------------------------------------------- /.github/workflows/custom-port.yml: -------------------------------------------------------------------------------- 1 | name: Start Redis server on custom port 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | redis-action: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | redis-version: [5, 6, 7] 11 | 12 | name: Start Redis Server v${{ matrix.redis-version }} 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v4 16 | 17 | - name: Start Redis Server 18 | uses: ./ 19 | with: 20 | redis-version: ${{ matrix.redis-version }} 21 | redis-port: 12345 22 | -------------------------------------------------------------------------------- /.github/workflows/fallback-to-latest-version.yml: -------------------------------------------------------------------------------- 1 | name: Start Redis server with latest version 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | redis-action: 7 | runs-on: ubuntu-latest 8 | 9 | name: Start Redis Server with latest Redis version 10 | steps: 11 | - name: Checkout 12 | uses: actions/checkout@v4 13 | 14 | - name: Start Redis Server 15 | uses: ./ 16 | with: 17 | redis-version: ${{ matrix.redis-versions }} 18 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Start Redis server 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | redis-action: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | redis-version: [5, 6, 7] 11 | 12 | name: Start Redis Server v${{ matrix.redis-version }} 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v4 16 | 17 | - name: Start Redis Server 18 | uses: ./ 19 | with: 20 | redis-version: ${{ matrix.redis-version }} 21 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [1.8.0](https://github.com/supercharge/redis-github-action/compare/v1.7.0...v1.8.0) - 2023-12-12 4 | 5 | ### Added 6 | - add Redis 7 to testing 7 | 8 | ### Updated 9 | - bump GitHub Actions service `actions/checkout` to version `v4` 10 | 11 | ### Removed 12 | - remove Redis 4 from testing 13 | 14 | ### Fixed 15 | - fix position of adding the Docker `--rm` flag to be added before starting the Redis server, because the `--rm` flag would be passed to the Redis server instead of Docker 16 | 17 | 18 | ## [1.7.0](https://github.com/supercharge/redis-github-action/compare/v1.6.0...v1.7.0) - 2023-09-04 19 | 20 | ### Added 21 | - add `redis-password` for start Redis with Authentication 22 | 23 | ### Updated 24 | - update versions in README 25 | 26 | 27 | ## [1.6.0](https://github.com/supercharge/redis-github-action/compare/v1.5.0...v1.6.0) - 2023-07-27 28 | 29 | ### Added 30 | - add `redis-remove-container` option adding the `--rm` flag to the resulting `docker run … --rm` command which starts the Redis container 31 | 32 | ### Updated 33 | - update versions in README 34 | 35 | 36 | ## [1.5.0](https://github.com/supercharge/redis-github-action/compare/v1.4.0...v1.5.0) - 2023-02-14 37 | 38 | ### Added 39 | - use a custom Redis image: useful if you need to run an alternative Redis image like Redis Stack 40 | - uses `redis` as the default Docker image 41 | 42 | 43 | ## [1.4.0](https://github.com/supercharge/redis-github-action/compare/v1.3.0...v1.4.0) - 2021-12-28 44 | 45 | ### Added 46 | - use a custom name for the Redis container: this is helpful when starting multiple Redis instances 47 | 48 | 49 | ## [1.3.0](https://github.com/supercharge/redis-github-action/compare/v1.2.0...v1.3.0) - 2021-12-27 50 | 51 | ### Added 52 | - start Redis instance on a custom port 53 | 54 | 55 | ## [1.2.0](https://github.com/supercharge/redis-github-action/compare/v1.1.0...v1.2.0) - 2021-01-08 56 | 57 | ### Added 58 | - version check before starting the Redis container: fall back to `latest` when no Redis version is defined for the workflow 59 | - run tests on pull requests 60 | 61 | ### Updated 62 | - refined wording in Readme 63 | 64 | 65 | ## [1.1.0](https://github.com/supercharge/redis-github-action/compare/v1.0.0...v1.1.0) - 2019-12-18 66 | 67 | ### Updated 68 | - switched from a Node.js workflow to a Docker-based workflow 69 | - reduces noise in the repo by removing the Node.js dependencies and only relying on a shell script 70 | 71 | 72 | ## 1.0.0 - 2019-12-17 73 | 74 | ### Added 75 | - `1.0.0` release 🚀 🎉 76 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM docker:stable 2 | COPY start-redis.sh /start-redis.sh 3 | RUN chmod +x /start-redis.sh 4 | ENTRYPOINT ["/start-redis.sh"] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 The Supercharge Node.js Framework 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 |
6 |
7 |

8 |

Redis in GitHub Actions

9 |

10 |

11 | Start a Redis server in your GitHub Actions. 12 |

13 |
14 |

15 | Usage 16 |

17 |
18 |
19 |

20 | Follow @marcuspoehls and @superchargejs for updates! 21 |

22 |
23 | 24 | --- 25 | 26 | 27 | ## Introduction 28 | This GitHub Action starts a Redis server on the default port `6379`. 29 | 30 | This is useful when running tests against a Redis database. 31 | 32 | 33 | ## Usage 34 | A code example says more than 1,000 words. Here’s an exemplary GitHub Action using a Redis server in versions 4 and 5 to test a Node.js app: 35 | 36 | ```yaml 37 | name: Run tests 38 | 39 | on: [push] 40 | 41 | jobs: 42 | build: 43 | runs-on: ubuntu-latest 44 | strategy: 45 | matrix: 46 | node-version: [18.x, 20.x] 47 | redis-version: [6, 7] 48 | 49 | steps: 50 | - name: Git checkout 51 | uses: actions/checkout@v3 52 | 53 | - name: Use Node.js ${{ matrix.node-version }} 54 | uses: actions/setup-node@v3 55 | with: 56 | node-version: ${{ matrix.node-version }} 57 | 58 | - name: Start Redis 59 | uses: supercharge/redis-github-action@1.7.0 60 | with: 61 | redis-version: ${{ matrix.redis-version }} 62 | 63 | - run: npm install 64 | 65 | - run: npm test 66 | env: 67 | CI: true 68 | ``` 69 | 70 | 71 | ### Using a Custom Redis Image 72 | You can utilize an alternative Redis image using the `redis-image` input: 73 | 74 | ```yaml 75 | name: Run tests 76 | 77 | on: [push] 78 | 79 | jobs: 80 | build: 81 | runs-on: ubuntu-latest 82 | strategy: 83 | matrix: 84 | redis-version: [6.2.4-v4, 6.2.6-v3] 85 | 86 | steps: 87 | - name: Start Redis 88 | uses: supercharge/redis-github-action@1.7.0 89 | with: 90 | redis-image: redis/redis-stack-server 91 | redis-version: ${{ matrix.redis-version }} 92 | 93 | - name: … 94 | ``` 95 | 96 | 97 | ### Using Redis on a Custom Port 98 | You can start the Redis instance on a custom port using the `redis-port` input: 99 | 100 | ```yaml 101 | name: Run tests 102 | 103 | on: [push] 104 | 105 | jobs: 106 | build: 107 | runs-on: ubuntu-latest 108 | strategy: 109 | matrix: 110 | redis-version: [6, 7] 111 | 112 | steps: 113 | - name: Start Redis 114 | uses: supercharge/redis-github-action@1.7.0 115 | with: 116 | redis-version: ${{ matrix.redis-version }} 117 | redis-port: 12345 118 | 119 | - name: … 120 | ``` 121 | 122 | 123 | ### Using a Custom Container Name 124 | 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: 125 | 126 | ```yaml 127 | name: Run tests 128 | 129 | on: [push] 130 | 131 | jobs: 132 | build: 133 | runs-on: ubuntu-latest 134 | strategy: 135 | matrix: 136 | redis-version: [6, 7] 137 | 138 | steps: 139 | - name: Start Redis 140 | uses: supercharge/redis-github-action@1.7.0 141 | with: 142 | redis-version: ${{ matrix.redis-version }} 143 | redis-container-name: redis-auth-token-cache 144 | 145 | - name: … 146 | ``` 147 | 148 | 149 | ### Remove container when exit 150 | Starting in v1.6.0, when running this action on a self-hosted runner, it’s helpful to remove the container so its name won’t conflict: 151 | 152 | ```yaml 153 | name: Run tests 154 | 155 | on: [push] 156 | 157 | jobs: 158 | build: 159 | runs-on: ubuntu-latest 160 | strategy: 161 | matrix: 162 | redis-version: [6, 7] 163 | 164 | steps: 165 | - name: Start Redis 166 | uses: supercharge/redis-github-action@1.7.0 167 | with: 168 | redis-version: ${{ matrix.redis-version }} 169 | redis-remove-container: true # false by default 170 | 171 | - name: … 172 | ``` 173 | 174 | 175 | ### Using Authentication 176 | Starting in v1.7.0, You can start the Redis with Authentication using the `redis-password` input: 177 | 178 | ```yaml 179 | name: Run tests 180 | 181 | on: [push] 182 | 183 | jobs: 184 | build: 185 | runs-on: ubuntu-latest 186 | strategy: 187 | matrix: 188 | redis-version: [6, 7] 189 | 190 | steps: 191 | - name: Start Redis 192 | uses: supercharge/redis-github-action@1.7.0 193 | with: 194 | redis-version: ${{ matrix.redis-version }} 195 | redis-password: 'password' 196 | 197 | - name: … 198 | ``` 199 | 200 | 201 | ## License 202 | MIT © [Supercharge](https://superchargejs.com) 203 | 204 | --- 205 | 206 | > [superchargejs.com](https://superchargejs.com)  ·  207 | > GitHub [@supercharge](https://github.com/supercharge)  ·  208 | > Twitter [@superchargejs](https://twitter.com/superchargejs) 209 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Redis Server in GitHub Actions' 2 | description: 'Start a Redis server' 3 | 4 | branding: 5 | icon: 'database' 6 | color: 'red' 7 | 8 | inputs: 9 | redis-image: 10 | description: 'Redis image to use. Useful if you need to run a custom Redis image' 11 | required: false 12 | default: 'redis' 13 | redis-version: 14 | description: 'Redis version to use' 15 | required: false 16 | default: 'latest' 17 | redis-port: 18 | description: 'Redis port to use and expose' 19 | required: false 20 | default: 6379 21 | redis-password: 22 | description: "Redis password to use" 23 | required: false 24 | default: '' 25 | redis-container-name: 26 | description: "Name of the created container. Useful if you run multiple Redis containers" 27 | required: false 28 | default: 'redis' 29 | redis-remove-container: 30 | description: "Remove container after container exit?" 31 | required: false 32 | type: boolean 33 | default: false 34 | 35 | runs: 36 | using: 'docker' 37 | image: 'Dockerfile' 38 | args: 39 | - ${{ inputs.redis-image }} 40 | - ${{ inputs.redis-version }} 41 | - ${{ inputs.redis-port }} 42 | - ${{ inputs.redis-password }} 43 | - ${{ inputs.redis-container-name }} 44 | - ${{ inputs.redis-remove-container }} 45 | -------------------------------------------------------------------------------- /docs/new-release.md: -------------------------------------------------------------------------------- 1 | # Create a new Release 2 | This document contains notes for my future self on how to tag a new release for this package. 3 | 4 | 1. run [`release-it`](https://github.com/release-it/release-it) on the local command line 5 | 2. select the release version, create a tag, push changes, and don’t create an NPM release if `release-it` is asking for it 6 | 3. go to GitHub’s release page for this [redis-github-action](https://github.com/supercharge/redis-github-action/releases) and click the "Draft a new release" button 7 | 4. select the previously created tag and use the same tag version as the release title 8 | 5. that’s it 9 | -------------------------------------------------------------------------------- /start-redis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | REDIS_IMAGE=$1 4 | REDIS_VERSION=$2 5 | REDIS_PORT=$3 6 | REDIS_PASSWORD=$4 7 | REDIS_CONTAINER_NAME=$5 8 | REDIS_REMOVE_CONTAINER=$6 9 | 10 | if [ -z "$REDIS_VERSION" ]; then 11 | echo "Missing Redis version in the [redis-version] input. Received value: $REDIS_VERSION" 12 | echo "Falling back to Redis version [latest]" 13 | REDIS_VERSION='latest' 14 | fi 15 | 16 | DOCKER_RUN_ARGS="--name $REDIS_CONTAINER_NAME --publish $REDIS_PORT:6379 --detach $REDIS_IMAGE:$REDIS_VERSION" 17 | 18 | if [ "$REDIS_REMOVE_CONTAINER" == "true" ]; then 19 | DOCKER_RUN_ARGS="$DOCKER_RUN_ARGS --rm" 20 | fi 21 | 22 | if [ -n "$REDIS_PASSWORD" ]; then 23 | DOCKER_RUN_ARGS="$DOCKER_RUN_ARGS redis-server --requirepass $REDIS_PASSWORD" 24 | fi 25 | 26 | echo "Starting single-node Redis instance: $DOCKER_RUN_ARGS" 27 | docker run $DOCKER_RUN_ARGS 28 | --------------------------------------------------------------------------------