Skip to content

Commit

Permalink
Only test an action when it changes
Browse files Browse the repository at this point in the history
  • Loading branch information
baksetercx committed Dec 20, 2024
1 parent d7f4d48 commit b03497f
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions .github/workflows/test-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ env:
SYSTEM_NAME: 'core'

jobs:
set-matrices:
name: Set matrices
prepare-jobs:
name: Prepare jobs
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrices.outputs.matrix }}
matrix-analyze: ${{ steps.set-matrices.outputs.matrix-analyze }}
matrix-build: ${{ steps.set-matrices.outputs.matrix-build }}
matrix-deploy: ${{ steps.set-matrices.outputs.matrix-deploy }}
matrix-trivy: ${{ steps.set-matrices.outputs.matrix-trivy }}
all-changed-files: ${{ steps.changed-files.outputs.all_changed_files }}
steps:
- name: Set matrices
id: set-matrices
Expand Down Expand Up @@ -113,11 +114,15 @@ jobs:
env:
RUNNER: ${{ github.event_name == 'workflow_dispatch' && inputs.runner || 'elvia-runner' }}

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45

analyze:
name: Analyze
needs: [set-matrices]
needs: [prepare-jobs]
strategy:
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix-analyze) }}
matrix: ${{ fromJson(needs.prepare-jobs.outputs.matrix-analyze) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-${{ matrix.language }}-analyze'
cancel-in-progress: true
Expand All @@ -126,6 +131,7 @@ jobs:
actions: read
contents: read
security-events: write
if: ${{ contains('analyze/action.yml', needs.pepare-jobs.outputs.all-changed-files) }}
steps:
- name: Checkout this repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -153,9 +159,9 @@ jobs:

unit-tests:
name: Unit Tests
needs: [set-matrices]
needs: [prepare-jobs]
strategy:
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix) }}
matrix: ${{ fromJson(needs.prepare-jobs.outputs.matrix) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-unit-tests'
cancel-in-progress: true
Expand All @@ -165,6 +171,7 @@ jobs:
checks: write
issues: read
pull-requests: write
if: ${{ contains('unittest/action.yml', needs.prepare-jobs.outputs.all-changed-files) }}
steps:
- name: Checkout this repository
uses: actions/checkout@v4
Expand All @@ -191,10 +198,10 @@ jobs:

build:
name: Build
needs: [set-matrices]
needs: [prepare-jobs]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix-build) }}
matrix: ${{ fromJson(needs.prepare-jobs.outputs.matrix-build) }}
concurrency:
group: |
${{ github.workflow }}-${{ github.event_name }}-${{ github.job }}-${{ matrix.runner }}-${{ matrix.application-name }}-${{ matrix.project-file }}-${{ matrix.registry }}
Expand All @@ -208,6 +215,7 @@ jobs:
pull-requests: write
security-events: write
environment: build
if: ${{ contains('build/action.yml', needs.prepare-jobs.outputs.all-changed-files) }}
steps:
- name: Checkout this repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -241,6 +249,7 @@ jobs:

build-vulnerable-service:
name: Build Vulnerable Service
needs: [prepare-jobs]
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-build-vulnerable-service'
cancel-in-progress: true
Expand All @@ -252,7 +261,7 @@ jobs:
security-events: write
environment: build
# We are testing if a PR comment is created, so ony run on PR.
if: ${{ github.event_name == 'pull_request' }}
if: ${{ github.event_name == 'pull_request' && contains('build/action.yml', needs.prepare-jobs.outputs.all-changed-files) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -296,10 +305,10 @@ jobs:

deploy-dev:
name: Deploy Dev
needs: [set-matrices, build]
needs: [prepare-jobs, build]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix-deploy) }}
matrix: ${{ fromJson(needs.prepare-jobs.outputs.matrix-deploy) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.application-name }}-${{ matrix.runtime-cloud-provider }}-deploy-dev'
cancel-in-progress: false
Expand All @@ -308,6 +317,7 @@ jobs:
contents: read
id-token: write
environment: dev
if: ${{ contains('deploy/action.yml', needs.prepare-jobs.outputs.all-changed-files) }}
steps:
- name: Checkout this repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -342,9 +352,9 @@ jobs:

integration-tests:
name: Integration Tests
needs: [set-matrices, deploy-dev]
needs: [prepare-jobs, deploy-dev]
strategy:
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix) }}
matrix: ${{ fromJson(needs.prepare-jobs.outputs.matrix) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-integration-tests'
cancel-in-progress: true
Expand All @@ -355,6 +365,7 @@ jobs:
issues: read
pull-requests: write
id-token: write
if: ${{ contains('trivy-iac-scan/action.yml', needs.pepare-jobs.outputs.all-changed-files) }}
steps:
- name: Checkout this repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -384,10 +395,10 @@ jobs:

trivy-iac-scan:
name: Trivy IaC Scan
needs: [set-matrices]
needs: [prepare-jobs]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix-trivy) }}
matrix: ${{ fromJson(needs.prepare-jobs.outputs.matrix-trivy) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-trivy-iac-scan'
cancel-in-progress: true
Expand All @@ -396,6 +407,7 @@ jobs:
actions: read
contents: read
security-events: write
if: ${{ contains('trivy-iac-scan/action.yml', needs.pepare-jobs.outputs.all-changed-files) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -406,13 +418,14 @@ jobs:

terraform-format-check:
name: Terraform Format Check
needs: [set-matrices]
needs: [prepare-jobs]
strategy:
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix) }}
matrix: ${{ fromJson(needs.prepare-jobs.outputs.matrix) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-terraform-format-check'
cancel-in-progress: true
runs-on: ${{ matrix.runner }}
if: ${{ contains('terraform-format/action.yml', needs.pepare-jobs.outputs.all-changed-files) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -423,16 +436,17 @@ jobs:

slack-message-vault:
name: Slack Message using Vault
needs: [set-matrices]
needs: [prepare-jobs]
strategy:
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix) }}
matrix: ${{ fromJson(needs.prepare-jobs.outputs.matrix) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-slack-message-vault'
cancel-in-progress: true
runs-on: ${{ matrix.runner }}
permissions:
contents: read
id-token: write
if: ${{ contains('slack-message/action.yml', needs.pepare-jobs.outputs.all-changed-files) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -446,13 +460,14 @@ jobs:

slack-message-token:
name: Slack Message using token
needs: [set-matrices]
needs: [prepare-jobs]
strategy:
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix) }}
matrix: ${{ fromJson(needs.prepare-jobs.outputs.matrix) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-slack-message-token'
cancel-in-progress: true
runs-on: ${{ matrix.runner }}
if: ${{ contains('slack-message/action.yml', needs.pepare-jobs.outputs.all-changed-files) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -465,16 +480,17 @@ jobs:

vault:
name: Vault
needs: [set-matrices]
needs: [prepare-jobs]
strategy:
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix) }}
matrix: ${{ fromJson(needs.prepare-jobs.outputs.matrix) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-vault'
cancel-in-progress: true
runs-on: ${{ matrix.runner }}
permissions:
contents: read
id-token: write
if: ${{ contains('vault/action.yml', needs.pepare-jobs.outputs.all-changed-files) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down

0 comments on commit b03497f

Please sign in to comment.