See other cool blogs

github

GitHub Workflow

Elixir Test Workflow

name: tests

on: [push, pull_request]

jobs:
  tests:
    name: Run Tests
    runs-on: ubuntu-latest
    strategy:
      matrix:
        include:
          - otp: '27.0'
            elixir: '1.18'
    env:
      MIX_ENV: test
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - uses: actions/checkout@v3
      - uses: erlef/setup-beam@v1
        with:
          otp-version: ${{ matrix.otp }}
          elixir-version: ${{ matrix.elixir }}
      - uses: actions/cache@v3
        with:
          path: deps
          key: ${{ runner.os }}-${{ matrix.elixir }}-otp${{ matrix.otp }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
          restore-keys: |
            ${{ runner.os }}-${{ matrix.elixir }}-otp${{ matrix.otp }}-mix-
      - run: mix deps.get
      - run: mix test

What Each Part Does

  • name: tests: workflow name shown in GitHub Actions.
  • on: [push, pull_request]: runs on pushes and pull request updates.
  • jobs: starts the list of jobs.
  • tests: job identifier.
  • name: Run Tests: human-readable job name.
  • runs-on: ubuntu-latest: uses an Ubuntu runner.
  • strategy.matrix: defines version combinations.
  • otp: '27.0' and elixir: '1.18': selected OTP and Elixir versions.
  • env: environment variables shared across steps.
  • MIX_ENV: test: runs Mix in test mode.
  • GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}: GitHub-provided token.
  • steps: ordered actions/commands.
  • actions/checkout@v3: checks out repo code.
  • erlef/setup-beam@v1: installs Erlang/OTP and Elixir.
  • otp-version: ${{ matrix.otp }}: matrix-driven OTP.
  • elixir-version: ${{ matrix.elixir }}: matrix-driven Elixir.
  • actions/cache@v3: caches dependencies.
  • path: deps: caches Mix dependency directory.
  • key: cache key based on OS, versions, and lockfile hash.
  • ${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}: lockfile hash for cache invalidation.
  • restore-keys: fallback cache prefixes.
  • ${{ runner.os }}-${{ matrix.elixir }}-otp${{ matrix.otp }}-mix-: fallback prefix.
  • mix deps.get: fetches dependencies.
  • mix test: runs tests.