Skip to content

Commit

Permalink
ci: Modify build workflow to only build images on changes
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Drew <[email protected]>
  • Loading branch information
learnitall committed Aug 16, 2024
1 parent 5ad370f commit a025fad
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .github/images.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

{
"include": [
{
"name": "cmapisrv-mock",
"context": "cmapisrv-mock",
"dockerfile": "./cmapisrv-mock/Dockerfile"
},
{
"name": "egw-scale-utils",
"context": "egw-scale-utils",
"dockerfile": "./egw-scale-utils/Dockerfile"
}
]
}

52 changes: 44 additions & 8 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,55 @@ on:
- main

jobs:
generate-matrix:
name: Create build matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}

steps:
- name: Checkout Source Code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false

- name: Check code changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
if: ${{ github.event_name == 'pull_request' }}
id: changes
with:
# These filter names must be synced with the `name` attribute for
# each entry in images.json.
filters: |
all:
- '.github/images.json'
- '.github/workflows/build.yaml'
cmapisrv-mock:
- 'cmapisrv-mock/**'
egw-scale-utils:
- 'egw-scale-utils/**'
- name: Generate matrix
id: generate-matrix
run: |
if [[ "${{ github.event_name }}" == "push" || "${{ steps.changes.outputs.all }}" == "true" ]]; then
echo "matrix=$(jq -c . ./.github/images.json)" >> $GITHUB_OUTPUT
exit 0
fi
jq -c '{"include": [ .include[] | select(any(.name == ${{ steps.changes.outputs.changes }}[]; .)) ]}' ./.github/images.json > /tmp/matrix.json
echo "Generated matrix:"
jq . /tmp/matrix.json
echo "matrix=$(jq -c . /tmp/matrix.json)" >> $GITHUB_OUTPUT
build-and-push:
name: Build and Push
runs-on: ubuntu-latest
needs: generate-matrix

strategy:
matrix:
include:
- name: cmapisrv-mock
context: cmapisrv-mock
dockerfile: ./cmapisrv-mock/Dockerfile
- name: egw-scale-utils
context: egw-scale-utils
dockerfile: ./egw-scale-utils/Dockerfile
matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }}

steps:
- name: Set up Docker Buildx
Expand Down

0 comments on commit a025fad

Please sign in to comment.