Tests workflow (oliver006/redis_exporter)
The Tests workflow from oliver006/redis_exporter, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get run de-duplication, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Tests workflow from the oliver006/redis_exporter repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Tests
on:
pull_request:
push:
branches:
- master
- "v*"
jobs:
test-stuff:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Docker
uses: docker/setup-buildx-action@v4
- name: Set up Docker Compose
run: sudo apt-get install docker-compose
# need to do this before we start the services as they need the TLS creds
- name: Create test certs for TLS
run: |
make test-certs
chmod 777 ./contrib/tls/*
- name: Start services
run: docker-compose up -d
working-directory: ./
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: '1.26'
- name: Install Dependencies
run: go mod tidy
- name: Docker logs
run: |
echo "${{ toJson(job) }}"
docker ps -a
echo "ok"
- name: Run tests
env:
LOG_LEVEL: "info"
run: |
sleep 15
make test
- name: Run tests - redis 8
env:
LOG_LEVEL: "info"
TEST_REDIS_URI: "redis://localhost:16388"
TEST_PWD_REDIS_URI: "redis://:redis-password@localhost:16380"
run: |
go test -v -race -p 1 ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v7
with:
fail_ci_if_error: true
files: ./coverage.txt
token: ${{ secrets.CODECOV_TOKEN }} # required
verbose: true
- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@v2
with:
file: coverage.txt
- name: Stop services
run: docker-compose down
working-directory: ./
lint-stuff:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: '1.26'
- name: Install Dependencies
run: go mod tidy
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.11.2
args: "--tests=false"
- name: Run checks
env:
LOG_LEVEL: "info"
run: |
make checks
build-stuff:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: '1.26'
- name: Install Dependencies
run: go mod tidy
- name: Build some binaries
run: make build-some-amd64-binaries
- name: Generate mixin
run: make mixin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Test Docker Image Build - Alpine
uses: docker/build-push-action@v7
with:
push: false
target: alpine
tags: user/app:tst
file: Dockerfile
build-args: "GOARCH=amd64"
- name: Test Docker Image Build - Scratch
uses: docker/build-push-action@v7
with:
push: false
target: scratch-release
tags: user/app:tst
file: Dockerfile
build-args: "GOARCH=amd64"
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Tests on: pull_request: push: branches: - master - "v*" concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: test-stuff: timeout-minutes: 30 runs-on: latchkey-small steps: - name: Checkout code uses: actions/checkout@v7 - name: Set up Docker uses: docker/setup-buildx-action@v4 - name: Set up Docker Compose run: sudo apt-get install docker-compose # need to do this before we start the services as they need the TLS creds - name: Create test certs for TLS run: | make test-certs chmod 777 ./contrib/tls/* - name: Start services run: docker-compose up -d working-directory: ./ - name: Setup Go uses: actions/setup-go@v6 with: go-version: '1.26' - name: Install Dependencies run: go mod tidy - name: Docker logs run: | echo "${{ toJson(job) }}" docker ps -a echo "ok" - name: Run tests env: LOG_LEVEL: "info" run: | sleep 15 make test - name: Run tests - redis 8 env: LOG_LEVEL: "info" TEST_REDIS_URI: "redis://localhost:16388" TEST_PWD_REDIS_URI: "redis://:redis-password@localhost:16380" run: | go test -v -race -p 1 ./... - name: Upload coverage to Codecov uses: codecov/codecov-action@v7 with: fail_ci_if_error: true files: ./coverage.txt token: ${{ secrets.CODECOV_TOKEN }} # required verbose: true - name: Upload coverage to Coveralls uses: coverallsapp/github-action@v2 with: file: coverage.txt - name: Stop services run: docker-compose down working-directory: ./ lint-stuff: timeout-minutes: 30 runs-on: latchkey-small steps: - name: Checkout code uses: actions/checkout@v7 - name: Setup Go uses: actions/setup-go@v6 with: go-version: '1.26' - name: Install Dependencies run: go mod tidy - name: golangci-lint uses: golangci/golangci-lint-action@v9 with: version: v2.11.2 args: "--tests=false" - name: Run checks env: LOG_LEVEL: "info" run: | make checks build-stuff: timeout-minutes: 30 runs-on: latchkey-small steps: - name: Checkout code uses: actions/checkout@v7 - name: Setup Go uses: actions/setup-go@v6 with: go-version: '1.26' - name: Install Dependencies run: go mod tidy - name: Build some binaries run: make build-some-amd64-binaries - name: Generate mixin run: make mixin - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 - name: Test Docker Image Build - Alpine uses: docker/build-push-action@v7 with: push: false target: alpine tags: user/app:tst file: Dockerfile build-args: "GOARCH=amd64" - name: Test Docker Image Build - Scratch uses: docker/build-push-action@v7 with: push: false target: scratch-release tags: user/app:tst file: Dockerfile build-args: "GOARCH=amd64"
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
- Add a job timeout so a hung step cannot burn hours of runner time.
5 third-party actions are referenced by a movable tag. Pin them to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Dependency installs
- Container pulls and builds
This workflow runs 3 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.