From 07c873f627c7086e99aaf4b50c29baec17b40b1a Mon Sep 17 00:00:00 2001 From: Jayapriya Pai Date: Thu, 3 Oct 2024 23:50:39 +0530 Subject: [PATCH] .github/workflow: make execution of e2e and unit tests conditional Ref: https://docs.github.com/en/actions/using-jobs/using-conditions-to-control-job-execution This will help to avoid blocking the merge on conditional execution when only markdown files are changed Signed-off-by: Jayapriya Pai --- .github/workflows/changed-files.yaml | 27 ++++++++++++++++++++++++ .github/workflows/e2e-feature-gated.yaml | 8 +++---- .github/workflows/e2e.yaml | 11 +++++----- .github/workflows/unit.yaml | 8 ++++++- 4 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/changed-files.yaml diff --git a/.github/workflows/changed-files.yaml b/.github/workflows/changed-files.yaml new file mode 100644 index 000000000..60d3459a6 --- /dev/null +++ b/.github/workflows/changed-files.yaml @@ -0,0 +1,27 @@ +name: changed-files + +on: + workflow_call: + outputs: + non-markdown-files: + description: "changed files list" + value: ${{ jobs.changed-files.outputs.non-markdown-files }} + +jobs: + changed-files: + # Map the job outputs to step outputs + outputs: + non-markdown-files : ${{ steps.changed-files.outputs.non-markdown-files}} + runs-on: ubuntu-latest + steps: + - name: checkout repo + id: checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: get changed files + id: changed-files + run: | + echo non-markdown-files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -iv .md$ | xargs) >> $GITHUB_OUTPUT + - run: | + echo "${{ steps.changed-files.outputs.non-markdown-files}}" diff --git a/.github/workflows/e2e-feature-gated.yaml b/.github/workflows/e2e-feature-gated.yaml index 124d0c34c..0ff1636a6 100644 --- a/.github/workflows/e2e-feature-gated.yaml +++ b/.github/workflows/e2e-feature-gated.yaml @@ -1,8 +1,6 @@ name: e2e-feature-gated on: pull_request: - paths-ignore: - - '**/*.md' push: branches: - 'release-*' @@ -10,15 +8,17 @@ on: - 'main' tags: - 'v*' - paths-ignore: - - '**/*.md' # To cancel running workflow when new commits pushed in a pull request concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: + changed-files: + uses: ./.github/workflows/changed-files.yaml e2e-tests: name: E2E tests for feature gates + needs: changed-files + if: ${{ needs.changed-files.outputs.non-markdown-files }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index fb0b85640..02d2b9c56 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -1,8 +1,6 @@ name: e2e on: pull_request: - paths-ignore: - - '**/*.md' push: branches: - 'release-*' @@ -10,16 +8,18 @@ on: - 'main' tags: - 'v*' - paths-ignore: - - '**/*.md' # To cancel running workflow when new commits pushed in a pull request concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: + changed-files: + uses: ./.github/workflows/changed-files.yaml e2e-tests: name: E2E tests runs-on: ubuntu-latest + needs: changed-files + if: ${{ needs.changed-files.outputs.non-markdown-files }} strategy: matrix: suite: [alertmanager, prometheus, prometheusAllNS, thanosruler, operatorUpgrade] @@ -105,8 +105,9 @@ jobs: # Added to summarize the matrix and allow easy branch protection rules setup e2e-tests-result: name: End-to-End Test Results - if: always() + if: ${{ needs.changed-files.outputs.non-markdown-files }} needs: + - changed-files - e2e-tests runs-on: ubuntu-latest steps: diff --git a/.github/workflows/unit.yaml b/.github/workflows/unit.yaml index 7f6c1d4a4..7c76b747e 100644 --- a/.github/workflows/unit.yaml +++ b/.github/workflows/unit.yaml @@ -17,9 +17,13 @@ concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: + changed-files: + uses: ./.github/workflows/changed-files.yaml unit-tests: - runs-on: ubuntu-latest name: Unit tests + runs-on: ubuntu-latest + needs: changed-files + if: ${{ needs.changed-files.outputs.non-markdown-files }} steps: - uses: actions/checkout@v4 - name: Import environment variables from file @@ -32,6 +36,8 @@ jobs: extended-tests: runs-on: ubuntu-latest name: Extended tests + needs: changed-files + if: ${{ needs.changed-files.outputs.non-markdown-files }} steps: - uses: actions/checkout@v4 - name: Import environment variables from file