Leverage Matrices for DRY Workflow Management

Leverage Matrices for DRY Workflow Management⌗
😓 Tired of repeating similar job definitions for different scenarios in your Github Workflow?
💡 Matrices offer a DRY (Don’t Repeat Yourself) approach to automation on GitHub.
📖 By defining variables and their combinations within a single job, you can automatically trigger multiple runs with specific configurations. Imagine building and pushing Docker images for various versions and registries effortlessly!
Benefits:
👨💻 Maintainable: Reduces code duplication and simplifies maintenance.
Scalable: Supports testing across diverse environments with ease.
Flexible: Adapts to evolving needs without requiring major code changes.
👩🔬 Example:
Suppose you need to build Docker images from multiple Dockerfile templates and push them to different container registries. Matrices can automate this process, saving you time and effort.
name: AWESOME SAMPLE MATRIX
on:
push:
branches:
- main
jobs:
braised-meat:
runs-on: ubuntu-latest
strategy:
matrix:
foo:
- original_foo
bar:
- value_1
- value_2
include:
- bar: value_1
buzz: buzz_1 # additional matrix
foo: additional_foo # Additional element to array
- bar: value_2
buzz: buzz_2 # additional matrix
steps:
- name: Show matrix
run: |
echo "${{ matrix.foo }}"
echo "${{ matrix.bar }}"
echo "${{ matrix.buzz }}"