Builds a matrix of workspaces based on glob patterns and analysis of which files have changed
Required The GitHub API token to use.
Required A newline-separated list of globs or dependency glob expressions representing specific workspaces. A !
can be used to exclude certain patterns.
A dependency glob expression looks like foo/*/ : bar/**/*
- if anything under bar
changes then all workspaces matching foo/*/
are returned.
A particular workspace to return when the event type is workflow_dispatch
.
A newline-separated list of globs representing dependencies of each workspace. If any of the dependencies have changed then all workspaces will be returned.
If provided, results will be relative to the given path
If provided, the action uses the specified path as the root for the purposes of detecting matching workspaces based on the provided glob patterns.
The matrix object of the following shape:
{
"workspace": ["match1", "match2"]
}
on:
push:
branches:
- main
paths:
- "terraform/clusters/*/*.tf"
jobs:
determine-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.build-workspace-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- id: build-workspace-matrix
uses: iStreamPlanet/github-actions/build-workspace-matrix@main
with:
github-token: ${{secrets.GITHUB_TOKEN}}
workspaces: |
# Only matching workspaces that contain changes will be returned
terraform/clusters/*/
# except for /example, which is excluded
!terraform/clusters/example/
# additionally, if any *.tf file under shared_modules/foo or shared_modules/bar (recursively)
# is changed, all workspaces matching product-a-* will be returned
terraform/clusters/product-a-*/ : shared_modules/foo/*.tf
terraform/clusters/product-a-*/ : shared_modules/bar/**/*.tf
global_dependencies: |
# If something in global dependencies changes then all matched workspaces are returned
terraform/modules/**/*.tf
build:
needs: [determine-matrix]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.determine-matrix.outputs.matrix) }}
defaults:
run:
working-directory: ${{ matrix.workspace }}
steps:
- uses: actions/checkout@v2
- run: pwd
on:
schedule:
# * is a special character in YAML so you have to quote this string
# Runs at 9 AM Pacific Time every weekday
- cron: "0 16 * * 1-5"
jobs:
determine-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.build-workspace-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- id: build-workspace-matrix
uses: iStreamPlanet/github-actions/build-workspace-matrix@main
with:
github-token: ${{secrets.GITHUB_TOKEN}}
# All workspaces returned
workspaces: |
terraform/clusters/*/
# Global dependencies not evaluated in this case
global_dependencies: ""
on:
workflow_dispatch:
inputs:
workspace:
description: "The path to the Terraform workspace"
required: true
jobs:
determine-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.build-workspace-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- id: build-workspace-matrix
uses: iStreamPlanet/github-actions/build-workspace-matrix@main
with:
github-token: ${{secrets.GITHUB_TOKEN}}
# A matrix with a single value provided by the input is returned
workflow_dispatch_workspace: ${{ github.event.inputs.workspace }}