This is the ORIGINAL post.
Use Objects in Array within the Matrix Strategy Definition
I Love Github Action Matrix Strategy!
GitHub Actions Matrix strategy is a feature that enables developers to execute a set of jobs across multiple configurations.
Typically, configurations are defined as arrays of values for various parameters such as operating systems, programming languages, or versions of dependencies.
See this example from GitHub Action Documentation.
jobs:
example_matrix:
strategy:
matrix:
version: [10, 12, 14]
os: [ubuntu-latest, windows-latest]
With the above configuration, Github will maximize the number of jobs run in parallel depending on runner availability.
However, I don’t need all combinations…
This is my case. I want to run two jobs in parallel.
One is for app1 deployment and the other is for app2 deployment.
jobs:
deploy:
name: "Deploy to S3 bucket"
runs-on: ubuntu-latest
strategy:
matrix:
app-type:
[
{
app: app1,
bucket: app1-website-bucket,
cf-id: E************1,
},
{
app: app2,
bucket: app2-website-bucket,
cf-id: E************2,
},
]
with:
BUILD_PATH: ./${{ matrix.app-type.app }}/build
S3_BUCKET: ${{ matrix.app-type.bucket }}
CLOUDFRONT_DISTRIBUTION_ID: ${{ matrix.app-type.cf-id }}
Now, I will easily reference the properties of each configuration object using ${{ matrix.app-type.xxx }}. GitHub Actions will expand the matrix based on the number of objects in the app-type array, executing separate job runs for each configuration.
In this case, there will be two jobs (app1 and app2) running in parallel with the required parameters.
Notes
Matrix Strategy supports expanding or adding new configurations via include and excluding configurations via exclude . However, I still prefer the way shown in this article to get a straightforward view of the workflow definition.
What do you think or prefer?
Finally
Please follow me on Medium if you are interested in Cloud, DevOps, automation, programming, and any tech topics. I would also appreciate it if you could give me a clap.
Your comments are always welcome.
Thanks.