Skip to content

Commit

Permalink
ci: check for changes before triggering actions for deployment and bu…
Browse files Browse the repository at this point in the history
…ild (#337)

- Only triggers build for infrastructure when files in `.azure` folder
has changed
- Only triggers build for backend services when files in `src` folder
has changed

---------

Co-authored-by: Magnus Sandgren <5285192+MagnusSandgren@users.noreply.github.com>
  • Loading branch information
arealmaas and MagnusSandgren authored Jan 15, 2024
1 parent 234a34c commit 77a3538
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/CheckForChanges.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Check for changes"

on:
workflow_call:
outputs:
hasAzureChanges:
description: "Azure related files changed"
value: ${{ jobs.check-for-changes.outputs.hasAzureChanges }}
hasBackendChanges:
description: "Backend related files changed"
value: ${{ jobs.check-for-changes.outputs.hasBackendChanges }}

jobs:
check-for-changes:
name: Filter
runs-on: ubuntu-latest
outputs:
hasBackendChanges: ${{ steps.paths-filter.outputs.backend == 'true' }}
hasAzureChanges: ${{ steps.paths-filter.outputs.azure == 'true' }}
steps:
- uses: actions/checkout@v4

- uses: dorny/paths-filter@v2
id: paths-filter
with:
base: ${{ github.ref }}
filters: |
backend:
- 'src/**/*'
azure:
- '.azure/**/*'
# todo: add additional files that should trigger a build
2 changes: 1 addition & 1 deletion .github/workflows/Deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: OIDC Login to Azure Public Cloud with AzPowershell
- name: OIDC Login to Azure Public Cloud
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/PullRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ on:
- "tests/k6/**"

jobs:
check-for-changes:
name: Check for changes
uses: ./.github/workflows/CheckForChanges.yml

build:
uses: ./.github/workflows/BuildAndTest.yml
needs: ["check-for-changes"]
if: ${{ needs.check-for-changes.outputs.hasBackendChanges == 'true' }}

# todo: only if .azure-files are changed
build-infrastructure:
uses: ./.github/workflows/BuildInfrastructure.yml
needs: ["check-for-changes"]
if: ${{ needs.check-for-changes.outputs.hasAzureChanges == 'true' }}
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/Workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ on:
- "tests/k6/**"

jobs:
check-for-changes:
name: Check for changes
uses: ./.github/workflows/CheckForChanges.yml

build-and-test:
uses: ./.github/workflows/BuildAndTest.yml
needs: [check-for-changes]
if: ${{ needs.check-for-changes.outputs.hasBackendChanges == 'true' }}

publish:
needs: [build-and-test]
uses: ./.github/workflows/Publish.yml
needs: [build-and-test]
secrets:
GCR_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down

0 comments on commit 77a3538

Please sign in to comment.