Skip to content
Latchkey

CI workflow (prometheus-community/postgres_exporter)

The CI workflow from prometheus-community/postgres_exporter, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: prometheus-community/postgres_exporter.github/workflows/ci.ymlLicense Apache-2.0View source

What it does

This is the CI workflow from the prometheus-community/postgres_exporter repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
---
name: CI
on:
  pull_request:
  push:
    branches: [main, master, 'release-*']
    tags: ['v*']

permissions:
  contents: read

jobs:
  test_go:
    name: Go tests
    runs-on: ubuntu-latest
    container:
      # Whenever the Go version is updated here, .promu.yml
      # should also be updated.
      image: quay.io/prometheus/golang-builder:1.26-base
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          persist-credentials: false
      - uses: prometheus/promci-setup@3e5cd31b34b8ae19efa8f071c5e3cdb44884a7f8 # v0.2.1
      - run: make GO_ONLY=1 SKIP_GOLANGCI_LINT=1
      - run: git diff --exit-code

  build:
    name: Build
    runs-on: ubuntu-latest
    strategy:
      matrix:
        thread: [ 0, 1, 2, 3]
    steps:
      - uses: prometheus/promci/build@13941414d409d227afd67544e5d306827db5a1a2 # v0.8.5
        with:
          parallelism: 4
          thread: ${{ matrix.thread }}

  publish_default:
    name: Publish default branch artifacts
    runs-on: ubuntu-latest
    permissions:
      packages: write
    needs: [test_go, build]
    if: |
      (github.event_name == 'push' && github.event.ref == 'refs/heads/main')
      ||
      (github.event_name == 'push' && github.event.ref == 'refs/heads/master')
    steps:
      - uses: prometheus/promci/publish_main@13941414d409d227afd67544e5d306827db5a1a2 # v0.8.5
        with:
          docker_hub_organization: prometheuscommunity
          docker_hub_password: ${{ secrets.docker_hub_password }}
          ghcr_io_organization: prometheus-community
          ghcr_io_password: ${{ github.token }}
          quay_io_organization: prometheuscommunity
          quay_io_password: ${{ secrets.quay_io_password }}

  publish_release:
    name: Publish release artefacts
    runs-on: ubuntu-latest
    permissions:
      contents: write
      packages: write
    needs: [test_go, build]
    if: |
      (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v'))
    steps:
      - uses: prometheus/promci/publish_release@13941414d409d227afd67544e5d306827db5a1a2 # v0.8.5
        with:
          docker_hub_organization: prometheuscommunity
          docker_hub_password: ${{ secrets.docker_hub_password }}
          ghcr_io_organization: prometheus-community
          ghcr_io_password: ${{ github.token }}
          quay_io_organization: prometheuscommunity
          quay_io_password: ${{ secrets.quay_io_password }}
          github_token: ${{ github.token }}

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

---
name: CI
on:
  pull_request:
  push:
    branches: [main, master, 'release-*']
    tags: ['v*']
 
permissions:
  contents: read
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  test_go:
    timeout-minutes: 30
    name: Go tests
    runs-on: latchkey-small
    container:
      # Whenever the Go version is updated here, .promu.yml
      # should also be updated.
      image: quay.io/prometheus/golang-builder:1.26-base
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          persist-credentials: false
      - uses: prometheus/promci-setup@3e5cd31b34b8ae19efa8f071c5e3cdb44884a7f8 # v0.2.1
      - run: make GO_ONLY=1 SKIP_GOLANGCI_LINT=1
      - run: git diff --exit-code
 
  build:
    timeout-minutes: 30
    name: Build
    runs-on: latchkey-small
    strategy:
      matrix:
        thread: [ 0, 1, 2, 3]
    steps:
      - uses: prometheus/promci/build@13941414d409d227afd67544e5d306827db5a1a2 # v0.8.5
        with:
          parallelism: 4
          thread: ${{ matrix.thread }}
 
  publish_default:
    timeout-minutes: 30
    name: Publish default branch artifacts
    runs-on: latchkey-small
    permissions:
      packages: write
    needs: [test_go, build]
    if: |
      (github.event_name == 'push' && github.event.ref == 'refs/heads/main')
      ||
      (github.event_name == 'push' && github.event.ref == 'refs/heads/master')
    steps:
      - uses: prometheus/promci/publish_main@13941414d409d227afd67544e5d306827db5a1a2 # v0.8.5
        with:
          docker_hub_organization: prometheuscommunity
          docker_hub_password: ${{ secrets.docker_hub_password }}
          ghcr_io_organization: prometheus-community
          ghcr_io_password: ${{ github.token }}
          quay_io_organization: prometheuscommunity
          quay_io_password: ${{ secrets.quay_io_password }}
 
  publish_release:
    timeout-minutes: 30
    name: Publish release artefacts
    runs-on: latchkey-small
    permissions:
      contents: write
      packages: write
    needs: [test_go, build]
    if: |
      (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v'))
    steps:
      - uses: prometheus/promci/publish_release@13941414d409d227afd67544e5d306827db5a1a2 # v0.8.5
        with:
          docker_hub_organization: prometheuscommunity
          docker_hub_password: ${{ secrets.docker_hub_password }}
          ghcr_io_organization: prometheus-community
          ghcr_io_password: ${{ github.token }}
          quay_io_organization: prometheuscommunity
          quay_io_password: ${{ secrets.quay_io_password }}
          github_token: ${{ github.token }}
 

What changed

This workflow runs 4 jobs (7 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow